Commit e159b2e5005af3196aa846556fb46a03b9e2417d
1 parent
ba31d5f6
code review:砍价的代码
Showing
15 changed files
with
73 additions
and
136 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.bargain; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 7 | +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | |
| 6 | 8 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityCreateReqVO; |
| 7 | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; |
| 8 | 10 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityRespVO; |
| ... | ... | @@ -20,8 +22,8 @@ import org.springframework.web.bind.annotation.*; |
| 20 | 22 | |
| 21 | 23 | import javax.annotation.Resource; |
| 22 | 24 | import javax.validation.Valid; |
| 25 | +import java.util.Collections; | |
| 23 | 26 | import java.util.List; |
| 24 | -import java.util.Set; | |
| 25 | 27 | |
| 26 | 28 | import static cn.hutool.core.collection.CollectionUtil.newArrayList; |
| 27 | 29 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| ... | ... | @@ -37,7 +39,7 @@ public class BargainActivityController { |
| 37 | 39 | private BargainActivityService activityService; |
| 38 | 40 | |
| 39 | 41 | @Resource |
| 40 | - private ProductSpuApi spuApi; | |
| 42 | + private ProductSpuApi productSpuApi; | |
| 41 | 43 | |
| 42 | 44 | @PostMapping("/create") |
| 43 | 45 | @Operation(summary = "创建砍价活动") |
| ... | ... | @@ -80,12 +82,17 @@ public class BargainActivityController { |
| 80 | 82 | @Valid BargainActivityPageReqVO pageVO) { |
| 81 | 83 | // 查询砍价活动 |
| 82 | 84 | PageResult<BargainActivityDO> pageResult = activityService.getBargainActivityPage(pageVO); |
| 85 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 86 | + return success(PageResult.empty(pageResult.getTotal())); | |
| 87 | + } | |
| 88 | + | |
| 83 | 89 | // 拼接数据 |
| 84 | - Set<Long> activityIds = convertSet(pageResult.getList(), BargainActivityDO::getId); | |
| 85 | - Set<Long> spuIds = convertSet(pageResult.getList(), BargainActivityDO::getSpuId); | |
| 86 | - return success(BargainActivityConvert.INSTANCE.convertPage(pageResult, | |
| 87 | - activityService.getBargainProductsByActivityIds(activityIds), | |
| 88 | - spuApi.getSpuList(spuIds))); | |
| 90 | +// List<BargainProductDO> products = activityService.getBargainProductsByActivityIds( | |
| 91 | +// convertSet(pageResult.getList(), BargainActivityDO::getId)); | |
| 92 | + List<BargainProductDO> products = Collections.emptyList(); | |
| 93 | + List<ProductSpuRespDTO> spus = productSpuApi.getSpuList( | |
| 94 | + convertSet(pageResult.getList(), BargainActivityDO::getSpuId)); | |
| 95 | + return success(BargainActivityConvert.INSTANCE.convertPage(pageResult, products, spus)); | |
| 89 | 96 | } |
| 90 | 97 | |
| 91 | 98 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java
| ... | ... | @@ -22,7 +22,7 @@ public class BargainActivityBaseVO { |
| 22 | 22 | @NotNull(message = "砍价名称不能为空") |
| 23 | 23 | private String name; |
| 24 | 24 | |
| 25 | - @Schema(description = "商品 SPU 编号,关联 ProductSpuDO 的 id", example = "[1,2,3]") | |
| 25 | + @Schema(description = "商品 SPU 编号", example = "1") | |
| 26 | 26 | @NotNull(message = "砍价商品不能为空") |
| 27 | 27 | private Long spuId; |
| 28 | 28 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductCreateReqVO; | |
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; | |
| 4 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 5 | import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| ... | ... | @@ -17,6 +17,6 @@ public class BargainActivityCreateReqVO extends BargainActivityBaseVO { |
| 17 | 17 | |
| 18 | 18 | @Schema(description = "砍价商品", requiredMode = Schema.RequiredMode.REQUIRED) |
| 19 | 19 | @Valid |
| 20 | - private List<BargainProductCreateReqVO> products; | |
| 20 | + private List<BargainProductBaseVO> products; | |
| 21 | 21 | |
| 22 | 22 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java
| ... | ... | @@ -20,15 +20,6 @@ public class BargainActivityPageReqVO extends PageParam { |
| 20 | 20 | @Schema(description = "砍价名称", example = "赵六") |
| 21 | 21 | private String name; |
| 22 | 22 | |
| 23 | - @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") | |
| 24 | - private Long spuId; | |
| 25 | - | |
| 26 | - @Schema(description = "总限购数量", example = "16218") | |
| 27 | - private Integer totalLimitCount; | |
| 28 | - | |
| 29 | - @Schema(description = "单次限购数量", example = "28265") | |
| 30 | - private Integer singleLimitCount; | |
| 31 | - | |
| 32 | 23 | @Schema(description = "开始时间") |
| 33 | 24 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 34 | 25 | private LocalDateTime[] startTime; |
| ... | ... | @@ -37,29 +28,7 @@ public class BargainActivityPageReqVO extends PageParam { |
| 37 | 28 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 38 | 29 | private LocalDateTime[] endTime; |
| 39 | 30 | |
| 40 | - @Schema(description = "开团人数") | |
| 41 | - private Integer userSize; | |
| 42 | - | |
| 43 | - @Schema(description = "开团组数") | |
| 44 | - private Integer totalNum; | |
| 45 | - | |
| 46 | - @Schema(description = "成团组数") | |
| 47 | - private Integer successNum; | |
| 48 | - | |
| 49 | - @Schema(description = "参与人数", example = "25222") | |
| 50 | - private Integer orderUserCount; | |
| 51 | - | |
| 52 | - @Schema(description = "虚拟成团") | |
| 53 | - private Integer virtualGroup; | |
| 54 | - | |
| 55 | 31 | @Schema(description = "活动状态:0开启 1关闭", example = "0") |
| 56 | 32 | private Integer status; |
| 57 | 33 | |
| 58 | - @Schema(description = "限制时长(小时)") | |
| 59 | - private Integer limitDuration; | |
| 60 | - | |
| 61 | - @Schema(description = "创建时间") | |
| 62 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 63 | - private LocalDateTime[] createTime; | |
| 64 | - | |
| 65 | 34 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityRespVO.java
| ... | ... | @@ -6,7 +6,6 @@ import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| 7 | 7 | import lombok.ToString; |
| 8 | 8 | |
| 9 | -import javax.validation.Valid; | |
| 10 | 9 | import javax.validation.constraints.NotNull; |
| 11 | 10 | import java.time.LocalDateTime; |
| 12 | 11 | import java.util.List; |
| ... | ... | @@ -17,8 +16,6 @@ import java.util.List; |
| 17 | 16 | @ToString(callSuper = true) |
| 18 | 17 | public class BargainActivityRespVO extends BargainActivityBaseVO { |
| 19 | 18 | |
| 20 | - // TODO @puhui999:example 补全 | |
| 21 | - | |
| 22 | 19 | @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") |
| 23 | 20 | private String spuName; |
| 24 | 21 | |
| ... | ... | @@ -31,7 +28,7 @@ public class BargainActivityRespVO extends BargainActivityBaseVO { |
| 31 | 28 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 32 | 29 | private LocalDateTime createTime; |
| 33 | 30 | |
| 34 | - @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "888") | |
| 35 | 32 | private Integer successCount; |
| 36 | 33 | |
| 37 | 34 | @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| ... | ... | @@ -39,7 +36,6 @@ public class BargainActivityRespVO extends BargainActivityBaseVO { |
| 39 | 36 | private Integer status; |
| 40 | 37 | |
| 41 | 38 | @Schema(description = "砍价商品", requiredMode = Schema.RequiredMode.REQUIRED) |
| 42 | - @Valid | |
| 43 | 39 | private List<BargainProductRespVO> products; |
| 44 | 40 | |
| 45 | 41 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; | |
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; | |
| 4 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 5 | import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| ... | ... | @@ -22,6 +22,6 @@ public class BargainActivityUpdateReqVO extends BargainActivityBaseVO { |
| 22 | 22 | |
| 23 | 23 | @Schema(description = "砍价商品", requiredMode = Schema.RequiredMode.REQUIRED) |
| 24 | 24 | @Valid |
| 25 | - private List<BargainProductUpdateReqVO> products; | |
| 25 | + private List<BargainProductBaseVO> products; | |
| 26 | 26 | |
| 27 | 27 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java
| ... | ... | @@ -16,19 +16,19 @@ public class BargainProductBaseVO { |
| 16 | 16 | @NotNull(message = "商品 spuId 不能为空") |
| 17 | 17 | private Long spuId; |
| 18 | 18 | |
| 19 | - @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") | |
| 19 | + @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "44") | |
| 20 | 20 | @NotNull(message = "商品 skuId 不能为空") |
| 21 | 21 | private Long skuId; |
| 22 | 22 | |
| 23 | - @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") | |
| 23 | + @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "33") | |
| 24 | 24 | @NotNull(message = "砍价起始价格不能为空") |
| 25 | 25 | private Integer bargainFirstPrice; |
| 26 | 26 | |
| 27 | - @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") | |
| 27 | + @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "22") | |
| 28 | 28 | @NotNull(message = "砍价底价不能为空") |
| 29 | 29 | private Integer bargainPrice; |
| 30 | 30 | |
| 31 | - @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") | |
| 31 | + @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "11") | |
| 32 | 32 | @NotNull(message = "活动库存不能为空") |
| 33 | 33 | private Integer stock; |
| 34 | 34 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | - | |
| 8 | -// TODO @puhui999:是不是应该把 BargainProductCreateReqVO 和 BargainProductUpdateReqVO 合并在一起哈。就是一个 SaveReqVO | |
| 9 | -@Schema(description = "管理后台 - 砍价商品创建 Request VO") | |
| 10 | -@Data | |
| 11 | -@EqualsAndHashCode(callSuper = true) | |
| 12 | -@ToString(callSuper = true) | |
| 13 | -public class BargainProductCreateReqVO extends BargainProductBaseVO { | |
| 14 | - | |
| 15 | -} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | -import lombok.ToString; | |
| 7 | - | |
| 8 | -@Schema(description = "管理后台 - 砍价商品更新 Request VO") | |
| 9 | -@Data | |
| 10 | -@EqualsAndHashCode(callSuper = true) | |
| 11 | -@ToString(callSuper = true) | |
| 12 | -public class BargainProductUpdateReqVO extends BargainProductBaseVO { | |
| 13 | - | |
| 14 | -} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java
| ... | ... | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba |
| 9 | 9 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; |
| 11 | 11 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductRespVO; |
| 12 | -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; | |
| 13 | 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| 14 | 13 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; |
| 15 | 14 | import org.mapstruct.Mapper; |
| ... | ... | @@ -40,8 +39,9 @@ public interface BargainActivityConvert { |
| 40 | 39 | |
| 41 | 40 | BargainProductRespVO convert(BargainProductDO bean); |
| 42 | 41 | |
| 43 | - default BargainActivityRespVO convert(BargainActivityDO bean, List<BargainProductDO> productDOs) { | |
| 44 | - return convert(bean).setProducts(convertList2(productDOs)); | |
| 42 | + default BargainActivityRespVO convert(BargainActivityDO activity, | |
| 43 | + List<BargainProductDO> products) { | |
| 44 | + return convert(activity).setProducts(convertList2(products)); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | List<BargainActivityRespVO> convertList(List<BargainActivityDO> list); |
| ... | ... | @@ -51,39 +51,37 @@ public interface BargainActivityConvert { |
| 51 | 51 | default PageResult<BargainActivityRespVO> convertPage(PageResult<BargainActivityDO> page, |
| 52 | 52 | List<BargainProductDO> productList, |
| 53 | 53 | List<ProductSpuRespDTO> spuList) { |
| 54 | - Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); | |
| 55 | 54 | PageResult<BargainActivityRespVO> pageResult = convertPage(page); |
| 55 | + // 拼接商品 | |
| 56 | + Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); | |
| 56 | 57 | pageResult.getList().forEach(item -> { |
| 57 | - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { | |
| 58 | - item.setSpuName(spu.getName()); | |
| 59 | - item.setPicUrl(spu.getPicUrl()); | |
| 60 | - }); | |
| 61 | 58 | item.setProducts(convertList2(productList)); |
| 59 | + MapUtils.findAndThen(spuMap, item.getSpuId(), | |
| 60 | + spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())); | |
| 62 | 61 | }); |
| 63 | 62 | return pageResult; |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | List<BargainProductRespVO> convertList2(List<BargainProductDO> productDOs); |
| 67 | 66 | |
| 68 | - // TODO @puhui999:参数改成 activity、product 会不会干净一点哈 | |
| 69 | 67 | @Mappings({ |
| 70 | 68 | @Mapping(target = "id", ignore = true), |
| 71 | - @Mapping(target = "activityId", source = "activityDO.id"), | |
| 72 | - @Mapping(target = "spuId", source = "activityDO.spuId"), | |
| 73 | - @Mapping(target = "skuId", source = "vo.skuId"), | |
| 74 | - @Mapping(target = "bargainFirstPrice", source = "vo.bargainFirstPrice"), | |
| 75 | - @Mapping(target = "bargainPrice", source = "vo.bargainPrice"), | |
| 76 | - @Mapping(target = "stock", source = "vo.stock"), | |
| 77 | - @Mapping(target = "activityStartTime", source = "activityDO.startTime"), | |
| 78 | - @Mapping(target = "activityEndTime", source = "activityDO.endTime") | |
| 69 | + @Mapping(target = "activityId", source = "activity.id"), | |
| 70 | + @Mapping(target = "spuId", source = "activity.spuId"), | |
| 71 | + @Mapping(target = "skuId", source = "product.skuId"), | |
| 72 | + @Mapping(target = "bargainFirstPrice", source = "product.bargainFirstPrice"), | |
| 73 | + @Mapping(target = "bargainPrice", source = "product.bargainPrice"), | |
| 74 | + @Mapping(target = "stock", source = "product.stock"), | |
| 75 | + @Mapping(target = "activityStartTime", source = "activity.startTime"), | |
| 76 | + @Mapping(target = "activityEndTime", source = "activity.endTime") | |
| 79 | 77 | }) |
| 80 | - BargainProductDO convert(BargainActivityDO activityDO, BargainProductBaseVO vo); | |
| 78 | + BargainProductDO convert(BargainActivityDO activity, BargainProductBaseVO product); | |
| 81 | 79 | |
| 82 | 80 | default List<BargainProductDO> convertList(List<? extends BargainProductBaseVO> products, BargainActivityDO activityDO) { |
| 83 | 81 | return CollectionUtils.convertList(products, item -> convert(activityDO, item).setActivityStatus(activityDO.getStatus())); |
| 84 | 82 | } |
| 85 | 83 | |
| 86 | - default List<BargainProductDO> convertList(List<BargainProductUpdateReqVO> updateProductVOs, | |
| 84 | + default List<BargainProductDO> convertList(List<BargainProductBaseVO> updateProductVOs, | |
| 87 | 85 | List<BargainProductDO> products, BargainActivityDO activity) { |
| 88 | 86 | Map<Long, Long> productMap = convertMap(products, BargainProductDO::getSkuId, BargainProductDO::getId); |
| 89 | 87 | return CollectionUtils.convertList(updateProductVOs, updateProductVO -> convert(activity, updateProductVO) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| ... | ... | @@ -41,8 +41,9 @@ public interface CombinationActivityConvert { |
| 41 | 41 | |
| 42 | 42 | CombinationProductRespVO convert(CombinationProductDO bean); |
| 43 | 43 | |
| 44 | - default CombinationActivityRespVO convert(CombinationActivityDO bean, List<CombinationProductDO> productDOs) { | |
| 45 | - return convert(bean).setProducts(convertList2(productDOs)); | |
| 44 | + default CombinationActivityRespVO convert(CombinationActivityDO activity, | |
| 45 | + List<CombinationProductDO> products) { | |
| 46 | + return convert(activity).setProducts(convertList2(products)); | |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | 49 | List<CombinationActivityRespVO> convertList(List<CombinationActivityDO> list); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.dal.dataobject.bargain; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 3 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | 5 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | 6 | import com.baomidou.mybatisplus.annotation.TableId; |
| ... | ... | @@ -28,7 +29,6 @@ public class BargainActivityDO extends BaseDO { |
| 28 | 29 | */ |
| 29 | 30 | @TableId |
| 30 | 31 | private Long id; |
| 31 | - | |
| 32 | 32 | /** |
| 33 | 33 | * 砍价活动名称 |
| 34 | 34 | */ |
| ... | ... | @@ -38,7 +38,6 @@ public class BargainActivityDO extends BaseDO { |
| 38 | 38 | * 活动开始时间 |
| 39 | 39 | */ |
| 40 | 40 | private LocalDateTime startTime; |
| 41 | - | |
| 42 | 41 | /** |
| 43 | 42 | * 活动结束时间 |
| 44 | 43 | */ |
| ... | ... | @@ -46,6 +45,8 @@ public class BargainActivityDO extends BaseDO { |
| 46 | 45 | |
| 47 | 46 | /** |
| 48 | 47 | * 活动状态 |
| 48 | + * | |
| 49 | + * 枚举 {@link CommonStatusEnum} | |
| 49 | 50 | */ |
| 50 | 51 | private Integer status; |
| 51 | 52 | |
| ... | ... | @@ -53,40 +54,36 @@ public class BargainActivityDO extends BaseDO { |
| 53 | 54 | * 商品 SPU 编号 |
| 54 | 55 | */ |
| 55 | 56 | private Long spuId; |
| 57 | + /** | |
| 58 | + * 砍价库存 | |
| 59 | + */ | |
| 60 | + private Integer stock; | |
| 56 | 61 | |
| 57 | 62 | /** |
| 58 | 63 | * 达到该人数,才能砍到低价 |
| 59 | 64 | */ |
| 60 | 65 | private Integer userSize; |
| 61 | - | |
| 62 | 66 | /** |
| 63 | 67 | * 最大帮砍次数 |
| 64 | 68 | */ |
| 65 | 69 | private Integer bargainCount; |
| 66 | - | |
| 67 | 70 | /** |
| 68 | 71 | * 总限购数量 |
| 69 | 72 | */ |
| 70 | 73 | private Integer totalLimitCount; |
| 71 | - | |
| 72 | - /** | |
| 73 | - * 砍价库存 | |
| 74 | - */ | |
| 75 | - private Integer stock; | |
| 76 | - | |
| 77 | 74 | /** |
| 78 | 75 | * 用户每次砍价的最小金额,单位:分 |
| 79 | 76 | */ |
| 80 | 77 | private Integer randomMinPrice; |
| 81 | - | |
| 82 | 78 | /** |
| 83 | 79 | * 用户每次砍价的最大金额,单位:分 |
| 84 | 80 | */ |
| 85 | 81 | private Integer randomMaxPrice; |
| 86 | - | |
| 87 | 82 | /** |
| 88 | 83 | * 砍价成功数量 |
| 89 | 84 | */ |
| 90 | 85 | private Integer successCount; |
| 91 | 86 | |
| 87 | + // TODO @puhui999:把 BargainProductDO 字段融合过来; | |
| 88 | + | |
| 92 | 89 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java
| ... | ... | @@ -13,6 +13,7 @@ import java.time.LocalDateTime; |
| 13 | 13 | * |
| 14 | 14 | * @author HUIHUI |
| 15 | 15 | */ |
| 16 | +@Deprecated // 应该融合到 BargainActivityDO 表 | |
| 16 | 17 | @TableName("promotion_bargain_product") |
| 17 | 18 | @KeySequence("promotion_bargain_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 |
| 18 | 19 | @Data | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java
| ... | ... | @@ -59,9 +59,9 @@ public interface BargainActivityService { |
| 59 | 59 | /** |
| 60 | 60 | * 获得砍价活动商品列表 |
| 61 | 61 | * |
| 62 | - * @param ids 砍价活动 ids | |
| 62 | + * @param activityIds 砍价活动 ids | |
| 63 | 63 | * @return 砍价活动的商品列表 |
| 64 | 64 | */ |
| 65 | - List<BargainProductDO> getBargainProductsByActivityIds(Collection<Long> ids); | |
| 65 | + List<BargainProductDO> getBargainProductsByActivityIds(Collection<Long> activityIds); | |
| 66 | 66 | |
| 67 | 67 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java renamed to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java
| ... | ... | @@ -13,14 +13,12 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 13 | 13 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityCreateReqVO; |
| 14 | 14 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; |
| 15 | 15 | import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; |
| 16 | -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductCreateReqVO; | |
| 17 | -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; | |
| 16 | +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; | |
| 18 | 17 | import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; |
| 19 | 18 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; |
| 20 | 19 | import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; |
| 21 | 20 | import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainActivityMapper; |
| 22 | 21 | import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainProductMapper; |
| 23 | -import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainRecordMapper; | |
| 24 | 22 | import org.springframework.stereotype.Service; |
| 25 | 23 | import org.springframework.transaction.annotation.Transactional; |
| 26 | 24 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -43,14 +41,13 @@ import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProd |
| 43 | 41 | */ |
| 44 | 42 | @Service |
| 45 | 43 | @Validated |
| 46 | -public class BargainServiceImpl implements BargainActivityService, BargainRecordService { | |
| 44 | +public class BargainActivityServiceImpl implements BargainActivityService { | |
| 47 | 45 | |
| 48 | 46 | @Resource |
| 49 | 47 | private BargainActivityMapper bargainActivityMapper; |
| 50 | 48 | @Resource |
| 51 | - private BargainRecordMapper recordMapper; | |
| 52 | - @Resource | |
| 53 | 49 | private BargainProductMapper bargainProductMapper; |
| 50 | + | |
| 54 | 51 | @Resource |
| 55 | 52 | private ProductSpuApi productSpuApi; |
| 56 | 53 | @Resource |
| ... | ... | @@ -64,21 +61,21 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord |
| 64 | 61 | // 获取所选 spu下的所有 sku |
| 65 | 62 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); |
| 66 | 63 | // 校验商品 sku 是否存在 |
| 67 | - validateProductSkuAllExists(skus, createReqVO.getProducts(), BargainProductCreateReqVO::getSkuId); | |
| 64 | + validateProductSkuAllExists(skus, createReqVO.getProducts(), BargainProductBaseVO::getSkuId); | |
| 68 | 65 | |
| 69 | 66 | // 插入砍价活动 |
| 70 | - BargainActivityDO activityDO = BargainActivityConvert.INSTANCE.convert(createReqVO); | |
| 67 | + BargainActivityDO activity = BargainActivityConvert.INSTANCE.convert(createReqVO); | |
| 71 | 68 | // TODO 营销相关属性初始化 砍价成功更新相关属性 |
| 72 | - activityDO.setSuccessCount(0); | |
| 69 | + activity.setSuccessCount(0); | |
| 73 | 70 | // 活动总库存 |
| 74 | - activityDO.setStock(getSumValue(createReqVO.getProducts(), BargainProductCreateReqVO::getStock, Integer::sum)); | |
| 75 | - activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 76 | - bargainActivityMapper.insert(activityDO); | |
| 71 | + activity.setStock(getSumValue(createReqVO.getProducts(), BargainProductBaseVO::getStock, Integer::sum)); | |
| 72 | + activity.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 73 | + bargainActivityMapper.insert(activity); | |
| 77 | 74 | // 插入商品 |
| 78 | - List<BargainProductDO> productDOs = BargainActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activityDO); | |
| 75 | + List<BargainProductDO> productDOs = BargainActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activity); | |
| 79 | 76 | bargainProductMapper.insertBatch(productDOs); |
| 80 | 77 | // 返回 |
| 81 | - return activityDO.getId(); | |
| 78 | + return activity.getId(); | |
| 82 | 79 | } |
| 83 | 80 | |
| 84 | 81 | private void validateProductBargainConflict(Long spuId, Long activityId) { |
| ... | ... | @@ -113,12 +110,12 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord |
| 113 | 110 | // 获取所选 spu下的所有 sku |
| 114 | 111 | List<ProductSkuRespDTO> skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); |
| 115 | 112 | // 校验商品 sku 是否存在 |
| 116 | - validateProductSkuAllExists(skus, updateReqVO.getProducts(), BargainProductUpdateReqVO::getSkuId); | |
| 113 | + validateProductSkuAllExists(skus, updateReqVO.getProducts(), BargainProductBaseVO::getSkuId); | |
| 117 | 114 | |
| 118 | 115 | // 更新 |
| 119 | 116 | BargainActivityDO updateObj = BargainActivityConvert.INSTANCE.convert(updateReqVO); |
| 120 | 117 | // 更新活动库存 |
| 121 | - updateObj.setStock(getSumValue(updateReqVO.getProducts(), BargainProductUpdateReqVO::getStock, Integer::sum)); | |
| 118 | + updateObj.setStock(getSumValue(updateReqVO.getProducts(), BargainProductBaseVO::getStock, Integer::sum)); | |
| 122 | 119 | bargainActivityMapper.updateById(updateObj); |
| 123 | 120 | // 更新商品 |
| 124 | 121 | updateBargainProduct(updateObj, updateReqVO.getProducts()); |
| ... | ... | @@ -130,7 +127,7 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord |
| 130 | 127 | * @param updateObj 更新的活动 |
| 131 | 128 | * @param products 商品配置 |
| 132 | 129 | */ |
| 133 | - private void updateBargainProduct(BargainActivityDO updateObj, List<BargainProductUpdateReqVO> products) { | |
| 130 | + private void updateBargainProduct(BargainActivityDO updateObj, List<BargainProductBaseVO> products) { | |
| 134 | 131 | // 默认全部新增 |
| 135 | 132 | List<BargainProductDO> defaultNewList = BargainActivityConvert.INSTANCE.convertList(products, updateObj); |
| 136 | 133 | // 数据库中的老数据 |
| ... | ... | @@ -181,7 +178,7 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord |
| 181 | 178 | |
| 182 | 179 | @Override |
| 183 | 180 | public BargainActivityDO getBargainActivity(Long id) { |
| 184 | - return validateBargainActivityExists(id); | |
| 181 | + return bargainActivityMapper.selectById(id); | |
| 185 | 182 | } |
| 186 | 183 | |
| 187 | 184 | @Override |
| ... | ... | @@ -190,8 +187,8 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord |
| 190 | 187 | } |
| 191 | 188 | |
| 192 | 189 | @Override |
| 193 | - public List<BargainProductDO> getBargainProductsByActivityIds(Collection<Long> ids) { | |
| 194 | - return bargainProductMapper.selectListByActivityIds(ids); | |
| 190 | + public List<BargainProductDO> getBargainProductsByActivityIds(Collection<Long> activityIds) { | |
| 191 | + return bargainProductMapper.selectListByActivityIds(activityIds); | |
| 195 | 192 | } |
| 196 | 193 | |
| 197 | 194 | } | ... | ... |