mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
【代码优化】商城: 满减送活动
This commit is contained in:
parent
d9856ff79b
commit
1352613ebe
@ -40,13 +40,12 @@ public interface ErrorCodeConstants {
|
|||||||
|
|
||||||
// ========== 满减送活动 1-013-006-000 ==========
|
// ========== 满减送活动 1-013-006-000 ==========
|
||||||
ErrorCode REWARD_ACTIVITY_NOT_EXISTS = new ErrorCode(1_013_006_000, "满减送活动不存在");
|
ErrorCode REWARD_ACTIVITY_NOT_EXISTS = new ErrorCode(1_013_006_000, "满减送活动不存在");
|
||||||
ErrorCode REWARD_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1_013_006_001, "存在商品参加了其它满减送活动");
|
ErrorCode REWARD_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1_013_006_001, "该时间段存在商品参加了其它满减送活动");
|
||||||
ErrorCode REWARD_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1_013_006_002, "满减送活动已关闭,不能修改");
|
ErrorCode REWARD_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1_013_006_002, "满减送活动已关闭,不能修改");
|
||||||
ErrorCode REWARD_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED = new ErrorCode(1_013_006_003, "满减送活动未关闭,不能删除");
|
ErrorCode REWARD_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED = new ErrorCode(1_013_006_003, "满减送活动未关闭,不能删除");
|
||||||
ErrorCode REWARD_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1_013_006_004, "满减送活动已关闭,不能重复关闭");
|
ErrorCode REWARD_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1_013_006_004, "满减送活动已关闭,不能重复关闭");
|
||||||
ErrorCode REWARD_ACTIVITY_SCOPE_ALL_EXISTS = new ErrorCode(1_013_006_005, "已存在商品范围为全场的满减送活动");
|
ErrorCode REWARD_ACTIVITY_SCOPE_ALL_EXISTS = new ErrorCode(1_013_006_005, "该时间段已存在商品范围为全场的满减送活动");
|
||||||
ErrorCode REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS = new ErrorCode(1_013_006_006, "存在商品类型参加了其它满减送活动");
|
ErrorCode REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS = new ErrorCode(1_013_006_006, "该时间段存在商品类型参加了其它满减送活动");
|
||||||
ErrorCode REWARD_ACTIVITY_TIME_CONFLICTS = new ErrorCode(1_013_006_007, "满减送活动时段冲突");
|
|
||||||
|
|
||||||
// ========== TODO 空着 1-013-007-000 ============
|
// ========== TODO 空着 1-013-007-000 ============
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import static cn.hutool.core.collection.CollUtil.intersectionDistinct;
|
import static cn.hutool.core.collection.CollUtil.intersectionDistinct;
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
|
|
||||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,29 +115,29 @@ public class RewardActivityServiceImpl implements RewardActivityService {
|
|||||||
* @param rewardActivity 请求
|
* @param rewardActivity 请求
|
||||||
*/
|
*/
|
||||||
private void validateRewardActivitySpuConflicts(Long id, RewardActivityBaseVO rewardActivity) {
|
private void validateRewardActivitySpuConflicts(Long id, RewardActivityBaseVO rewardActivity) {
|
||||||
// 0. 获得所有的活动包括关闭的
|
// 0. 获得开启的所有的活动
|
||||||
List<RewardActivityDO> list = rewardActivityMapper.selectList();
|
List<RewardActivityDO> list = rewardActivityMapper.selectList(RewardActivityDO::getStatus, CommonStatusEnum.ENABLE.getStatus());
|
||||||
if (id != null) { // 排除自己这个活动
|
if (id != null) { // 排除自己这个活动
|
||||||
list.removeIf(activity -> id.equals(activity.getId()));
|
list.removeIf(activity -> id.equals(activity.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.1 校验满减送活动时间是否冲突
|
for (RewardActivityDO item : list) {
|
||||||
boolean hasConflict = list.stream().anyMatch(item -> LocalDateTimeUtil.isOverlap(item.getStartTime(), item.getEndTime(),
|
// 1.1 校验满减送活动时间是否冲突,如果时段不冲突那么不同的时间段内则可以存在相同的商品范围
|
||||||
rewardActivity.getStartTime(), rewardActivity.getEndTime()));
|
if (!LocalDateTimeUtil.isOverlap(item.getStartTime(), item.getEndTime(),
|
||||||
if (hasConflict) {
|
rewardActivity.getStartTime(), rewardActivity.getEndTime())) {
|
||||||
throw exception(REWARD_ACTIVITY_TIME_CONFLICTS);
|
continue;
|
||||||
}
|
}
|
||||||
// 1.2 校验商品范围是否重叠
|
// 1.2 校验商品范围是否重叠
|
||||||
if (PromotionProductScopeEnum.isAll(rewardActivity.getProductScope()) && // 情况一:全部商品参加
|
if (PromotionProductScopeEnum.isAll(rewardActivity.getProductScope()) &&
|
||||||
anyMatch(list, item -> PromotionProductScopeEnum.isAll(item.getProductScope()))) {
|
PromotionProductScopeEnum.isAll(item.getProductScope())) { // 情况一:全部商品参加
|
||||||
throw exception(REWARD_ACTIVITY_SCOPE_ALL_EXISTS);
|
throw exception(REWARD_ACTIVITY_SCOPE_ALL_EXISTS);
|
||||||
}
|
}
|
||||||
if (PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) || // 情况二:指定商品参加
|
if (PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) || // 情况二:指定商品参加
|
||||||
PromotionProductScopeEnum.isCategory(rewardActivity.getProductScope())) { // 情况三:指定商品类型参加
|
PromotionProductScopeEnum.isCategory(rewardActivity.getProductScope())) { // 情况三:指定商品类型参加
|
||||||
if (anyMatch(list, item -> !intersectionDistinct(item.getProductScopeValues(),
|
if (!intersectionDistinct(item.getProductScopeValues(), rewardActivity.getProductScopeValues()).isEmpty()) {
|
||||||
rewardActivity.getProductScopeValues()).isEmpty())) {
|
throw exception(PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) ?
|
||||||
throw exception(PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) ?
|
REWARD_ACTIVITY_SPU_CONFLICTS : REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS);
|
||||||
REWARD_ACTIVITY_SPU_CONFLICTS : REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user