Commit 65bf4671 authored by zhangfeng's avatar zhangfeng

错误码配置

parent 7f8837a4
...@@ -55,8 +55,19 @@ public interface ErrorCodeConstants { ...@@ -55,8 +55,19 @@ public interface ErrorCodeConstants {
ErrorCode SCORE_RULE_NOT_EXISTS = new ErrorCode(1004008010, "score.rule.not.exists"); ErrorCode SCORE_RULE_NOT_EXISTS = new ErrorCode(1004008010, "score.rule.not.exists");
ErrorCode SCORE_RULE_DELETE_ERROR = new ErrorCode(1004008011, "score.rule.delete.error"); ErrorCode SCORE_RULE_DELETE_ERROR = new ErrorCode(1004008011, "score.rule.delete.error");
ErrorCode SCORE_RULE_UPDATE_ERROR = new ErrorCode(1004008012, "score.rule.update.error"); ErrorCode SCORE_RULE_UPDATE_ERROR = new ErrorCode(1004008012, "score.rule.update.error");
ErrorCode SCORE_RULE_FIELD_ERROR = new ErrorCode(1004008013, "score.rule.field.error"); ErrorCode SCORE_RULE_STATUS_ERROR = new ErrorCode(1004008014, "score.rule.status.error");
ErrorCode SCORE_RULE_STATUS_NOT_ENABLE = new ErrorCode(1004008015, "score.rule.status.not.enable");
ErrorCode USER_ADDRESS_NOT_EXISTS = new ErrorCode(1004008014, "user.address.not.exists"); ErrorCode SCORE_RULE_UNIQUE_CHECK_ERROR = new ErrorCode(1004008016, "score.rule.unique.check.error");
ErrorCode USER_ADDRESS_FIELD_ERROR = new ErrorCode(1004008015, "user.address.field.error"); ErrorCode SCORE_RULE_TRANSPORT_TYPE_ERROR = new ErrorCode(1004008017, "score.rule.transport.type.error");
ErrorCode SCORE_RULE_TIME_ERROR = new ErrorCode(1004008018, "score.rule.time.error");
ErrorCode SCORE_RULE_PERIOD_ERROR = new ErrorCode(1004008019, "score.rule.period.error");
ErrorCode ORDERV_SCORE_RULE_ERROR = new ErrorCode(1004008020, "orderv.score.rule.error");
ErrorCode SCORE_RULE_SHARE_STATUS_ERROR = new ErrorCode(1004008021, "score.rule.share.status.error");
ErrorCode SCORE_RULE_EXTRA_ERROR = new ErrorCode(1004008022, "score.rule.extra.error");
ErrorCode SCORE_RULE_RECEIVE_ADDRESS_ERROR = new ErrorCode(1004008023, "score.rule.receive.address.error");
ErrorCode SCORE_RULE_ORDERENTRY_ERROR = new ErrorCode(1004008024, "score.rule.orderentry.error");
ErrorCode SCORE_RULE_FIRST_ORDER_ERROR = new ErrorCode(1004008025, "score.rule.first.order.error");
ErrorCode USER_ADDRESS_NOT_EXISTS = new ErrorCode(1004008026, "user.address.not.exists");
ErrorCode USER_ADDRESS_FIELD_ERROR = new ErrorCode(1004008027, "user.address.field.error");
} }
...@@ -31,7 +31,6 @@ import org.apache.commons.collections4.ListUtils; ...@@ -31,7 +31,6 @@ import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -64,7 +63,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -64,7 +63,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) { public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO); ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO);
if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) { if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "新增规则状态必须是启用或未启用" : "status must be 1 or 2"); throw exception(SCORE_RULE_STATUS_ERROR);
} }
verifyCommon(createReqVO); verifyCommon(createReqVO);
Integer scoreRuleType = scoreRule.getType(); Integer scoreRuleType = scoreRule.getType();
...@@ -77,17 +76,11 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -77,17 +76,11 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
private void verifyCommon(ScoreRuleBaseVO scoreRuleIn) { private void verifyCommon(ScoreRuleBaseVO scoreRuleIn) {
//校验公共入参 //校验公共入参
if (scoreRuleIn.getType() != ScoreRuleTypeEnum.ORDER_V.getValue() && scoreRuleIn.getGetScoreOnce() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "单次获得积分必须大于0" : "getScoreOnce must > 0");
}
if (scoreRuleIn.getType() != ScoreRuleTypeEnum.REGISTER.getValue() && scoreRuleIn.getMaxScoreTotal() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "累积最高积分必须大于0" : "maxScoreTotal must > 0");
}
if (scoreRuleIn.getStartTime().after((scoreRuleIn.getEndTime())) || scoreRuleIn.getEndTime().before(Date.from(Instant.now()))) { if (scoreRuleIn.getStartTime().after((scoreRuleIn.getEndTime())) || scoreRuleIn.getEndTime().before(Date.from(Instant.now()))) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "开始时间需早于结束时间,结束时间需比当前时间晚" : "startTime must before endTime and endTime must after now"); throw exception(SCORE_RULE_TIME_ERROR);
} }
if (scoreRuleIn.getScorePeriod() <= 0) { if (scoreRuleIn.getScorePeriod() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "积分过期时间必须大于0" : "scorePeriod must > 0"); throw exception(SCORE_RULE_PERIOD_ERROR);
} }
//如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验。海运空运分开算 //如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验。海运空运分开算
if (scoreRuleIn.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue() && scoreRuleIn.getType() != ScoreRuleTypeEnum.SHARE.getValue()) { if (scoreRuleIn.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue() && scoreRuleIn.getType() != ScoreRuleTypeEnum.SHARE.getValue()) {
...@@ -97,25 +90,25 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -97,25 +90,25 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleIn.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) { if (scoreRuleIn.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) {
ScoreRuleOrderVExtraVO extraOrderV = scoreRuleIn.getExtraOrderV(); ScoreRuleOrderVExtraVO extraOrderV = scoreRuleIn.getExtraOrderV();
if (extraOrderV == null) { if (extraOrderV == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值额外参数必填" : "extraOrderV must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
Integer transportType = extraOrderV.getTransportType(); Integer transportType = extraOrderV.getTransportType();
if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) { if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3"); throw exception(SCORE_RULE_TRANSPORT_TYPE_ERROR);
} }
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(scoreRuleDOLambdaQuery); List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(scoreRuleDOLambdaQuery);
if (scoreRuleDOS != null && !scoreRuleDOS.isEmpty()) { if (scoreRuleDOS != null && !scoreRuleDOS.isEmpty()) {
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) { for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
ScoreRuleOrderVExtraVO bean = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class); ScoreRuleOrderVExtraVO bean = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
if (Objects.equals(bean.getTransportType(), transportType)) { if (Objects.equals(bean.getTransportType(), transportType)) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled"); throw exception(SCORE_RULE_UNIQUE_CHECK_ERROR);
} }
} }
} }
} else { } else {
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery); Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 0) { if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled"); throw exception(SCORE_RULE_UNIQUE_CHECK_ERROR);
} }
} }
} }
...@@ -129,7 +122,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -129,7 +122,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_NOT_EXISTS); throw exception(SCORE_RULE_NOT_EXISTS);
} }
if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) { if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) {
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "只有未启用规则可以更新" : "only disabled rule can update"); throw exception(SCORE_RULE_UPDATE_ERROR);
} }
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(updateReqVO); ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(updateReqVO);
verifyCommon(updateReqVO); verifyCommon(updateReqVO);
...@@ -150,18 +143,18 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -150,18 +143,18 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleType == ScoreRuleTypeEnum.ORDER_V.getValue()) { if (scoreRuleType == ScoreRuleTypeEnum.ORDER_V.getValue()) {
ScoreRuleOrderVExtraVO extraOrderV = reqVO.getExtraOrderV(); ScoreRuleOrderVExtraVO extraOrderV = reqVO.getExtraOrderV();
if (extraOrderV == null) { if (extraOrderV == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值额外参数不能为空" : "extraOrderV must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) { if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "是否首单必须为是(0)或否(1)" : "firstOrder must 0 or 1"); throw exception(SCORE_RULE_FIRST_ORDER_ERROR);
} }
if (extraOrderV.getTransportType() != TransportTypeEnum.OCEAN_LCL.getValue() && extraOrderV.getTransportType() != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) { if (extraOrderV.getTransportType() != TransportTypeEnum.OCEAN_LCL.getValue() && extraOrderV.getTransportType() != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3"); throw exception(SCORE_RULE_TRANSPORT_TYPE_ERROR);
} }
// 国家,城市,仓库id从receiveAddrList中获取 // 国家,城市,仓库id从receiveAddrList中获取
List<List<Long>> receiveAddrList = extraOrderV.getReceiveAddrList(); List<List<Long>> receiveAddrList = extraOrderV.getReceiveAddrList();
if (receiveAddrList == null || extraOrderV.getReceiveAddrList().isEmpty()) { if (receiveAddrList == null || extraOrderV.getReceiveAddrList().isEmpty()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "国家,城市,提货点信息不能为空" : "receiveAddrList must not null"); throw exception(SCORE_RULE_RECEIVE_ADDRESS_ERROR);
} }
StringBuilder targetCountry = new StringBuilder(); StringBuilder targetCountry = new StringBuilder();
StringBuilder targetCity = new StringBuilder(); StringBuilder targetCity = new StringBuilder();
...@@ -172,7 +165,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -172,7 +165,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
targetCity.append(integers.get(1)).append(","); targetCity.append(integers.get(1)).append(",");
receiveAddr.append(integers.get(2)).append(","); receiveAddr.append(integers.get(2)).append(",");
} catch (Exception e) { } catch (Exception e) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "国家,城市,提货点参数列表不符合规则" : "receiveAddrList format error"); throw exception(SCORE_RULE_RECEIVE_ADDRESS_ERROR);
} }
} }
extraOrderV.setTargetCountry(targetCountry.toString()); extraOrderV.setTargetCountry(targetCountry.toString());
...@@ -180,55 +173,55 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -180,55 +173,55 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
extraOrderV.setReceiveAddr(receiveAddr.toString()); extraOrderV.setReceiveAddr(receiveAddr.toString());
extraOrderV.setReceiveAddrList(null); extraOrderV.setReceiveAddrList(null);
if (StringUtils.isBlank(extraOrderV.getOrderEntry())) { if (StringUtils.isBlank(extraOrderV.getOrderEntry())) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单入口不能为空" : "orderEntry must not null"); throw exception(SCORE_RULE_ORDERENTRY_ERROR);
} }
verifyOrderVRule(extraOrderV.getOrderVRule()); verifyOrderVRule(extraOrderV.getOrderVRule());
scoreRule.setExtra(JSONUtil.toJsonStr(extraOrderV)); scoreRule.setExtra(JSONUtil.toJsonStr(extraOrderV));
} else if (scoreRuleType == ScoreRuleTypeEnum.REGISTER.getValue()) { } else if (scoreRuleType == ScoreRuleTypeEnum.REGISTER.getValue()) {
if (reqVO.getExtraRegister() == null) { if (reqVO.getExtraRegister() == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "注册规则额外参数不能为空" : "extraRegister must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
if (StringUtils.isBlank(reqVO.getExtraRegister().getRegisterPlatform())) { if (StringUtils.isBlank(reqVO.getExtraRegister().getRegisterPlatform())) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "注册平台不能为空" : "registerPlatform must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
scoreRule.setExtra(JSONUtil.toJsonStr(reqVO.getExtraRegister())); scoreRule.setExtra(JSONUtil.toJsonStr(reqVO.getExtraRegister()));
} else if (scoreRuleType == ScoreRuleTypeEnum.RECOMMEND.getValue()) { } else if (scoreRuleType == ScoreRuleTypeEnum.RECOMMEND.getValue()) {
ScoreRulerRecommendExtraVO extraRecommend = reqVO.getExtraRecommend(); ScoreRulerRecommendExtraVO extraRecommend = reqVO.getExtraRecommend();
if (extraRecommend == null) { if (extraRecommend == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "推荐规则额外参数不能为空" : "extraRecommend must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
if (extraRecommend.getShareStatus() != YesOrNoTypeEnum.YES.ordinal() && extraRecommend.getShareStatus() != YesOrNoTypeEnum.NO.ordinal()) { if (extraRecommend.getShareStatus() != YesOrNoTypeEnum.YES.ordinal() && extraRecommend.getShareStatus() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "是否分享为是(0)或否(1)" : "shareStatus must 0 or 1"); throw exception(SCORE_RULE_SHARE_STATUS_ERROR);
} }
if (StringUtils.isAnyBlank(extraRecommend.getShareContentEn(), extraRecommend.getShareContentZh())) { if (StringUtils.isAnyBlank(extraRecommend.getShareContentEn(), extraRecommend.getShareContentZh())) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "分享文案不能为空" : "shareContentEn and shareContentZh must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
scoreRule.setExtra(JSONUtil.toJsonStr(extraRecommend)); scoreRule.setExtra(JSONUtil.toJsonStr(extraRecommend));
} else if (scoreRuleType == ScoreRuleTypeEnum.SHARE.getValue()) { } else if (scoreRuleType == ScoreRuleTypeEnum.SHARE.getValue()) {
ScoreRuleShareExtraVO extraShare = reqVO.getExtraShare(); ScoreRuleShareExtraVO extraShare = reqVO.getExtraShare();
if (extraShare == null) { if (extraShare == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "分享规则额外参数不能为空" : "extraShare must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
if (StringUtils.isAnyBlank(extraShare.getActivityDescZh(), extraShare.getActivityDescEn(), extraShare.getActivityUrl())) { if (StringUtils.isAnyBlank(extraShare.getActivityDescZh(), extraShare.getActivityDescEn(), extraShare.getActivityUrl())) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "活动详情,活动链接不能为空" : "activityDescZh,activityDescEn,activityUrl must not null"); throw exception(SCORE_RULE_EXTRA_ERROR);
} }
if (extraShare.getShareStatus() != YesOrNoTypeEnum.YES.ordinal() && extraShare.getShareStatus() != YesOrNoTypeEnum.NO.ordinal()) { if (extraShare.getShareStatus() != YesOrNoTypeEnum.YES.ordinal() && extraShare.getShareStatus() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "是否分享为是(0)或否(1)" : "shareStatus must 0 or 1"); throw exception(SCORE_RULE_SHARE_STATUS_ERROR);
} }
scoreRule.setExtra(JSONUtil.toJsonStr(extraShare)); scoreRule.setExtra(JSONUtil.toJsonStr(extraShare));
} else { } else {
throw exception(SCORE_RULE_NOT_EXISTS, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则类型错误" : "scoreRuleType error"); throw exception(SCORE_RULE_NOT_EXISTS);
} }
} }
private void verifyOrderVRule(List<ScoreRuleOrderVExtraVO.OrderVRule> extraOrderVRule) { private void verifyOrderVRule(List<ScoreRuleOrderVExtraVO.OrderVRule> extraOrderVRule) {
if (extraOrderVRule == null || extraOrderVRule.isEmpty()) { if (extraOrderVRule == null || extraOrderVRule.isEmpty()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值积分规则不能为空" : "orderVRule must not null"); throw exception(ORDERV_SCORE_RULE_ERROR);
} }
int low = 0; int low = 0;
for (ScoreRuleOrderVExtraVO.OrderVRule orderVRule : extraOrderVRule) { for (ScoreRuleOrderVExtraVO.OrderVRule orderVRule : extraOrderVRule) {
if (orderVRule.getLow() < low || orderVRule.getHigh() <= orderVRule.getLow() || orderVRule.getScore() <= 0) { if (orderVRule.getLow() < low || orderVRule.getHigh() <= orderVRule.getLow() || orderVRule.getScore() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值积分规则参数不符合规则" : "ordervrule does not conform to the rules"); throw exception(ORDERV_SCORE_RULE_ERROR);
} }
low = orderVRule.getHigh(); low = orderVRule.getHigh();
} }
...@@ -241,7 +234,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -241,7 +234,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_NOT_EXISTS); throw exception(SCORE_RULE_NOT_EXISTS);
} }
if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) { if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) {
throw exception(SCORE_RULE_DELETE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "只有未启用可以删除" : "only disabled rule can update"); throw exception(SCORE_RULE_DELETE_ERROR);
} }
// 删除 // 删除
scoreRuleMapper.deleteById(id); scoreRuleMapper.deleteById(id);
...@@ -346,12 +339,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -346,12 +339,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue()); .eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue());
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery); Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 0) { if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled"); throw exception(SCORE_RULE_UNIQUE_CHECK_ERROR);
} }
} }
upScoreRuleDO.setStatus(scoreRuleStatusReqVO.getStatus()); upScoreRuleDO.setStatus(scoreRuleStatusReqVO.getStatus());
} else { } else {
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则状态不允许改变" : "status not allow"); throw exception(SCORE_RULE_STATUS_ERROR);
} }
scoreRuleMapper.updateById(upScoreRuleDO); scoreRuleMapper.updateById(upScoreRuleDO);
scoreRuleRedisDao.deleteEnableScoreRule(scoreRuleDO.getType()); scoreRuleRedisDao.deleteEnableScoreRule(scoreRuleDO.getType());
...@@ -379,12 +372,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -379,12 +372,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_NOT_EXISTS); throw exception(SCORE_RULE_NOT_EXISTS);
} }
if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) { if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "只有启用规则可以延期" : "only enabled rule can delay"); throw exception(SCORE_RULE_STATUS_NOT_ENABLE);
} }
Instant now = Instant.now(); Instant now = Instant.now();
//结束时间不能小于当前时间 //结束时间不能小于当前时间
if (!delayReqVO.getEndTime().toInstant().isAfter(now) || !delayReqVO.getEndTime().toInstant().isAfter(scoreRuleDO.getStartTime().toInstant())) { if (!delayReqVO.getEndTime().toInstant().isAfter(now) || !delayReqVO.getEndTime().toInstant().isAfter(scoreRuleDO.getStartTime().toInstant())) {
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "活动结束时间不能早于当前时间" : "end time must after now and start time"); throw exception(SCORE_RULE_TIME_ERROR);
} }
ScoreRuleDO upScoreRuleDO = new ScoreRuleDO(); ScoreRuleDO upScoreRuleDO = new ScoreRuleDO();
upScoreRuleDO.setId(delayReqVO.getId()); upScoreRuleDO.setId(delayReqVO.getId());
...@@ -395,7 +388,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -395,7 +388,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
@Override @Override
public ScoreRuleDO getEnabledOrderVScoreRuleByTransportType(Integer transportType) { public ScoreRuleDO getEnabledOrderVScoreRuleByTransportType(Integer transportType) {
if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) { if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3"); throw exception(SCORE_RULE_TRANSPORT_TYPE_ERROR);
} }
LambdaQuery<ScoreRuleDO> lambdaQuery = new LambdaQuery<>(); LambdaQuery<ScoreRuleDO> lambdaQuery = new LambdaQuery<>();
lambdaQuery.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue()) lambdaQuery.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue())
......
...@@ -46,9 +46,11 @@ public class ScoreRuleBaseVO { ...@@ -46,9 +46,11 @@ public class ScoreRuleBaseVO {
private String coverImageEn; private String coverImageEn;
@ApiModelProperty(value = "单次获取积分数(订单V值不传)", required = true) @ApiModelProperty(value = "单次获取积分数(订单V值不传)", required = true)
@Min(value = 0,message = "单次获取积分数不能小于0")
private Integer getScoreOnce = 0; private Integer getScoreOnce = 0;
@ApiModelProperty(value = "累积最高积分(注册不传)", required = true) @ApiModelProperty(value = "累积最高积分(注册不传)", required = true)
@Min(value = 0,message = "累积最高积分不能小于0")
private Integer maxScoreTotal = 0; private Integer maxScoreTotal = 0;
@ApiModelProperty(value = "活动开始时间", required = true) @ApiModelProperty(value = "活动开始时间", required = true)
...@@ -63,6 +65,7 @@ public class ScoreRuleBaseVO { ...@@ -63,6 +65,7 @@ public class ScoreRuleBaseVO {
@ApiModelProperty(value = "积分有效期(天)", required = true) @ApiModelProperty(value = "积分有效期(天)", required = true)
@NotNull(message = "积分有效期不能为空") @NotNull(message = "积分有效期不能为空")
@Min(value = 0,message = "积分有效期不能小于0天")
private Integer scorePeriod; private Integer scorePeriod;
@ApiModelProperty(value = "排序值", required = true) @ApiModelProperty(value = "排序值", required = true)
......
...@@ -11,7 +11,7 @@ import java.util.List; ...@@ -11,7 +11,7 @@ import java.util.List;
*/ */
public interface RedeemRewardApi { public interface RedeemRewardApi {
RedeemRewardRespDTO redeemReward(RedeemRewardReqVO redeemRewardReqVO); Boolean redeemReward(RedeemRewardReqVO redeemRewardReqVO);
List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList); List<RedeemRewardRespDTO> redeemRewards(List<RedeemRewardReqVO> redeemRewardReqVOList);
RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId); RedeemDetailForUserDTO getRedeemDetailForUser(Long redeemId);
......
...@@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO; ...@@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO;
import cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper; import cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper;
import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper; import cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper;
import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum; import cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum;
import cn.iocoder.yudao.module.reward.enums.RewardStatusEnum;
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
...@@ -65,7 +66,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -65,7 +66,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public RedeemRewardRespDTO redeemReward(RedeemRewardReqVO redeemRewardReqVO) { public Boolean redeemReward(RedeemRewardReqVO redeemRewardReqVO) {
if (redeemRewardReqVO.getEntrance() != PlatformTypeEnum.BACKEND.getValue() && redeemRewardReqVO instanceof AppRedeemRewardReqVO){ if (redeemRewardReqVO.getEntrance() != PlatformTypeEnum.BACKEND.getValue() && redeemRewardReqVO instanceof AppRedeemRewardReqVO){
AppRedeemRewardReqVO appRedeemRewardReqVO = (AppRedeemRewardReqVO) redeemRewardReqVO; AppRedeemRewardReqVO appRedeemRewardReqVO = (AppRedeemRewardReqVO) redeemRewardReqVO;
SmsCodeUseReqDTO smsCodeUseReqDTO = new SmsCodeUseReqDTO(); SmsCodeUseReqDTO smsCodeUseReqDTO = new SmsCodeUseReqDTO();
...@@ -82,28 +83,28 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -82,28 +83,28 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 查询礼品 // 查询礼品
RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId()); RewardDO rewardDO = rewardMapper.selectById(redeemRewardReqVO.getRewardId());
if (rewardDO == null) { if (rewardDO == null) {
return getRedeemResp(false, "礼品不存在", "reward do not exist!"); throw exception(REWARD_NOT_EXISTS);
} }
// 礼品未开启 // 礼品未开启
if (rewardDO.getStatus() != 1) { if (rewardDO.getStatus() != 1) {
return getRedeemResp(false, "礼品未开启", "reward do not enable!"); throw exception(REWARD_NOT_ENABLE);
} }
// 礼品数量不够 // 礼品数量不够
if (rewardDO.getQuantityRemain() < redeemRewardReqVO.getRewardCount()) { if (rewardDO.getQuantityRemain() < redeemRewardReqVO.getRewardCount()) {
return getRedeemResp(false, "礼品数量不够", "reward do not enough!"); throw exception(REWARD_COUNT_NOT_ENOUGH);
} }
// 兑换方式不匹配 // 兑换方式不匹配
String pickMethod = rewardDO.getPickMethod(); String pickMethod = rewardDO.getPickMethod();
String[] split = pickMethod.split(","); String[] split = pickMethod.split(",");
if (!Arrays.asList(split).contains(String.valueOf(redeemRewardReqVO.getRedeemType()))) { if (!Arrays.asList(split).contains(String.valueOf(redeemRewardReqVO.getRedeemType()))) {
return getRedeemResp(false, "兑换方式不支持", "redeem type do not support!"); throw exception(REWARD_PICK_METHOD_NOT_ALLOW);
} }
verifyMemberUser(redeemRewardReqVO, rewardDO); verifyMemberUser(redeemRewardReqVO, rewardDO);
String lockKey = "reward:redeem:lock:" + redeemRewardReqVO.getRewardId(); String lockKey = "reward:redeem:lock:" + redeemRewardReqVO.getRewardId();
RLock lock = redissonClient.getLock(lockKey); RLock lock = redissonClient.getLock(lockKey);
try { try {
if (!lock.tryLock(2, 10, TimeUnit.SECONDS)) { if (!lock.tryLock(2, 10, TimeUnit.SECONDS)) {
return getRedeemResp(false, "系统繁忙,请稍后再试", "The service is busy, please try again later"); throw exception(GET_LOCK_FAILED);
} }
// 添加兑换记录 // 添加兑换记录
Long redeemId = addRedeemRecord(redeemRewardReqVO, rewardDO); Long redeemId = addRedeemRecord(redeemRewardReqVO, rewardDO);
...@@ -112,19 +113,11 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -112,19 +113,11 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 更新礼品 // 更新礼品
redeemReward(rewardDO, redeemRewardReqVO.getRewardCount()); redeemReward(rewardDO, redeemRewardReqVO.getRewardCount());
} catch (InterruptedException e) { } catch (InterruptedException e) {
return getRedeemResp(false, "系统繁忙,请稍后再试", "The service is busy, please try again later"); throw exception(GET_LOCK_FAILED);
} finally { } finally {
lock.unlock(); lock.unlock();
} }
return getRedeemResp(true, "兑换成功!", "redeem success!"); return true;
}
private RedeemRewardRespDTO getRedeemResp(Boolean exchangeResult, String msgZh, String msgEn) {
RedeemRewardRespDTO redeemRewardRespDTO = new RedeemRewardRespDTO();
redeemRewardRespDTO.setExchangeResult(false);
redeemRewardRespDTO.setMsgZh(msgZh);
redeemRewardRespDTO.setMsgEn(msgEn);
return redeemRewardRespDTO;
} }
private void redeemReward(RewardDO reward, Integer rewardCount) { private void redeemReward(RewardDO reward, Integer rewardCount) {
...@@ -171,7 +164,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi { ...@@ -171,7 +164,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
// 查询礼品 // 查询礼品
RewardDO rewardDO = rewardMapper.selectById(rewardId); RewardDO rewardDO = rewardMapper.selectById(rewardId);
// 礼品未开启 // 礼品未开启
if (rewardDO.getStatus() != 1) { if (rewardDO.getStatus() != RewardStatusEnum.ENABLED.getValue()) {
throw exception(REWARD_NOT_ENABLE); throw exception(REWARD_NOT_ENABLE);
} }
int totalCount = 0; int totalCount = 0;
......
...@@ -125,7 +125,7 @@ public class RedeemRewardController { ...@@ -125,7 +125,7 @@ public class RedeemRewardController {
@PostMapping("/single") @PostMapping("/single")
@ApiOperation("兑换礼品") @ApiOperation("兑换礼品")
@PreAuthorize("@ss.hasPermission('ecw:giftManagement:exchange')") @PreAuthorize("@ss.hasPermission('ecw:giftManagement:exchange')")
public CommonResult<RedeemRewardRespDTO> redeemReward(@Valid @RequestBody RedeemRewardReqVO redeemRewardReqVO) { public CommonResult<Boolean> redeemReward(@Valid @RequestBody RedeemRewardReqVO redeemRewardReqVO) {
return success(redeemRewardApi.redeemReward(redeemRewardReqVO)); return success(redeemRewardApi.redeemReward(redeemRewardReqVO));
} }
......
...@@ -58,7 +58,7 @@ public class AppRedeemRewardController { ...@@ -58,7 +58,7 @@ public class AppRedeemRewardController {
@ApiOperation("兑换礼品") @ApiOperation("兑换礼品")
@Idempotent(timeout = 5) @Idempotent(timeout = 5)
//@PreAuthenticated //@PreAuthenticated
public CommonResult<RedeemRewardRespDTO> redeemReward(@Valid @RequestBody AppRedeemRewardReqVO redeemRewardReqVO) { public CommonResult<Boolean> redeemReward(@Valid @RequestBody AppRedeemRewardReqVO redeemRewardReqVO) {
return success(redeemRewardApi.redeemReward(redeemRewardReqVO)); return success(redeemRewardApi.redeemReward(redeemRewardReqVO));
} }
@PostMapping("/send-sms-code") @PostMapping("/send-sms-code")
......
...@@ -1036,9 +1036,21 @@ level.bound.range.conflict = score range exist conflict ...@@ -1036,9 +1036,21 @@ level.bound.range.conflict = score range exist conflict
score.operate.idempotent.error = idempotent key conflict score.operate.idempotent.error = idempotent key conflict
score.rule.not.exists = score rule not exists score.rule.not.exists = score rule not exists
score.rule.field.error = score rule field error:{} score.rule.field.error = score rule field error
score.rule.update.error = score rule update error:{} score.rule.update.error = only disabled rule can update
score.rule.delete.error = score rule delete error:{} score.rule.delete.error = only disabled rule can delete
score.rule.status.error = score rule status error
score.rule.status.not.enable = score rule status not enable
score.rule.unique.check.error = score rule unique check error
score.rule.transport.type.error = transport type error
score.rule.time.error = score rule time error
score.rule.period.error = score rule period error
orderv.score.rule.error = order v score rule error
score.rule.share.status.error = score rule share status error
score.rule.extra.error = score rule extra error
score.rule.receive.address.error = score rule receive address error
score.rule.orderentry.error = order entry must not null
score.rule.first.order.error = firstOrder must 0 or 1
user.address.not.exists = user address not exists user.address.not.exists = user address not exists
user.address.field.error = user address field error:{} user.address.field.error = user address field error:{}
\ No newline at end of file
...@@ -1040,9 +1040,21 @@ level.bound.range.conflict = \u79EF\u5206\u8303\u56F4\u5B58\u5728\u51B2\u7A81 ...@@ -1040,9 +1040,21 @@ level.bound.range.conflict = \u79EF\u5206\u8303\u56F4\u5B58\u5728\u51B2\u7A81
score.operate.idempotent.error = \u5E42\u7B49key\u51B2\u7A81 score.operate.idempotent.error = \u5E42\u7B49key\u51B2\u7A81
score.rule.not.exists = \u79EF\u5206\u89C4\u5219\u4E0D\u5B58\u5728 score.rule.not.exists = \u79EF\u5206\u89C4\u5219\u4E0D\u5B58\u5728
score.rule.field.error = \u79EF\u5206\u89C4\u5219\u5B57\u6BB5\u9519\u8BEF\uFF1A{} score.rule.field.error = \u79EF\u5206\u89C4\u5219\u5B57\u6BB5\u9519\u8BEF
score.rule.update.error = \u79EF\u5206\u89C4\u5219\u66F4\u65B0\u5931\u8D25\uFF1A{} score.rule.update.error = \u53EA\u6709\u672A\u542F\u7528\u89C4\u5219\u53EF\u4EE5\u66F4\u65B0
score.rule.delete.error = \u79EF\u5206\u89C4\u5219\u5220\u9664\u5931\u8D25\uFF1A{} score.rule.delete.error = \u53EA\u6709\u672A\u542F\u7528\u53EF\u4EE5\u5220\u9664
score.rule.status.error = \u79EF\u5206\u89C4\u5219\u72B6\u6001\u9519\u8BEF
score.rule.status.not.enable = \u79EF\u5206\u89C4\u5219\u672A\u542F\u7528
score.rule.unique.check.error = \u79EF\u5206\u89C4\u5219\u552F\u4E00\u6027\u68C0\u67E5\u5931\u8D25
score.rule.transport.type.error = \u8FD0\u8F93\u7C7B\u578B\u9519\u8BEF
score.rule.time.error = \u6D3B\u52A8\u65F6\u95F4\u4E0D\u5408\u6CD5
score.rule.period.error = \u8FC7\u671F\u65F6\u95F4\u9519\u8BEF
orderv.score.rule.error = \u8BA2\u5355V\u503C\u79EF\u5206\u89C4\u5219\u9519\u8BEF
score.rule.share.status.error = \u5206\u4EAB\u72B6\u6001\u9519\u8BEF
score.rule.extra.error = \u79EF\u5206\u89C4\u5219\u989D\u5916\u5B57\u6BB5\u9519\u8BEF
score.rule.receive.address.error = \u8BA2\u5355V\u503C\u89C4\u5219\u63D0\u8D27\u70B9\u5217\u8868\u9519\u8BEF
score.rule.orderentry.error = \u8BA2\u5355\u5165\u53E3\u4E0D\u80FD\u4E3A\u7A7A
score.rule.first.order.error = \u662F\u5426\u9996\u5355\u5FC5\u987B\u4E3A\u662F\uFF080\uFF09\u6216\u5426\uFF081\uFF09
user.address.not.exists = \u7528\u6237\u5730\u5740\u4E0D\u5B58\u5728 user.address.not.exists = \u7528\u6237\u5730\u5740\u4E0D\u5B58\u5728
user.address.field.error = \u7528\u6237\u5730\u5740\u5B57\u6BB5\u9519\u8BEF\uFF1A{} user.address.field.error = \u7528\u6237\u5730\u5740\u5B57\u6BB5\u9519\u8BEF\uFF1A{}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment