Commit a482bdb3 authored by zhangfeng's avatar zhangfeng

Merge branch 'refs/heads/feature_member_score' into dev

parents 46c357ef 4de07c1d
......@@ -45,7 +45,6 @@ import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
@Service
@Validated
public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, ScoreRuleDO> implements ScoreRuleService {
public static final Locale LOCALE = LocaleContextHolder.getLocale();
@Resource
private ScoreRuleMapper scoreRuleMapper;
......@@ -60,7 +59,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO);
if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "新增规则状态必须是启用或未启用" : "status must be 1 or 2");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "新增规则状态必须是启用或未启用" : "status must be 1 or 2");
}
verifyCommon(createReqVO);
Integer scoreRuleType = scoreRule.getType();
......@@ -74,16 +73,16 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
private void verifyCommon(ScoreRuleBaseVO scoreRuleIn) {
//校验公共入参
if (scoreRuleIn.getType() != ScoreRuleTypeEnum.ORDER_V.getValue() && scoreRuleIn.getGetScoreOnce() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "单次获得积分必须大于0" : "getScoreOnce must > 0");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "单次获得积分必须大于0" : "getScoreOnce must > 0");
}
if (scoreRuleIn.getType() != ScoreRuleTypeEnum.RECOMMEND.getValue() && scoreRuleIn.getMaxScoreTotal() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "累积最高积分必须大于0" : "maxScoreTotal must > 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()))) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "开始时间需早于结束时间,结束时间需比当前时间晚" : "startTime must before endTime and endTime must after now");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "开始时间需早于结束时间,结束时间需比当前时间晚" : "startTime must before endTime and endTime must after now");
}
if (scoreRuleIn.getScorePeriod() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "积分过期时间必须大于0" : "scorePeriod must > 0");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "积分过期时间必须大于0" : "scorePeriod must > 0");
}
//如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验。海运空运分开算
if (scoreRuleIn.getStatus() == ScoreRuleStatusEnum.ENABLED.getValue() && scoreRuleIn.getType() != ScoreRuleTypeEnum.SHARE.getValue()) {
......@@ -93,25 +92,25 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleIn.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) {
ScoreRuleOrderVExtraVO extraOrderV = scoreRuleIn.getExtraOrderV();
if (extraOrderV == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "订单V值额外参数必填" : "extraOrderV must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值额外参数必填" : "extraOrderV must not null");
}
Integer transportType = extraOrderV.getTransportType();
if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3");
}
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(scoreRuleDOLambdaQuery);
if (scoreRuleDOS != null && !scoreRuleDOS.isEmpty()) {
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
ScoreRuleOrderVExtraVO bean = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
if (Objects.equals(bean.getTransportType(), transportType)) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled");
}
}
}
} else {
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled");
}
}
}
......@@ -125,7 +124,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_NOT_EXISTS);
}
if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) {
throw exception(SCORE_RULE_UPDATE_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "只有未启用规则可以更新" : "only disabled rule can update");
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "只有未启用规则可以更新" : "only disabled rule can update");
}
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(updateReqVO);
verifyCommon(updateReqVO);
......@@ -146,18 +145,18 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleType == ScoreRuleTypeEnum.ORDER_V.getValue()) {
ScoreRuleOrderVExtraVO extraOrderV = reqVO.getExtraOrderV();
if (extraOrderV == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "订单V值额外参数不能为空" : "extraOrderV must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值额外参数不能为空" : "extraOrderV must not null");
}
if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "是否首单必须为是(0)或否(1)" : "firstOrder must 0 or 1");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "是否首单必须为是(0)或否(1)" : "firstOrder must 0 or 1");
}
if (extraOrderV.getTransportType() != TransportTypeEnum.OCEAN_LCL.getValue() && extraOrderV.getTransportType() != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3");
}
// 国家,城市,仓库id从receiveAddrList中获取
List<List<Long>> receiveAddrList = extraOrderV.getReceiveAddrList();
if (receiveAddrList == null || extraOrderV.getReceiveAddrList().isEmpty()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "国家,城市,提货点信息不能为空" : "receiveAddrList must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "国家,城市,提货点信息不能为空" : "receiveAddrList must not null");
}
StringBuilder targetCountry = new StringBuilder();
StringBuilder targetCity = new StringBuilder();
......@@ -168,7 +167,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
targetCity.append(integers.get(1)).append(",");
receiveAddr.append(integers.get(2)).append(",");
} catch (Exception e) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "国家,城市,提货点参数列表不符合规则" : "receiveAddrList format error");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "国家,城市,提货点参数列表不符合规则" : "receiveAddrList format error");
}
}
extraOrderV.setTargetCountry(targetCountry.toString());
......@@ -176,55 +175,55 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
extraOrderV.setReceiveAddr(receiveAddr.toString());
extraOrderV.setReceiveAddrList(null);
if (StringUtils.isBlank(extraOrderV.getOrderEntry())) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "订单入口不能为空" : "orderEntry must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单入口不能为空" : "orderEntry must not null");
}
verifyOrderVRule(extraOrderV.getOrderVRule());
scoreRule.setExtra(JSONUtil.toJsonStr(extraOrderV));
} else if (scoreRuleType == ScoreRuleTypeEnum.REGISTER.getValue()) {
if (reqVO.getExtraRegister() == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "注册规则额外参数不能为空" : "extraRegister must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "注册规则额外参数不能为空" : "extraRegister must not null");
}
if (StringUtils.isBlank(reqVO.getExtraRegister().getRegisterPlatform())) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "注册平台不能为空" : "registerPlatform must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "注册平台不能为空" : "registerPlatform must not null");
}
scoreRule.setExtra(JSONUtil.toJsonStr(reqVO.getExtraRegister()));
} else if (scoreRuleType == ScoreRuleTypeEnum.RECOMMEND.getValue()) {
ScoreRulerRecommendExtraVO extraRecommend = reqVO.getExtraRecommend();
if (extraRecommend == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "推荐规则额外参数不能为空" : "extraRecommend must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "推荐规则额外参数不能为空" : "extraRecommend must not null");
}
if (extraRecommend.getShareStatus() != YesOrNoTypeEnum.YES.ordinal() && extraRecommend.getShareStatus() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "是否分享为是(0)或否(1)" : "shareStatus must 0 or 1");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "是否分享为是(0)或否(1)" : "shareStatus must 0 or 1");
}
if (StringUtils.isAnyBlank(extraRecommend.getShareContentEn(), extraRecommend.getShareContentZh())) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "分享文案不能为空" : "shareContentEn and shareContentZh must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "分享文案不能为空" : "shareContentEn and shareContentZh must not null");
}
scoreRule.setExtra(JSONUtil.toJsonStr(extraRecommend));
} else if (scoreRuleType == ScoreRuleTypeEnum.SHARE.getValue()) {
ScoreRuleShareExtraVO extraShare = reqVO.getExtraShare();
if (extraShare == null) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "分享规则额外参数不能为空" : "extraShare must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "分享规则额外参数不能为空" : "extraShare must not null");
}
if (StringUtils.isAnyBlank(extraShare.getActivityDescZh(), extraShare.getActivityDescEn(), extraShare.getActivityUrl())) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "活动详情,活动链接不能为空" : "activityDescZh,activityDescEn,activityUrl must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "活动详情,活动链接不能为空" : "activityDescZh,activityDescEn,activityUrl must not null");
}
if (extraShare.getShareStatus() != YesOrNoTypeEnum.YES.ordinal() && extraShare.getShareStatus() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "是否分享为是(0)或否(1)" : "shareStatus must 0 or 1");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "是否分享为是(0)或否(1)" : "shareStatus must 0 or 1");
}
scoreRule.setExtra(JSONUtil.toJsonStr(extraShare));
} else {
throw exception(SCORE_RULE_NOT_EXISTS, LOCALE == Locale.SIMPLIFIED_CHINESE ? "规则类型错误" : "scoreRuleType error");
throw exception(SCORE_RULE_NOT_EXISTS, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则类型错误" : "scoreRuleType error");
}
}
private void verifyOrderVRule(List<ScoreRuleOrderVExtraVO.OrderVRule> extraOrderVRule) {
if (extraOrderVRule == null || extraOrderVRule.isEmpty()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "订单V值积分规则不能为空" : "orderVRule must not null");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值积分规则不能为空" : "orderVRule must not null");
}
int low = 0;
for (ScoreRuleOrderVExtraVO.OrderVRule orderVRule : extraOrderVRule) {
if (orderVRule.getLow() < low || orderVRule.getHigh() <= orderVRule.getLow() || orderVRule.getScore() <= 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "订单V值积分规则参数不符合规则" : "ordervrule does not conform to the rules");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "订单V值积分规则参数不符合规则" : "ordervrule does not conform to the rules");
}
low = orderVRule.getHigh();
}
......@@ -237,7 +236,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_NOT_EXISTS);
}
if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue()) {
throw exception(SCORE_RULE_DELETE_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "只有未启用可以删除" : "only disabled rule can update");
throw exception(SCORE_RULE_DELETE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "只有未启用可以删除" : "only disabled rule can update");
}
// 删除
scoreRuleMapper.deleteById(id);
......@@ -342,12 +341,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue());
Long count = scoreRuleMapper.selectCount(scoreRuleDOLambdaQuery);
if (count > 0) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则唯一校验:已存在此类规则启用" : "such rule is already enabled");
}
}
upScoreRuleDO.setStatus(scoreRuleStatusReqVO.getStatus());
} else {
throw exception(SCORE_RULE_UPDATE_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "规则状态不允许改变" : "status not allow");
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "规则状态不允许改变" : "status not allow");
}
scoreRuleMapper.updateById(upScoreRuleDO);
scoreRuleRedisDao.deleteEnableScoreRule(scoreRuleDO.getType());
......@@ -375,12 +374,12 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_NOT_EXISTS);
}
if (scoreRuleDO.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_UPDATE_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "只有启用规则可以延期" : "only enabled rule can delay");
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "只有启用规则可以延期" : "only enabled rule can delay");
}
Instant now = Instant.now();
//结束时间不能小于当前时间
if (!delayReqVO.getEndTime().toInstant().isAfter(now) || !delayReqVO.getEndTime().toInstant().isAfter(scoreRuleDO.getStartTime().toInstant())) {
throw exception(SCORE_RULE_UPDATE_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "活动结束时间不能早于当前时间" : "end time must after now and start time");
throw exception(SCORE_RULE_UPDATE_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "活动结束时间不能早于当前时间" : "end time must after now and start time");
}
ScoreRuleDO upScoreRuleDO = new ScoreRuleDO();
upScoreRuleDO.setId(delayReqVO.getId());
......@@ -391,7 +390,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
@Override
public ScoreRuleDO getEnabledOrderVScoreRuleByTransportType(Integer transportType) {
if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR, LOCALE == Locale.SIMPLIFIED_CHINESE ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3");
throw exception(SCORE_RULE_FIELD_ERROR, LocaleContextHolder.getLocale().equals(Locale.SIMPLIFIED_CHINESE) ? "运输方式只能填海运(1)或空运(3)" : "transportType must 1 or 3");
}
LambdaQuery<ScoreRuleDO> lambdaQuery = new LambdaQuery<>();
lambdaQuery.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue())
......
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