【代码优化】商城: 满减送活动校验提示优化

This commit is contained in:
puhui999 2024-09-15 11:51:24 +08:00
parent a808157a62
commit ea6e365097
2 changed files with 8 additions and 8 deletions

View File

@ -44,7 +44,7 @@ public interface ErrorCodeConstants {
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_EXISTS = new ErrorCode(1_013_006_005, "与该时间段已存在的满减送活动商品范围冲突");
ErrorCode REWARD_ACTIVITY_SCOPE_EXISTS = new ErrorCode(1_013_006_005, "与该时间段满减送活动【{}】商品范围冲突,原因:{}");
// ========== TODO 空着 1-013-007-000 ============

View File

@ -135,16 +135,16 @@ public class RewardActivityServiceImpl implements RewardActivityService {
// 例如说rewardActivity 是全部活动结果有个 db 里的 activity 是某个分类它也是冲突的也就是说当前时间段内有且仅有只能有一个活动
if (PromotionProductScopeEnum.isAll(item.getProductScope()) ||
PromotionProductScopeEnum.isAll(rewardActivity.getProductScope())) {
// TODO puhui999需要提示出来与满减送活动xxx 活动存在商品范围冲突这里可能要分情况下面需要把 activityName 传入
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS);
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS, item.getName(),
PromotionProductScopeEnum.isAll(item.getProductScope()) ? "该活动商品范围为全部已覆盖包含本活动范围" :
"本活动商品范围为全部已覆盖包含了该活动商品范围");
}
// 情况二如果与该时间段内商品范围为类别的活动冲突
if (PromotionProductScopeEnum.isCategory(item.getProductScope())) {
// TODO puhui999前端我们有限制只允许子分类么可能要限制下不然基于分类查询不到对应的商品因为商品目前必须在子分类下
// 校验分类是否冲突
if (PromotionProductScopeEnum.isCategory(rewardActivity.getProductScope())) {
if (!intersectionDistinct(item.getProductScopeValues(), rewardActivity.getProductScopeValues()).isEmpty()) {
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS);
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS, item.getName(), "商品分类范围重叠");
}
}
// 校验商品分类是否冲突
@ -152,7 +152,7 @@ public class RewardActivityServiceImpl implements RewardActivityService {
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(rewardActivity.getProductScopeValues());
if (!intersectionDistinct(item.getProductScopeValues(),
convertSet(spuList, ProductSpuRespDTO::getCategoryId)).isEmpty()) {
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS);
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS, item.getName(), "该活动商品分类范围已包含本活动所选商品");
}
}
}
@ -161,7 +161,7 @@ public class RewardActivityServiceImpl implements RewardActivityService {
// 校验商品是否冲突
if (PromotionProductScopeEnum.isSpu(rewardActivity.getProductScope())) {
if (!intersectionDistinct(item.getProductScopeValues(), rewardActivity.getProductScopeValues()).isEmpty()) {
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS);
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS, item.getName(), "活动商品范围所选商品重叠");
}
}
// 校验商品分类是否冲突
@ -169,7 +169,7 @@ public class RewardActivityServiceImpl implements RewardActivityService {
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(item.getProductScopeValues());
if (!intersectionDistinct(rewardActivity.getProductScopeValues(),
convertSet(spuList, ProductSpuRespDTO::getCategoryId)).isEmpty()) {
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS);
throw exception(REWARD_ACTIVITY_SCOPE_EXISTS, item.getName(), "本活动商品分类范围包含了该活动所选商品");
}
}
}