Commit 921ced92 authored by zhangfeng's avatar zhangfeng

feat(601): 订单V值启用规则修改

parent 7469b864
......@@ -48,6 +48,8 @@ import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.member.enums.TransportTypeEnum.OCEAN_LCL;
import static cn.iocoder.yudao.module.member.enums.TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT;
/**
* 积分规则 Service 实现类
......@@ -108,25 +110,25 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_EXTRA_ERROR);
}
Integer transportType = extraOrderV.getTransportType();
if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
if (transportType != OCEAN_LCL.getValue() && transportType != SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_TRANSPORT_TYPE_ERROR);
}
scoreRuleUniqueCheck(scoreRuleIn.getType(), transportType, scoreRuleIn.getStartTime(), scoreRuleIn.getEndTime(), null);
orderVUniqueCheck(extraOrderV, scoreRuleIn.getStartTime(), scoreRuleIn.getEndTime(), null);
} else {
scoreRuleUniqueCheck(scoreRuleIn.getType(), null, scoreRuleIn.getStartTime(), scoreRuleIn.getEndTime(), null);
scoreRuleUniqueCheck(scoreRuleIn.getType(), scoreRuleIn.getStartTime(), scoreRuleIn.getEndTime(), null);
}
}
}
/**
* 积分规则唯一性校验
* 积分规则唯一性校验(订单V值单独校验)
*
* @param type 类型
* @param transportType 运输类型(订单V值传)
* @param newScoreRuleStart 新积分规则开始时间
* @param delayId 延期时的规则id
* @param newScoreRuleStart 新规则的开始时间
* @param newScoreRuleEnd 新规则的结束时间
* @param delayId 延期规则的id
*/
private void scoreRuleUniqueCheck(Integer type, Integer transportType, Date newScoreRuleStart, Date newScoreRuleEnd, Long delayId) {
private void scoreRuleUniqueCheck(Integer type, Date newScoreRuleStart, Date newScoreRuleEnd, Long delayId) {
LambdaQuery<ScoreRuleDO> scoreRuleDOLambdaQuery = new LambdaQuery<>();
scoreRuleDOLambdaQuery.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue())
.eq(ScoreRuleDO::getType, type);
......@@ -137,22 +139,131 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleDOS == null || scoreRuleDOS.isEmpty()) {
return;
}
if (transportType != null) {
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
ScoreRuleOrderVExtraVO bean = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
if (Objects.equals(bean.getTransportType(), transportType) && verifyTimeOverlap(newScoreRuleStart, newScoreRuleEnd, scoreRuleDO)) {
throw exception(SCORE_RULE_UNIQUE_CHECK_ERROR);
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
if (verifyTimeOverlap(newScoreRuleStart, newScoreRuleEnd, scoreRuleDO)) {
throw exception(SCORE_RULE_UNIQUE_CHECK_ERROR, scoreRuleDO.getCode());
}
}
}
/**
* 订单V规则唯一性校验
*
* @param extraOrderV 订单v值额外信息
* @param newScoreRuleStart 新规则的开始时间
* @param newScoreRuleEnd 新规则的结束时间
* @param delayId 延期时的规则id
*/
private void orderVUniqueCheck(ScoreRuleOrderVExtraVO extraOrderV, Date newScoreRuleStart, Date newScoreRuleEnd, Long delayId) {
LambdaQuery<ScoreRuleDO> scoreRuleDOLambdaQuery = new LambdaQuery<>();
scoreRuleDOLambdaQuery.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue())
.eq(ScoreRuleDO::getType, ScoreRuleTypeEnum.ORDER_V.getValue());
if (delayId != null) {
scoreRuleDOLambdaQuery.ne(ScoreRuleDO::getId, delayId);
}
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(scoreRuleDOLambdaQuery);
if (scoreRuleDOS == null || scoreRuleDOS.isEmpty()) {
return;
}
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
ScoreRuleOrderVExtraVO oldExtraVO = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
if (verifyTimeOverlap(newScoreRuleStart, newScoreRuleEnd, scoreRuleDO) && isSameOrderVRule(oldExtraVO, extraOrderV)) {
throw exception(SCORE_RULE_UNIQUE_CHECK_ERROR, scoreRuleDO.getCode());
}
}
}
private boolean isSameOrderVRule(ScoreRuleOrderVExtraVO oldExtraVO, ScoreRuleOrderVExtraVO extraOrderV) {
return oldExtraVO.getTransportType().equals(extraOrderV.getTransportType()) &&
Objects.equals(oldExtraVO.getFirstOrder(), extraOrderV.getFirstOrder()) &&
verifyReceiveAddr(oldExtraVO, extraOrderV) &&
verifyChannel(oldExtraVO, extraOrderV) &&
verifyOrderEntry(oldExtraVO.getOrderEntry(), extraOrderV.getOrderEntry());
}
private boolean verifyChannel(ScoreRuleOrderVExtraVO oldExtraVO, ScoreRuleOrderVExtraVO extraOrderV) {
// 运输方式空运时,判断渠道是否有交集
if (oldExtraVO.getTransportType().equals(SPECIAL_LINE_AIR_FREIGHT.getValue())) {
List<Long> oldChannel = oldExtraVO.getChannel();
List<Long> newChannel = extraOrderV.getChannel();
if (CollectionUtils.isEmpty(oldChannel) || CollectionUtils.isEmpty(newChannel)) {
return false;
}
return CollectionUtils.containsAny(oldChannel, newChannel);
}
return false;
}
private boolean verifyReceiveAddr(ScoreRuleOrderVExtraVO oldExtraVO, ScoreRuleOrderVExtraVO extraOrderV) {
List<String> oldReceiveAddrList = Arrays.asList(oldExtraVO.getReceiveAddr().split(","));
List<String> newReceiveAddrList = new ArrayList<>();
// 如果是前端传入的,国家,城市,仓库id从receiveAddrList中获取
if (extraOrderV.getReceiveAddrList() != null) {
List<List<Long>> receiveAddrList = extraOrderV.getReceiveAddrList();
if (extraOrderV.getReceiveAddrList().isEmpty()) {
throw exception(SCORE_RULE_RECEIVE_ADDRESS_ERROR);
}
for (List<Long> integers : receiveAddrList) {
try {
newReceiveAddrList.add(integers.get(2).toString());
} catch (Exception e) {
throw exception(SCORE_RULE_RECEIVE_ADDRESS_ERROR);
}
}
} else {
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
if (verifyTimeOverlap(newScoreRuleStart, newScoreRuleEnd, scoreRuleDO)) {
throw exception(SCORE_RULE_UNIQUE_CHECK_ERROR);
}
newReceiveAddrList = Arrays.asList(extraOrderV.getReceiveAddr().split(","));
}
// 如果有一个选的是全部,则返回true
if (oldReceiveAddrList.contains("0") || newReceiveAddrList.contains("0")) {
return true;
}
// 如果两个集合有交集,则返回true
return CollectionUtils.containsAny(oldReceiveAddrList, newReceiveAddrList);
}
private boolean verifyOrderEntry(String oldOrderEntry, String newOrderEntry) {
List<String> oldEntryList = Arrays.asList(oldOrderEntry.split(","));
List<String> newEntryList = Arrays.asList(newOrderEntry.split(","));
// 对订单入口进行归类后比较
Set<String> categorizedSources1 = categorizeOrderEntry(oldEntryList);
Set<String> categorizedSources2 = categorizeOrderEntry(newEntryList);
// 如果一个规则归类为 "ALL",则无论另一个是什么都算相同
if (categorizedSources1.contains("ALL") || categorizedSources2.contains("ALL")) {
return true;
}
// 仅当分类后的集合完全一致时才算相同
return categorizedSources1.equals(categorizedSources2);
}
private Set<String> categorizeOrderEntry(List<String> orderEntrys) {
Set<String> categorizedSources = new HashSet<>();
boolean hasBackend = false;
boolean hasClient = false;
for (String orderEntry : orderEntrys) {
if (orderEntry.equals("1")) {
hasBackend = true;
} else if (orderEntry.equals("2") || orderEntry.equals("3")) {
hasClient = true;
}
}
// 如果同时有后台和客户端,归为 "ALL"
if (hasBackend && hasClient) {
categorizedSources.add("ALL");
} else {
if (hasBackend) {
categorizedSources.add("BACKEND");
}
if (hasClient) {
categorizedSources.add("CLIENT");
}
}
return categorizedSources;
}
/**
* 校验规则时间区间是否有交集
*/
......@@ -194,7 +305,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) {
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() != OCEAN_LCL.getValue() && extraOrderV.getTransportType() != SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_TRANSPORT_TYPE_ERROR);
}
// 国家,城市,仓库id从receiveAddrList中获取
......@@ -389,9 +500,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (scoreRuleDO.getType() != ScoreRuleTypeEnum.SHARE.getValue()) {
if (scoreRuleDO.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) {
ScoreRuleOrderVExtraVO extraOrderV = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
scoreRuleUniqueCheck(scoreRuleDO.getType(), extraOrderV.getTransportType(), scoreRuleDO.getStartTime(), scoreRuleDO.getEndTime(), null);
orderVUniqueCheck(extraOrderV, scoreRuleDO.getStartTime(), scoreRuleDO.getEndTime(), null);
} else {
scoreRuleUniqueCheck(scoreRuleDO.getType(), null, scoreRuleDO.getStartTime(), scoreRuleDO.getEndTime(), null);
scoreRuleUniqueCheck(scoreRuleDO.getType(), scoreRuleDO.getStartTime(), scoreRuleDO.getEndTime(), null);
}
}
upScoreRuleDO.setStatus(scoreRuleStatusReqVO.getStatus());
......@@ -435,9 +546,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
// 新时间区间规则唯一校验
if (scoreRuleDO.getType() == ScoreRuleTypeEnum.ORDER_V.getValue()) {
ScoreRuleOrderVExtraVO extraOrderV = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
scoreRuleUniqueCheck(scoreRuleDO.getType(), extraOrderV.getTransportType(), scoreRuleDO.getStartTime(), delayReqVO.getEndTime(), scoreRuleDO.getId());
orderVUniqueCheck(extraOrderV, scoreRuleDO.getStartTime(), delayReqVO.getEndTime(), scoreRuleDO.getId());
} else {
scoreRuleUniqueCheck(scoreRuleDO.getType(), null, scoreRuleDO.getStartTime(), delayReqVO.getEndTime(), scoreRuleDO.getId());
scoreRuleUniqueCheck(scoreRuleDO.getType(), scoreRuleDO.getStartTime(), delayReqVO.getEndTime(), scoreRuleDO.getId());
}
ScoreRuleDO upScoreRuleDO = new ScoreRuleDO();
upScoreRuleDO.setId(delayReqVO.getId());
......@@ -447,7 +558,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()) {
if (transportType != OCEAN_LCL.getValue() && transportType != SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_TRANSPORT_TYPE_ERROR);
}
LambdaQuery<ScoreRuleDO> lambdaQuery = new LambdaQuery<>();
......
......@@ -1057,7 +1057,7 @@ score.rule.update.error = only disabled rule can update
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 = The same rule already exists during the validity period
score.rule.unique.check.error = The same rule already exists during the validity period: {}
score.rule.transport.type.error = transport type error
score.rule.time.error = score rule time error
score.rule.period.error = score rule period error
......
......@@ -1058,7 +1058,7 @@ score.rule.update.error = \u53EA\u6709\u672A\u542F\u7528\u89C4\u5219\u53EF\u4EE5
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 = \u6709\u6548\u671F\u5185\u5DF2\u5B58\u5728\u76F8\u540C\u89C4\u5219
score.rule.unique.check.error = \u6709\u6548\u671F\u5185\u5DF2\u5B58\u5728\u76F8\u540C\u89C4\u5219\uFF1A{}
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
......
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