diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 116e2fe42..841b4057e 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -40,13 +40,12 @@ public interface ErrorCodeConstants { // ========== 满减送活动 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_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_SCOPE_ALL_EXISTS = new ErrorCode(1_013_006_005, "已存在商品范围为全场的满减送活动"); - ErrorCode REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS = new ErrorCode(1_013_006_006, "存在商品类型参加了其它满减送活动"); - ErrorCode REWARD_ACTIVITY_TIME_CONFLICTS = new ErrorCode(1_013_006_007, "满减送活动时段冲突"); + ErrorCode REWARD_ACTIVITY_SCOPE_ALL_EXISTS = new ErrorCode(1_013_006_005, "该时间段已存在商品范围为全场的满减送活动"); + ErrorCode REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS = new ErrorCode(1_013_006_006, "该时间段存在商品类型参加了其它满减送活动"); // ========== TODO 空着 1-013-007-000 ============ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java index f12c0f284..f8299edea 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java @@ -24,7 +24,6 @@ import java.util.Objects; 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.util.collection.CollectionUtils.anyMatch; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; /** @@ -116,29 +115,29 @@ public class RewardActivityServiceImpl implements RewardActivityService { * @param rewardActivity 请求 */ private void validateRewardActivitySpuConflicts(Long id, RewardActivityBaseVO rewardActivity) { - // 0. 获得所有的活动包括关闭的 - List list = rewardActivityMapper.selectList(); + // 0. 获得开启的所有的活动 + List list = rewardActivityMapper.selectList(RewardActivityDO::getStatus, CommonStatusEnum.ENABLE.getStatus()); if (id != null) { // 排除自己这个活动 list.removeIf(activity -> id.equals(activity.getId())); } - // 1.1 校验满减送活动时间是否冲突 - boolean hasConflict = list.stream().anyMatch(item -> LocalDateTimeUtil.isOverlap(item.getStartTime(), item.getEndTime(), - rewardActivity.getStartTime(), rewardActivity.getEndTime())); - if (hasConflict) { - throw exception(REWARD_ACTIVITY_TIME_CONFLICTS); - } - // 1.2 校验商品范围是否重叠 - if (PromotionProductScopeEnum.isAll(rewardActivity.getProductScope()) && // 情况一:全部商品参加 - anyMatch(list, item -> PromotionProductScopeEnum.isAll(item.getProductScope()))) { - throw exception(REWARD_ACTIVITY_SCOPE_ALL_EXISTS); - } - if (PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) || // 情况二:指定商品参加 - PromotionProductScopeEnum.isCategory(rewardActivity.getProductScope())) { // 情况三:指定商品类型参加 - if (anyMatch(list, item -> !intersectionDistinct(item.getProductScopeValues(), - rewardActivity.getProductScopeValues()).isEmpty())) { - throw exception(PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) ? - REWARD_ACTIVITY_SPU_CONFLICTS : REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS); + for (RewardActivityDO item : list) { + // 1.1 校验满减送活动时间是否冲突,如果时段不冲突那么不同的时间段内则可以存在相同的商品范围 + if (!LocalDateTimeUtil.isOverlap(item.getStartTime(), item.getEndTime(), + rewardActivity.getStartTime(), rewardActivity.getEndTime())) { + continue; + } + // 1.2 校验商品范围是否重叠 + if (PromotionProductScopeEnum.isAll(rewardActivity.getProductScope()) && + PromotionProductScopeEnum.isAll(item.getProductScope())) { // 情况一:全部商品参加 + throw exception(REWARD_ACTIVITY_SCOPE_ALL_EXISTS); + } + if (PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) || // 情况二:指定商品参加 + PromotionProductScopeEnum.isCategory(rewardActivity.getProductScope())) { // 情况三:指定商品类型参加 + if (!intersectionDistinct(item.getProductScopeValues(), rewardActivity.getProductScopeValues()).isEmpty()) { + throw exception(PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope()) ? + REWARD_ACTIVITY_SPU_CONFLICTS : REWARD_ACTIVITY_SCOPE_CATEGORY_EXISTS); + } } } }