Commit 6e111540101da844f3b83a4557f92203ff9fdfc2
1 parent
ffbf9278
SPU: 添加选择优惠卷
Showing
14 changed files
with
180 additions
and
29 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java
| @@ -34,8 +34,9 @@ public interface ErrorCodeConstants { | @@ -34,8 +34,9 @@ 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【{}】不处于上架状态"); | ||
| 38 | - ErrorCode SPU_NOT_RECYCLE = new ErrorCode(1_008_005_003, "商品 SPU 不处于回收站状态"); | 37 | + ErrorCode SPU_SAVE_FAIL_COUPON_TEMPLATE_NOT_EXISTS = new ErrorCode(1_008_005_002, "商品 SPU 保存失败,原因:优惠卷不存在"); |
| 38 | + ErrorCode SPU_NOT_ENABLE = new ErrorCode(1_008_005_003, "商品 SPU【{}】不处于上架状态"); | ||
| 39 | + ErrorCode SPU_NOT_RECYCLE = new ErrorCode(1_008_005_004, "商品 SPU 不处于回收站状态"); | ||
| 39 | 40 | ||
| 40 | // ========== 商品 SKU 1-008-006-000 ========== | 41 | // ========== 商品 SKU 1-008-006-000 ========== |
| 41 | ErrorCode SKU_NOT_EXISTS = new ErrorCode(1_008_006_000, "商品 SKU 不存在"); | 42 | ErrorCode SKU_NOT_EXISTS = new ErrorCode(1_008_006_000, "商品 SKU 不存在"); |
yudao-module-mall/yudao-module-product-biz/pom.xml
| @@ -28,6 +28,11 @@ | @@ -28,6 +28,11 @@ | ||
| 28 | <artifactId>yudao-module-member-api</artifactId> | 28 | <artifactId>yudao-module-member-api</artifactId> |
| 29 | <version>${revision}</version> | 29 | <version>${revision}</version> |
| 30 | </dependency> | 30 | </dependency> |
| 31 | + <dependency> | ||
| 32 | + <groupId>cn.iocoder.boot</groupId> | ||
| 33 | + <artifactId>yudao-module-promotion-api</artifactId> | ||
| 34 | + <version>${revision}</version> | ||
| 35 | + </dependency> | ||
| 31 | 36 | ||
| 32 | <!-- 业务组件 --> | 37 | <!-- 业务组件 --> |
| 33 | <dependency> | 38 | <dependency> |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| @@ -11,6 +11,8 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | @@ -11,6 +11,8 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | ||
| 11 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | 11 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 12 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | 12 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 13 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | 13 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; |
| 14 | +import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi; | ||
| 15 | +import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | ||
| 14 | import io.swagger.v3.oas.annotations.Operation; | 16 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | import io.swagger.v3.oas.annotations.Parameter; | 17 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | import io.swagger.v3.oas.annotations.tags.Tag; | 18 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -43,6 +45,9 @@ public class ProductSpuController { | @@ -43,6 +45,9 @@ public class ProductSpuController { | ||
| 43 | @Resource | 45 | @Resource |
| 44 | private ProductSkuService productSkuService; | 46 | private ProductSkuService productSkuService; |
| 45 | 47 | ||
| 48 | + @Resource | ||
| 49 | + private CouponTemplateApi couponTemplateApi; | ||
| 50 | + | ||
| 46 | @PostMapping("/create") | 51 | @PostMapping("/create") |
| 47 | @Operation(summary = "创建商品 SPU") | 52 | @Operation(summary = "创建商品 SPU") |
| 48 | @PreAuthorize("@ss.hasPermission('product:spu:create')") | 53 | @PreAuthorize("@ss.hasPermission('product:spu:create')") |
| @@ -87,7 +92,10 @@ public class ProductSpuController { | @@ -87,7 +92,10 @@ public class ProductSpuController { | ||
| 87 | } | 92 | } |
| 88 | // 查询商品 SKU | 93 | // 查询商品 SKU |
| 89 | List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId()); | 94 | List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId()); |
| 90 | - return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus)); | 95 | + // 查询优惠卷 |
| 96 | + List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds( | ||
| 97 | + spu.getGiveCouponTemplateIds()); | ||
| 98 | + return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus, couponTemplateList)); | ||
| 91 | } | 99 | } |
| 92 | 100 | ||
| 93 | @GetMapping("/list-all-simple") | 101 | @GetMapping("/list-all-simple") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java
| @@ -96,19 +96,31 @@ public class ProductSpuBaseVO { | @@ -96,19 +96,31 @@ public class ProductSpuBaseVO { | ||
| 96 | @NotNull(message = "商品赠送积分不能为空") | 96 | @NotNull(message = "商品赠送积分不能为空") |
| 97 | private Integer giveIntegral; | 97 | private Integer giveIntegral; |
| 98 | 98 | ||
| 99 | - @Schema(description = "赠送的优惠劵编号的数组", example = "[1, 10]") // TODO 这块前端还未实现 | ||
| 100 | - private List<Long> giveCouponTemplateIds; | 99 | + @Schema(description = "赠送的优惠劵数组包含优惠券编号和名称") |
| 100 | + private List<GiveCouponTemplate> giveCouponTemplate; | ||
| 101 | 101 | ||
| 102 | @Schema(description = "分销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | 102 | @Schema(description = "分销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 103 | @NotNull(message = "商品分销类型不能为空") | 103 | @NotNull(message = "商品分销类型不能为空") |
| 104 | private Boolean subCommissionType; | 104 | private Boolean subCommissionType; |
| 105 | 105 | ||
| 106 | - @Schema(description = "活动展示顺序", example = "[1, 3, 2, 4, 5]") // TODO 这块前端还未实现 | 106 | + @Schema(description = "活动展示顺序", example = "[1, 3, 2, 4, 5]") |
| 107 | private List<Integer> activityOrders; | 107 | private List<Integer> activityOrders; |
| 108 | 108 | ||
| 109 | // ========== 统计相关字段 ========= | 109 | // ========== 统计相关字段 ========= |
| 110 | 110 | ||
| 111 | - @Schema(description = "虚拟销量", example = "芋道") | 111 | + @Schema(description = "虚拟销量", example = "66") |
| 112 | private Integer virtualSalesCount; | 112 | private Integer virtualSalesCount; |
| 113 | 113 | ||
| 114 | + @Schema(description = "管理后台 - 商品 SPU 赠送的优惠卷") | ||
| 115 | + @Data | ||
| 116 | + public static class GiveCouponTemplate { | ||
| 117 | + | ||
| 118 | + @Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 119 | + private Long id; | ||
| 120 | + | ||
| 121 | + @Schema(description = "优惠劵名", requiredMode = Schema.RequiredMode.REQUIRED, example = "春节送送送") | ||
| 122 | + private String name; | ||
| 123 | + | ||
| 124 | + } | ||
| 125 | + | ||
| 114 | } | 126 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
| @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | ||
| 12 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 12 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 13 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | 13 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 14 | import cn.iocoder.yudao.module.product.enums.DictTypeConstants; | 14 | import cn.iocoder.yudao.module.product.enums.DictTypeConstants; |
| 15 | +import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | ||
| 15 | import org.mapstruct.Mapper; | 16 | import org.mapstruct.Mapper; |
| 16 | import org.mapstruct.Mapping; | 17 | import org.mapstruct.Mapping; |
| 17 | import org.mapstruct.Named; | 18 | import org.mapstruct.Named; |
| @@ -100,10 +101,14 @@ public interface ProductSpuConvert { | @@ -100,10 +101,14 @@ public interface ProductSpuConvert { | ||
| 100 | 101 | ||
| 101 | List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus); | 102 | List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus); |
| 102 | 103 | ||
| 103 | - default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus) { | ||
| 104 | - ProductSpuDetailRespVO detailRespVO = convert03(spu); | ||
| 105 | - detailRespVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skus)); | ||
| 106 | - return detailRespVO; | 104 | + List<ProductSpuDetailRespVO.GiveCouponTemplate> convertList04(List<CouponTemplateRespDTO> couponTemplateList); |
| 105 | + | ||
| 106 | + default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus, | ||
| 107 | + List<CouponTemplateRespDTO> couponTemplateList) { | ||
| 108 | + ProductSpuDetailRespVO respVO = convert03(spu); | ||
| 109 | + respVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skus)); | ||
| 110 | + respVO.setGiveCouponTemplate(convertList04(couponTemplateList)); | ||
| 111 | + return respVO; | ||
| 107 | } | 112 | } |
| 108 | 113 | ||
| 109 | default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) { | 114 | default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) { |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| @@ -16,8 +16,10 @@ import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; | @@ -16,8 +16,10 @@ import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; | ||
| 16 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | 16 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 17 | import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; | 17 | import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; |
| 18 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; | 18 | import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; |
| 19 | -import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; | ||
| 20 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | 19 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 20 | +import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi; | ||
| 21 | +import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | ||
| 22 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; | ||
| 21 | import com.google.common.collect.Maps; | 23 | import com.google.common.collect.Maps; |
| 22 | import org.springframework.context.annotation.Lazy; | 24 | import org.springframework.context.annotation.Lazy; |
| 23 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
| @@ -26,10 +28,10 @@ import org.springframework.validation.annotation.Validated; | @@ -26,10 +28,10 @@ import org.springframework.validation.annotation.Validated; | ||
| 26 | 28 | ||
| 27 | import javax.annotation.Resource; | 29 | import javax.annotation.Resource; |
| 28 | import java.util.*; | 30 | import java.util.*; |
| 31 | +import java.util.stream.Collectors; | ||
| 29 | 32 | ||
| 30 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 31 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMinValue; | ||
| 32 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; | 34 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 33 | import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL; | 35 | import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL; |
| 34 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; | 36 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; |
| 35 | 37 | ||
| @@ -52,9 +54,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -52,9 +54,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 52 | private ProductBrandService brandService; | 54 | private ProductBrandService brandService; |
| 53 | @Resource | 55 | @Resource |
| 54 | private ProductCategoryService categoryService; | 56 | private ProductCategoryService categoryService; |
| 57 | + | ||
| 55 | @Resource | 58 | @Resource |
| 56 | - @Lazy // 循环依赖,避免报错 | ||
| 57 | - private ProductPropertyValueService productPropertyValueService; | 59 | + private CouponTemplateApi couponTemplateApi; |
| 58 | 60 | ||
| 59 | @Override | 61 | @Override |
| 60 | @Transactional(rollbackFor = Exception.class) | 62 | @Transactional(rollbackFor = Exception.class) |
| @@ -62,6 +64,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -62,6 +64,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 62 | // 校验分类、品牌 | 64 | // 校验分类、品牌 |
| 63 | validateCategory(createReqVO.getCategoryId()); | 65 | validateCategory(createReqVO.getCategoryId()); |
| 64 | brandService.validateProductBrand(createReqVO.getBrandId()); | 66 | brandService.validateProductBrand(createReqVO.getBrandId()); |
| 67 | + // 校验优惠券 | ||
| 68 | + Set<Long> giveCouponTemplateIds = convertSet(createReqVO.getGiveCouponTemplate(), ProductSpuCreateReqVO.GiveCouponTemplate::getId); | ||
| 69 | + validateCouponTemplate(giveCouponTemplateIds); | ||
| 65 | // 校验 SKU | 70 | // 校验 SKU |
| 66 | List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus(); | 71 | List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus(); |
| 67 | productSkuService.validateSkuList(skuSaveReqList, createReqVO.getSpecType()); | 72 | productSkuService.validateSkuList(skuSaveReqList, createReqVO.getSpecType()); |
| @@ -69,6 +74,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -69,6 +74,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 69 | ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); | 74 | ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); |
| 70 | // 初始化 SPU 中 SKU 相关属性 | 75 | // 初始化 SPU 中 SKU 相关属性 |
| 71 | initSpuFromSkus(spu, skuSaveReqList); | 76 | initSpuFromSkus(spu, skuSaveReqList); |
| 77 | + // 设置优惠券 | ||
| 78 | + spu.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds)); | ||
| 72 | // 插入 SPU | 79 | // 插入 SPU |
| 73 | productSpuMapper.insert(spu); | 80 | productSpuMapper.insert(spu); |
| 74 | // 插入 SKU | 81 | // 插入 SKU |
| @@ -85,6 +92,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -85,6 +92,9 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 85 | // 校验分类、品牌 | 92 | // 校验分类、品牌 |
| 86 | validateCategory(updateReqVO.getCategoryId()); | 93 | validateCategory(updateReqVO.getCategoryId()); |
| 87 | brandService.validateProductBrand(updateReqVO.getBrandId()); | 94 | brandService.validateProductBrand(updateReqVO.getBrandId()); |
| 95 | + // 校验优惠券 | ||
| 96 | + Set<Long> giveCouponTemplateIds = convertSet(updateReqVO.getGiveCouponTemplate(), ProductSpuUpdateReqVO.GiveCouponTemplate::getId); | ||
| 97 | + validateCouponTemplate(giveCouponTemplateIds); | ||
| 88 | // 校验SKU | 98 | // 校验SKU |
| 89 | List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = updateReqVO.getSkus(); | 99 | List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = updateReqVO.getSkus(); |
| 90 | productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); | 100 | productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); |
| @@ -92,6 +102,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -92,6 +102,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 92 | // 更新 SPU | 102 | // 更新 SPU |
| 93 | ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); | 103 | ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); |
| 94 | initSpuFromSkus(updateObj, skuSaveReqList); | 104 | initSpuFromSkus(updateObj, skuSaveReqList); |
| 105 | + // 设置优惠券 | ||
| 106 | + updateObj.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds)); | ||
| 95 | productSpuMapper.updateById(updateObj); | 107 | productSpuMapper.updateById(updateObj); |
| 96 | // 批量更新 SKU | 108 | // 批量更新 SKU |
| 97 | productSkuService.updateSkuList(updateObj.getId(), updateReqVO.getSkus()); | 109 | productSkuService.updateSkuList(updateObj.getId(), updateReqVO.getSkus()); |
| @@ -125,6 +137,10 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -125,6 +137,10 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 125 | // 默认商品浏览量 | 137 | // 默认商品浏览量 |
| 126 | spu.setBrowseCount(0); | 138 | spu.setBrowseCount(0); |
| 127 | } | 139 | } |
| 140 | + // 如果活动顺序为空则默认初始化 | ||
| 141 | + if (CollUtil.isEmpty(spu.getActivityOrders())) { | ||
| 142 | + spu.setActivityOrders(Arrays.stream(PromotionTypeEnum.ARRAYS).boxed().collect(Collectors.toList())); | ||
| 143 | + } | ||
| 128 | } | 144 | } |
| 129 | 145 | ||
| 130 | /** | 146 | /** |
| @@ -140,6 +156,13 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -140,6 +156,13 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 140 | } | 156 | } |
| 141 | } | 157 | } |
| 142 | 158 | ||
| 159 | + private void validateCouponTemplate(Collection<Long> ids) { | ||
| 160 | + List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(ids); | ||
| 161 | + if (couponTemplateList.size() != ids.size()) { | ||
| 162 | + throw exception(SPU_SAVE_FAIL_COUPON_TEMPLATE_NOT_EXISTS); | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + | ||
| 143 | @Override | 166 | @Override |
| 144 | public List<ProductSpuDO> validateSpuList(Collection<Long> ids) { | 167 | public List<ProductSpuDO> validateSpuList(Collection<Long> ids) { |
| 145 | if (CollUtil.isEmpty(ids)) { | 168 | if (CollUtil.isEmpty(ids)) { |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/CouponTemplateApi.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.coupon; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | ||
| 4 | + | ||
| 5 | +import java.util.Collection; | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 优惠劵模版 API 接口 | ||
| 10 | + * | ||
| 11 | + * @author HUIHUI | ||
| 12 | + */ | ||
| 13 | +public interface CouponTemplateApi { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 获得优惠券模版的精简信息列表 | ||
| 17 | + * | ||
| 18 | + * @param ids 优惠券模版编号 | ||
| 19 | + * @return 优惠券模版的精简信息列表 | ||
| 20 | + */ | ||
| 21 | + List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids); | ||
| 22 | + | ||
| 23 | +} |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/dto/CouponTemplateRespDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.coupon.dto; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 优惠券模版 Response DTO | ||
| 8 | + * | ||
| 9 | + * @author HUIHUI | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class CouponTemplateRespDTO { | ||
| 13 | + /** | ||
| 14 | + * 模板编号,自增唯一 | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | + private Long id; | ||
| 18 | + /** | ||
| 19 | + * 优惠劵名 | ||
| 20 | + */ | ||
| 21 | + private String name; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 状态 | ||
| 25 | + * | ||
| 26 | + * 枚举 {@link CommonStatusEnum} | ||
| 27 | + */ | ||
| 28 | + private Integer status; | ||
| 29 | + | ||
| 30 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/coupon/CouponTemplateApiImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.coupon; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.convert.coupon.CouponTemplateConvert; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService; | ||
| 6 | +import org.springframework.stereotype.Service; | ||
| 7 | + | ||
| 8 | +import javax.annotation.Resource; | ||
| 9 | +import java.util.Collection; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 优惠劵模版 API 接口实现类 | ||
| 14 | + * | ||
| 15 | + * @author HUIHUI | ||
| 16 | + */ | ||
| 17 | +@Service | ||
| 18 | +public class CouponTemplateApiImpl implements CouponTemplateApi { | ||
| 19 | + | ||
| 20 | + @Resource | ||
| 21 | + private CouponTemplateService couponTemplateService; | ||
| 22 | + | ||
| 23 | + @Override | ||
| 24 | + public List<CouponTemplateRespDTO> getCouponTemplateListByIds(Collection<Long> ids) { | ||
| 25 | + return CouponTemplateConvert.INSTANCE.convertList(couponTemplateService.getCouponTemplateListByIds(ids)); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/coupon/CouponTemplateConvert.java
| @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.convert.coupon; | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.convert.coupon; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO; | ||
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateCreateReqVO; | 6 | 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; | 7 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplatePageReqVO; |
| 7 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.template.CouponTemplateRespVO; |
| @@ -58,4 +59,6 @@ public interface CouponTemplateConvert { | @@ -58,4 +59,6 @@ public interface CouponTemplateConvert { | ||
| 58 | } | 59 | } |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 62 | + List<CouponTemplateRespDTO> convertList(List<CouponTemplateDO> list); | ||
| 63 | + | ||
| 61 | } | 64 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponTemplateMapper.java
| @@ -8,10 +8,11 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -8,10 +8,11 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 8 | 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; |
| 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; |
| 10 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 10 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 11 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||
| 11 | import org.apache.ibatis.annotations.Mapper; | 12 | import org.apache.ibatis.annotations.Mapper; |
| 12 | -import org.apache.ibatis.annotations.Param; | ||
| 13 | 13 | ||
| 14 | import java.time.LocalDateTime; | 14 | import java.time.LocalDateTime; |
| 15 | +import java.util.Collection; | ||
| 15 | import java.util.List; | 16 | import java.util.List; |
| 16 | import java.util.function.Consumer; | 17 | import java.util.function.Consumer; |
| 17 | 18 | ||
| @@ -39,7 +40,11 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | @@ -39,7 +40,11 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | ||
| 39 | .orderByDesc(CouponTemplateDO::getId)); | 40 | .orderByDesc(CouponTemplateDO::getId)); |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | - void updateTakeCount(@Param("id") Long id, @Param("incrCount") Integer incrCount); | 43 | + default void updateTakeCount(Long id, Integer incrCount) { |
| 44 | + update(null, new LambdaUpdateWrapper<CouponTemplateDO>() | ||
| 45 | + .eq(CouponTemplateDO::getId, id) | ||
| 46 | + .setSql("take_count = take_count + " + incrCount)); | ||
| 47 | + } | ||
| 43 | 48 | ||
| 44 | default List<CouponTemplateDO> selectListByTakeType(Integer takeType) { | 49 | default List<CouponTemplateDO> selectListByTakeType(Integer takeType) { |
| 45 | return selectList(CouponTemplateDO::getTakeType, takeType); | 50 | return selectList(CouponTemplateDO::getTakeType, takeType); |
| @@ -70,4 +75,8 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | @@ -70,4 +75,8 @@ public interface CouponTemplateMapper extends BaseMapperX<CouponTemplateDO> { | ||
| 70 | return canTakeConsumer; | 75 | return canTakeConsumer; |
| 71 | } | 76 | } |
| 72 | 77 | ||
| 78 | + default List<CouponTemplateDO> selectListByIds(Collection<Long> ids) { | ||
| 79 | + return selectList(new LambdaQueryWrapperX<CouponTemplateDO>().in(CouponTemplateDO::getId, ids)); | ||
| 80 | + } | ||
| 81 | + | ||
| 73 | } | 82 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java
| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; | ||
| 8 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; | 8 | import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; |
| 9 | 9 | ||
| 10 | import javax.validation.Valid; | 10 | import javax.validation.Valid; |
| 11 | +import java.util.Collection; | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| @@ -91,4 +92,12 @@ public interface CouponTemplateService { | @@ -91,4 +92,12 @@ public interface CouponTemplateService { | ||
| 91 | List<CouponTemplateDO> getCouponTemplateList(List<Integer> canTakeTypes, Integer productScope, | 92 | List<CouponTemplateDO> getCouponTemplateList(List<Integer> canTakeTypes, Integer productScope, |
| 92 | Long productScopeValue, Integer count); | 93 | Long productScopeValue, Integer count); |
| 93 | 94 | ||
| 95 | + /** | ||
| 96 | + * 获得优惠券模版列表 | ||
| 97 | + * | ||
| 98 | + * @param ids 优惠券模版编号 | ||
| 99 | + * @return 优惠券模版列表 | ||
| 100 | + */ | ||
| 101 | + List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids); | ||
| 102 | + | ||
| 94 | } | 103 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; | @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; | ||
| 16 | import org.springframework.validation.annotation.Validated; | 16 | import org.springframework.validation.annotation.Validated; |
| 17 | 17 | ||
| 18 | import javax.annotation.Resource; | 18 | import javax.annotation.Resource; |
| 19 | +import java.util.Collection; | ||
| 19 | import java.util.List; | 20 | import java.util.List; |
| 20 | import java.util.Objects; | 21 | import java.util.Objects; |
| 21 | 22 | ||
| @@ -126,4 +127,9 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -126,4 +127,9 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 126 | return couponTemplateMapper.selectList(canTakeTypes, productScope, productScopeValue, count); | 127 | return couponTemplateMapper.selectList(canTakeTypes, productScope, productScopeValue, count); |
| 127 | } | 128 | } |
| 128 | 129 | ||
| 130 | + @Override | ||
| 131 | + public List<CouponTemplateDO> getCouponTemplateListByIds(Collection<Long> ids) { | ||
| 132 | + return couponTemplateMapper.selectListByIds(ids); | ||
| 133 | + } | ||
| 134 | + | ||
| 129 | } | 135 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/resources/mapper/coupon/CouponTemplateMapper.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | -<mapper namespace="cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper"> | ||
| 4 | - | ||
| 5 | - <update id="updateTakeCount"> | ||
| 6 | - UPDATE promotion_coupon_template | ||
| 7 | - SET take_count = take_count + #{incrCount} | ||
| 8 | - WHERE id = #{id} | ||
| 9 | - </update> | ||
| 10 | - | ||
| 11 | -</mapper> |