Commit d0d21b27875c1093e94bc4c68d7adb8bab814fac
1 parent
42a899c5
优惠券:新增/修改时,校验对应的商品、分类是否存在
Showing
11 changed files
with
164 additions
and
20 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/category/ProductCategoryApi.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.api.category; | ||
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 商品分类 API 接口 | ||
| 7 | + * | ||
| 8 | + * @author owen | ||
| 9 | + */ | ||
| 10 | +public interface ProductCategoryApi { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 校验商品分类是否有效。如下情况,视为无效: | ||
| 14 | + * 1. 商品分类编号不存在 | ||
| 15 | + * 2. 商品分类被禁用 | ||
| 16 | + * | ||
| 17 | + * @param ids 商品分类编号数组 | ||
| 18 | + */ | ||
| 19 | + void validateCategoryList(Collection<Long> ids); | ||
| 20 | +} |
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApi.java
| @@ -22,10 +22,26 @@ public interface ProductSpuApi { | @@ -22,10 +22,26 @@ public interface ProductSpuApi { | ||
| 22 | List<ProductSpuRespDTO> getSpuList(Collection<Long> ids); | 22 | List<ProductSpuRespDTO> getSpuList(Collection<Long> ids); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | + * 批量查询 SPU 数组,并且校验是否 SPU 是否有效 | ||
| 26 | + * | ||
| 27 | + * @param ids SPU 编号列表 | ||
| 28 | + * @return SPU 数组 | ||
| 29 | + */ | ||
| 30 | + List<ProductSpuRespDTO> getSpuListAndValidate(Collection<Long> ids); | ||
| 31 | + | ||
| 32 | + /** | ||
| 25 | * 获得 SPU | 33 | * 获得 SPU |
| 26 | * | 34 | * |
| 27 | * @return SPU | 35 | * @return SPU |
| 28 | */ | 36 | */ |
| 29 | ProductSpuRespDTO getSpu(Long id); | 37 | ProductSpuRespDTO getSpu(Long id); |
| 30 | 38 | ||
| 39 | + /** | ||
| 40 | + * 校验商品是否有效。如下情况,视为无效: | ||
| 41 | + * 1. 商品编号不存在 | ||
| 42 | + * 2. 商品被禁用 | ||
| 43 | + * | ||
| 44 | + * @param ids 商品编号数组 | ||
| 45 | + */ | ||
| 46 | + void validateSpuList(Collection<Long> ids); | ||
| 31 | } | 47 | } |
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java
| @@ -34,7 +34,7 @@ public interface ErrorCodeConstants { | @@ -34,7 +34,7 @@ public interface ErrorCodeConstants { | ||
| 34 | // ========== 商品 SPU 1-008-005-000 ========== | 34 | // ========== 商品 SPU 1-008-005-000 ========== |
| 35 | ErrorCode SPU_NOT_EXISTS = new ErrorCode(1_008_005_000, "商品 SPU 不存在"); | 35 | ErrorCode SPU_NOT_EXISTS = new ErrorCode(1_008_005_000, "商品 SPU 不存在"); |
| 36 | ErrorCode SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR = new ErrorCode(1_008_005_001, "商品分类不正确,原因:必须使用第二级的商品分类及以下"); | 36 | ErrorCode SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR = new ErrorCode(1_008_005_001, "商品分类不正确,原因:必须使用第二级的商品分类及以下"); |
| 37 | - ErrorCode SPU_NOT_ENABLE = new ErrorCode(1_008_005_002, "商品 SPU 不处于上架状态"); | 37 | + ErrorCode SPU_NOT_ENABLE = new ErrorCode(1_008_005_002, "商品 SPU【[]】不处于上架状态"); |
| 38 | ErrorCode SPU_NOT_RECYCLE = new ErrorCode(1_008_005_003, "商品 SPU 不处于回收站状态"); | 38 | ErrorCode SPU_NOT_RECYCLE = new ErrorCode(1_008_005_003, "商品 SPU 不处于回收站状态"); |
| 39 | 39 | ||
| 40 | // ========== 商品 SKU 1-008-006-000 ========== | 40 | // ========== 商品 SKU 1-008-006-000 ========== |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/category/ProductCategoryApiImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.product.api.category; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; | ||
| 4 | +import org.springframework.stereotype.Service; | ||
| 5 | +import org.springframework.validation.annotation.Validated; | ||
| 6 | + | ||
| 7 | +import javax.annotation.Resource; | ||
| 8 | +import java.util.Collection; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 商品分类 API 接口实现类 | ||
| 12 | + * | ||
| 13 | + * @author owen | ||
| 14 | + */ | ||
| 15 | +@Service | ||
| 16 | +@Validated | ||
| 17 | +public class ProductCategoryApiImpl implements ProductCategoryApi { | ||
| 18 | + | ||
| 19 | + @Resource | ||
| 20 | + private ProductCategoryService productCategoryService; | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public void validateCategoryList(Collection<Long> ids) { | ||
| 24 | + productCategoryService.validateCategoryList(ids); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | +} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApiImpl.java
| @@ -3,9 +3,6 @@ package cn.iocoder.yudao.module.product.api.spu; | @@ -3,9 +3,6 @@ package cn.iocoder.yudao.module.product.api.spu; | ||
| 3 | import cn.hutool.core.collection.CollectionUtil; | 3 | import cn.hutool.core.collection.CollectionUtil; |
| 4 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | 4 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 5 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; | 5 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; |
| 6 | -import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | ||
| 7 | -import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; | ||
| 8 | -import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | ||
| 9 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | 6 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; |
| 10 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.validation.annotation.Validated; | 8 | import org.springframework.validation.annotation.Validated; |
| @@ -37,8 +34,18 @@ public class ProductSpuApiImpl implements ProductSpuApi { | @@ -37,8 +34,18 @@ public class ProductSpuApiImpl implements ProductSpuApi { | ||
| 37 | } | 34 | } |
| 38 | 35 | ||
| 39 | @Override | 36 | @Override |
| 37 | + public List<ProductSpuRespDTO> getSpuListAndValidate(Collection<Long> ids) { | ||
| 38 | + return ProductSpuConvert.INSTANCE.convertList2(spuService.validateSpuList(ids)); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 40 | public ProductSpuRespDTO getSpu(Long id) { | 42 | public ProductSpuRespDTO getSpu(Long id) { |
| 41 | return ProductSpuConvert.INSTANCE.convert02(spuService.getSpu(id)); | 43 | return ProductSpuConvert.INSTANCE.convert02(spuService.getSpu(id)); |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 46 | + @Override | ||
| 47 | + public void validateSpuList(Collection<Long> ids) { | ||
| 48 | + spuService.validateSpuList(ids); | ||
| 49 | + } | ||
| 50 | + | ||
| 44 | } | 51 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryService.java
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCateg | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCateg | ||
| 6 | import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; |
| 7 | 7 | ||
| 8 | import javax.validation.Valid; | 8 | import javax.validation.Valid; |
| 9 | +import java.util.Collection; | ||
| 9 | import java.util.List; | 10 | import java.util.List; |
| 10 | 11 | ||
| 11 | /** | 12 | /** |
| @@ -75,4 +76,12 @@ public interface ProductCategoryService { | @@ -75,4 +76,12 @@ public interface ProductCategoryService { | ||
| 75 | */ | 76 | */ |
| 76 | List<ProductCategoryDO> getEnableCategoryList(); | 77 | List<ProductCategoryDO> getEnableCategoryList(); |
| 77 | 78 | ||
| 79 | + /** | ||
| 80 | + * 校验商品分类是否有效。如下情况,视为无效: | ||
| 81 | + * 1. 商品分类编号不存在 | ||
| 82 | + * 2. 商品分类被禁用 | ||
| 83 | + * | ||
| 84 | + * @param ids 商品分类编号数组 | ||
| 85 | + */ | ||
| 86 | + void validateCategoryList(Collection<Long> ids); | ||
| 78 | } | 87 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.category; | 1 | package cn.iocoder.yudao.module.product.service.category; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 4 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; |
| 5 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; | 7 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; |
| 6 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; | 8 | import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; |
| @@ -13,7 +15,9 @@ import org.springframework.stereotype.Service; | @@ -13,7 +15,9 @@ import org.springframework.stereotype.Service; | ||
| 13 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
| 14 | 16 | ||
| 15 | import javax.annotation.Resource; | 17 | import javax.annotation.Resource; |
| 18 | +import java.util.Collection; | ||
| 16 | import java.util.List; | 19 | import java.util.List; |
| 20 | +import java.util.Map; | ||
| 17 | import java.util.Objects; | 21 | import java.util.Objects; |
| 18 | 22 | ||
| 19 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 23 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -100,6 +104,26 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { | @@ -100,6 +104,26 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { | ||
| 100 | } | 104 | } |
| 101 | 105 | ||
| 102 | @Override | 106 | @Override |
| 107 | + public void validateCategoryList(Collection<Long> ids) { | ||
| 108 | + if (CollUtil.isEmpty(ids)) { | ||
| 109 | + return; | ||
| 110 | + } | ||
| 111 | + // 获得商品分类信息 | ||
| 112 | + List<ProductCategoryDO> categoryList = productCategoryMapper.selectBatchIds(ids); | ||
| 113 | + Map<Long, ProductCategoryDO> categoryMap = CollectionUtils.convertMap(categoryList, ProductCategoryDO::getId); | ||
| 114 | + // 校验 | ||
| 115 | + ids.forEach(id -> { | ||
| 116 | + ProductCategoryDO category = categoryMap.get(id); | ||
| 117 | + if (category == null) { | ||
| 118 | + throw exception(CATEGORY_NOT_EXISTS); | ||
| 119 | + } | ||
| 120 | + if (!CommonStatusEnum.ENABLE.getStatus().equals(category.getStatus())) { | ||
| 121 | + throw exception(CATEGORY_DISABLED, category.getName()); | ||
| 122 | + } | ||
| 123 | + }); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + @Override | ||
| 103 | public ProductCategoryDO getCategory(Long id) { | 127 | public ProductCategoryDO getCategory(Long id) { |
| 104 | return productCategoryMapper.selectById(id); | 128 | return productCategoryMapper.selectById(id); |
| 105 | } | 129 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java
| @@ -136,4 +136,14 @@ public interface ProductSpuService { | @@ -136,4 +136,14 @@ public interface ProductSpuService { | ||
| 136 | */ | 136 | */ |
| 137 | Long getSpuCountByCategoryId(Long categoryId); | 137 | Long getSpuCountByCategoryId(Long categoryId); |
| 138 | 138 | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * 校验商品是否有效。如下情况,视为无效: | ||
| 142 | + * 1. 商品编号不存在 | ||
| 143 | + * 2. 商品被禁用 | ||
| 144 | + * | ||
| 145 | + * @param ids 商品编号数组 | ||
| 146 | + * @return 商品 SPU 列表 | ||
| 147 | + */ | ||
| 148 | + List<ProductSpuDO> validateSpuList(Collection<Long> ids); | ||
| 139 | } | 149 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.spu; | 1 | package cn.iocoder.yudao.module.product.service.spu; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ObjectUtil; | 4 | import cn.hutool.core.util.ObjectUtil; |
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -140,6 +141,28 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -140,6 +141,28 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 140 | } | 141 | } |
| 141 | 142 | ||
| 142 | @Override | 143 | @Override |
| 144 | + public List<ProductSpuDO> validateSpuList(Collection<Long> ids) { | ||
| 145 | + if (CollUtil.isEmpty(ids)) { | ||
| 146 | + return Collections.emptyList(); | ||
| 147 | + } | ||
| 148 | + // 获得商品信息 | ||
| 149 | + List<ProductSpuDO> spuList = productSpuMapper.selectBatchIds(ids); | ||
| 150 | + Map<Long, ProductSpuDO> spuMap = CollectionUtils.convertMap(spuList, ProductSpuDO::getId); | ||
| 151 | + // 校验 | ||
| 152 | + ids.forEach(id -> { | ||
| 153 | + ProductSpuDO spu = spuMap.get(id); | ||
| 154 | + if (spu == null) { | ||
| 155 | + throw exception(SPU_NOT_EXISTS); | ||
| 156 | + } | ||
| 157 | + if (!ProductSpuStatusEnum.isEnable(spu.getStatus())) { | ||
| 158 | + throw exception(SPU_NOT_ENABLE, spu.getName()); | ||
| 159 | + } | ||
| 160 | + }); | ||
| 161 | + | ||
| 162 | + return spuList; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + @Override | ||
| 143 | @Transactional(rollbackFor = Exception.class) | 166 | @Transactional(rollbackFor = Exception.class) |
| 144 | public void deleteSpu(Long id) { | 167 | public void deleteSpu(Long id) { |
| 145 | // 校验存在 | 168 | // 校验存在 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| @@ -2,19 +2,22 @@ package cn.iocoder.yudao.module.promotion.service.coupon; | @@ -2,19 +2,22 @@ package cn.iocoder.yudao.module.promotion.service.coupon; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi; | ||
| 6 | +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | ||
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateUpdateReqVO; | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateUpdateReqVO; |
| 8 | import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; | 10 | import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; |
| 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | 11 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 10 | import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper; | 12 | import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper; |
| 13 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; | ||
| 11 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; | 14 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; |
| 12 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 13 | import org.springframework.validation.annotation.Validated; | 16 | import org.springframework.validation.annotation.Validated; |
| 14 | 17 | ||
| 15 | import javax.annotation.Resource; | 18 | import javax.annotation.Resource; |
| 16 | - | ||
| 17 | import java.util.List; | 19 | import java.util.List; |
| 20 | +import java.util.Objects; | ||
| 18 | 21 | ||
| 19 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 20 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS; | 23 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS; |
| @@ -32,9 +35,15 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -32,9 +35,15 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 32 | @Resource | 35 | @Resource |
| 33 | private CouponTemplateMapper couponTemplateMapper; | 36 | private CouponTemplateMapper couponTemplateMapper; |
| 34 | 37 | ||
| 35 | - // TODO @疯狂:新增/修改时,需要校验对应的商品、分类是否存在 | 38 | + @Resource |
| 39 | + private ProductCategoryApi productCategoryApi; | ||
| 40 | + @Resource | ||
| 41 | + private ProductSpuApi productSpuApi; | ||
| 42 | + | ||
| 36 | @Override | 43 | @Override |
| 37 | public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { | 44 | public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { |
| 45 | + // 校验商品范围 | ||
| 46 | + validateProductScope(createReqVO.getProductScope(), createReqVO.getProductScopeValues()); | ||
| 38 | // 插入 | 47 | // 插入 |
| 39 | CouponTemplateDO couponTemplate = CouponTemplateConvert.INSTANCE.convert(createReqVO) | 48 | CouponTemplateDO couponTemplate = CouponTemplateConvert.INSTANCE.convert(createReqVO) |
| 40 | .setStatus(CommonStatusEnum.ENABLE.getStatus()); | 49 | .setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| @@ -51,6 +60,8 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -51,6 +60,8 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 51 | if (updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { | 60 | if (updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { |
| 52 | throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); | 61 | throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); |
| 53 | } | 62 | } |
| 63 | + // 校验商品范围 | ||
| 64 | + validateProductScope(updateReqVO.getProductScope(), updateReqVO.getProductScopeValues()); | ||
| 54 | 65 | ||
| 55 | // 更新 | 66 | // 更新 |
| 56 | CouponTemplateDO updateObj = CouponTemplateConvert.INSTANCE.convert(updateReqVO); | 67 | CouponTemplateDO updateObj = CouponTemplateConvert.INSTANCE.convert(updateReqVO); |
| @@ -81,6 +92,14 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -81,6 +92,14 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 81 | return couponTemplate; | 92 | return couponTemplate; |
| 82 | } | 93 | } |
| 83 | 94 | ||
| 95 | + private void validateProductScope(Integer productScope, List<Long> productScopeValues) { | ||
| 96 | + if (Objects.equals(PromotionProductScopeEnum.SPU.getScope(), productScope)) { | ||
| 97 | + productSpuApi.validateSpuList(productScopeValues); | ||
| 98 | + } else if (Objects.equals(PromotionProductScopeEnum.CATEGORY.getScope(), productScope)) { | ||
| 99 | + productCategoryApi.validateCategoryList(productScopeValues); | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + | ||
| 84 | @Override | 103 | @Override |
| 85 | public CouponTemplateDO getCouponTemplate(Long id) { | 104 | public CouponTemplateDO getCouponTemplate(Long id) { |
| 86 | return couponTemplateMapper.selectById(id); | 105 | return couponTemplateMapper.selectById(id); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java
| @@ -4,7 +4,6 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | @@ -4,7 +4,6 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | ||
| 4 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | 4 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; |
| 5 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | 5 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 6 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | 6 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 7 | -import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | ||
| 8 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; | 7 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; |
| 9 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; | 8 | import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; |
| 10 | import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculator; | 9 | import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculator; |
| @@ -20,7 +19,8 @@ import java.util.Map; | @@ -20,7 +19,8 @@ import java.util.Map; | ||
| 20 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 19 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 21 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | 20 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| 22 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | 21 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 23 | -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; | 22 | +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; |
| 23 | +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_STOCK_NOT_ENOUGH; | ||
| 24 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_PAY_PRICE_ILLEGAL; | 24 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_PAY_PRICE_ILLEGAL; |
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| @@ -82,18 +82,7 @@ public class TradePriceServiceImpl implements TradePriceService { | @@ -82,18 +82,7 @@ public class TradePriceServiceImpl implements TradePriceService { | ||
| 82 | 82 | ||
| 83 | private List<ProductSpuRespDTO> checkSpuList(List<ProductSkuRespDTO> skuList) { | 83 | private List<ProductSpuRespDTO> checkSpuList(List<ProductSkuRespDTO> skuList) { |
| 84 | // 获得商品 SPU 数组 | 84 | // 获得商品 SPU 数组 |
| 85 | - List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(convertSet(skuList, ProductSkuRespDTO::getSpuId)); | ||
| 86 | - | ||
| 87 | - // 校验商品 SPU | ||
| 88 | - spus.forEach(spu -> { | ||
| 89 | - if (spu == null) { | ||
| 90 | - throw exception(SPU_NOT_EXISTS); | ||
| 91 | - } | ||
| 92 | - if (!ProductSpuStatusEnum.isEnable(spu.getStatus())) { | ||
| 93 | - throw exception(SPU_NOT_ENABLE); | ||
| 94 | - } | ||
| 95 | - }); | ||
| 96 | - return spus; | 85 | + return productSpuApi.getSpuListAndValidate(convertSet(skuList, ProductSkuRespDTO::getSpuId)); |
| 97 | } | 86 | } |
| 98 | 87 | ||
| 99 | } | 88 | } |