From e159b2e5005af3196aa846556fb46a03b9e2417d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 13 Aug 2023 00:49:35 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=EF=BC=9A=E7=A0=8D=E4=BB=B7?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bargain/BargainActivityController.java | 21 +++++++---- .../vo/activity/BargainActivityBaseVO.java | 2 +- .../activity/BargainActivityCreateReqVO.java | 4 +- .../vo/activity/BargainActivityPageReqVO.java | 31 ---------------- .../vo/activity/BargainActivityRespVO.java | 6 +-- .../activity/BargainActivityUpdateReqVO.java | 4 +- .../vo/product/BargainProductBaseVO.java | 8 ++-- .../vo/product/BargainProductCreateReqVO.java | 15 -------- .../vo/product/BargainProductUpdateReqVO.java | 14 ------- .../bargain/BargainActivityConvert.java | 36 +++++++++--------- .../CombinationActivityConvert.java | 5 ++- .../dataobject/bargain/BargainActivityDO.java | 37 +++++++++---------- .../dataobject/bargain/BargainProductDO.java | 1 + .../bargain/BargainActivityService.java | 4 +- ...l.java => BargainActivityServiceImpl.java} | 37 +++++++++---------- 15 files changed, 81 insertions(+), 144 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductCreateReqVO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/{BargainServiceImpl.java => BargainActivityServiceImpl.java} (87%) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java index 1e8e14f12..b51a9783c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/BargainActivityController.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.promotion.controller.admin.bargain; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityRespVO; @@ -20,8 +22,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Collections; import java.util.List; -import java.util.Set; import static cn.hutool.core.collection.CollectionUtil.newArrayList; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -37,7 +39,7 @@ public class BargainActivityController { private BargainActivityService activityService; @Resource - private ProductSpuApi spuApi; + private ProductSpuApi productSpuApi; @PostMapping("/create") @Operation(summary = "创建砍价活动") @@ -80,12 +82,17 @@ public class BargainActivityController { @Valid BargainActivityPageReqVO pageVO) { // 查询砍价活动 PageResult pageResult = activityService.getBargainActivityPage(pageVO); + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); + } + // 拼接数据 - Set activityIds = convertSet(pageResult.getList(), BargainActivityDO::getId); - Set spuIds = convertSet(pageResult.getList(), BargainActivityDO::getSpuId); - return success(BargainActivityConvert.INSTANCE.convertPage(pageResult, - activityService.getBargainProductsByActivityIds(activityIds), - spuApi.getSpuList(spuIds))); +// List products = activityService.getBargainProductsByActivityIds( +// convertSet(pageResult.getList(), BargainActivityDO::getId)); + List products = Collections.emptyList(); + List spus = productSpuApi.getSpuList( + convertSet(pageResult.getList(), BargainActivityDO::getSpuId)); + return success(BargainActivityConvert.INSTANCE.convertPage(pageResult, products, spus)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java index 560c88bcf..e8a118abe 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java +++ b/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 { @NotNull(message = "砍价名称不能为空") private String name; - @Schema(description = "商品 SPU 编号,关联 ProductSpuDO 的 id", example = "[1,2,3]") + @Schema(description = "商品 SPU 编号", example = "1") @NotNull(message = "砍价商品不能为空") private Long spuId; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java index 38e6fb403..2e1208fc6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -17,6 +17,6 @@ public class BargainActivityCreateReqVO extends BargainActivityBaseVO { @Schema(description = "砍价商品", requiredMode = Schema.RequiredMode.REQUIRED) @Valid - private List products; + private List products; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java index 1845a929e..61daa6c7b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java +++ b/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 { @Schema(description = "砍价名称", example = "赵六") private String name; - @Schema(description = "商品 SPU 编号关联 ProductSpuDO 的 id", example = "14016") - private Long spuId; - - @Schema(description = "总限购数量", example = "16218") - private Integer totalLimitCount; - - @Schema(description = "单次限购数量", example = "28265") - private Integer singleLimitCount; - @Schema(description = "开始时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] startTime; @@ -37,29 +28,7 @@ public class BargainActivityPageReqVO extends PageParam { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] endTime; - @Schema(description = "开团人数") - private Integer userSize; - - @Schema(description = "开团组数") - private Integer totalNum; - - @Schema(description = "成团组数") - private Integer successNum; - - @Schema(description = "参与人数", example = "25222") - private Integer orderUserCount; - - @Schema(description = "虚拟成团") - private Integer virtualGroup; - @Schema(description = "活动状态:0开启 1关闭", example = "0") private Integer status; - @Schema(description = "限制时长(小时)") - private Integer limitDuration; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityRespVO.java index 064e4e8ac..69c99ba16 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityRespVO.java +++ b/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; import lombok.EqualsAndHashCode; import lombok.ToString; -import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; import java.util.List; @@ -17,8 +16,6 @@ import java.util.List; @ToString(callSuper = true) public class BargainActivityRespVO extends BargainActivityBaseVO { - // TODO @puhui999:example 补全 - @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") private String spuName; @@ -31,7 +28,7 @@ public class BargainActivityRespVO extends BargainActivityBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; - @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "888") private Integer successCount; @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") @@ -39,7 +36,6 @@ public class BargainActivityRespVO extends BargainActivityBaseVO { private Integer status; @Schema(description = "砍价商品", requiredMode = Schema.RequiredMode.REQUIRED) - @Valid private List products; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java index 242288c30..1f11cfb1e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -22,6 +22,6 @@ public class BargainActivityUpdateReqVO extends BargainActivityBaseVO { @Schema(description = "砍价商品", requiredMode = Schema.RequiredMode.REQUIRED) @Valid - private List products; + private List products; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java index 2c5ca7ef8..02004d4f8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java +++ b/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 { @NotNull(message = "商品 spuId 不能为空") private Long spuId; - @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "44") @NotNull(message = "商品 skuId 不能为空") private Long skuId; - @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "33") @NotNull(message = "砍价起始价格不能为空") private Integer bargainFirstPrice; - @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "22") @NotNull(message = "砍价底价不能为空") private Integer bargainPrice; - @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "11") @NotNull(message = "活动库存不能为空") private Integer stock; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductCreateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductCreateReqVO.java deleted file mode 100644 index 9b14b1765..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductCreateReqVO.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -// TODO @puhui999:是不是应该把 BargainProductCreateReqVO 和 BargainProductUpdateReqVO 合并在一起哈。就是一个 SaveReqVO -@Schema(description = "管理后台 - 砍价商品创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BargainProductCreateReqVO extends BargainProductBaseVO { - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java deleted file mode 100644 index 986a4c8f8..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - 砍价商品更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BargainProductUpdateReqVO extends BargainProductBaseVO { - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java index ebd1f303a..f7d7ee740 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java +++ b/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 import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import org.mapstruct.Mapper; @@ -40,8 +39,9 @@ public interface BargainActivityConvert { BargainProductRespVO convert(BargainProductDO bean); - default BargainActivityRespVO convert(BargainActivityDO bean, List productDOs) { - return convert(bean).setProducts(convertList2(productDOs)); + default BargainActivityRespVO convert(BargainActivityDO activity, + List products) { + return convert(activity).setProducts(convertList2(products)); } List convertList(List list); @@ -51,39 +51,37 @@ public interface BargainActivityConvert { default PageResult convertPage(PageResult page, List productList, List spuList) { - Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); PageResult pageResult = convertPage(page); + // 拼接商品 + Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); pageResult.getList().forEach(item -> { - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { - item.setSpuName(spu.getName()); - item.setPicUrl(spu.getPicUrl()); - }); item.setProducts(convertList2(productList)); + MapUtils.findAndThen(spuMap, item.getSpuId(), + spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())); }); return pageResult; } List convertList2(List productDOs); - // TODO @puhui999:参数改成 activity、product 会不会干净一点哈 @Mappings({ @Mapping(target = "id", ignore = true), - @Mapping(target = "activityId", source = "activityDO.id"), - @Mapping(target = "spuId", source = "activityDO.spuId"), - @Mapping(target = "skuId", source = "vo.skuId"), - @Mapping(target = "bargainFirstPrice", source = "vo.bargainFirstPrice"), - @Mapping(target = "bargainPrice", source = "vo.bargainPrice"), - @Mapping(target = "stock", source = "vo.stock"), - @Mapping(target = "activityStartTime", source = "activityDO.startTime"), - @Mapping(target = "activityEndTime", source = "activityDO.endTime") + @Mapping(target = "activityId", source = "activity.id"), + @Mapping(target = "spuId", source = "activity.spuId"), + @Mapping(target = "skuId", source = "product.skuId"), + @Mapping(target = "bargainFirstPrice", source = "product.bargainFirstPrice"), + @Mapping(target = "bargainPrice", source = "product.bargainPrice"), + @Mapping(target = "stock", source = "product.stock"), + @Mapping(target = "activityStartTime", source = "activity.startTime"), + @Mapping(target = "activityEndTime", source = "activity.endTime") }) - BargainProductDO convert(BargainActivityDO activityDO, BargainProductBaseVO vo); + BargainProductDO convert(BargainActivityDO activity, BargainProductBaseVO product); default List convertList(List products, BargainActivityDO activityDO) { return CollectionUtils.convertList(products, item -> convert(activityDO, item).setActivityStatus(activityDO.getStatus())); } - default List convertList(List updateProductVOs, + default List convertList(List updateProductVOs, List products, BargainActivityDO activity) { Map productMap = convertMap(products, BargainProductDO::getSkuId, BargainProductDO::getId); return CollectionUtils.convertList(updateProductVOs, updateProductVO -> convert(activity, updateProductVO) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index f4404af8a..52fb4b967 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/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 { CombinationProductRespVO convert(CombinationProductDO bean); - default CombinationActivityRespVO convert(CombinationActivityDO bean, List productDOs) { - return convert(bean).setProducts(convertList2(productDOs)); + default CombinationActivityRespVO convert(CombinationActivityDO activity, + List products) { + return convert(activity).setProducts(convertList2(products)); } List convertList(List list); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java index 034973269..59dc31c20 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainActivityDO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.bargain; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -28,7 +29,6 @@ public class BargainActivityDO extends BaseDO { */ @TableId private Long id; - /** * 砍价活动名称 */ @@ -38,7 +38,6 @@ public class BargainActivityDO extends BaseDO { * 活动开始时间 */ private LocalDateTime startTime; - /** * 活动结束时间 */ @@ -46,6 +45,8 @@ public class BargainActivityDO extends BaseDO { /** * 活动状态 + * + * 枚举 {@link CommonStatusEnum} */ private Integer status; @@ -53,40 +54,36 @@ public class BargainActivityDO extends BaseDO { * 商品 SPU 编号 */ private Long spuId; - - /** - * 达到该人数,才能砍到低价 - */ - private Integer userSize; - - /** - * 最大帮砍次数 - */ - private Integer bargainCount; - - /** - * 总限购数量 - */ - private Integer totalLimitCount; - /** * 砍价库存 */ private Integer stock; + /** + * 达到该人数,才能砍到低价 + */ + private Integer userSize; + /** + * 最大帮砍次数 + */ + private Integer bargainCount; + /** + * 总限购数量 + */ + private Integer totalLimitCount; /** * 用户每次砍价的最小金额,单位:分 */ private Integer randomMinPrice; - /** * 用户每次砍价的最大金额,单位:分 */ private Integer randomMaxPrice; - /** * 砍价成功数量 */ private Integer successCount; + // TODO @puhui999:把 BargainProductDO 字段融合过来; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java index 8f47ce1da..abef4efe7 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java +++ b/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; * * @author HUIHUI */ +@Deprecated // 应该融合到 BargainActivityDO 表 @TableName("promotion_bargain_product") @KeySequence("promotion_bargain_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java index a7b1b0dbd..3e1253f12 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityService.java +++ b/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 { /** * 获得砍价活动商品列表 * - * @param ids 砍价活动 ids + * @param activityIds 砍价活动 ids * @return 砍价活动的商品列表 */ - List getBargainProductsByActivityIds(Collection ids); + List getBargainProductsByActivityIds(Collection activityIds); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java similarity index 87% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 1a314ebab..d1128a10a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainServiceImpl.java +++ b/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; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductBaseVO; import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainActivityMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainProductMapper; -import cn.iocoder.yudao.module.promotion.dal.mysql.bargain.BargainRecordMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -43,14 +41,13 @@ import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProd */ @Service @Validated -public class BargainServiceImpl implements BargainActivityService, BargainRecordService { +public class BargainActivityServiceImpl implements BargainActivityService { @Resource private BargainActivityMapper bargainActivityMapper; @Resource - private BargainRecordMapper recordMapper; - @Resource private BargainProductMapper bargainProductMapper; + @Resource private ProductSpuApi productSpuApi; @Resource @@ -64,21 +61,21 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord // 获取所选 spu下的所有 sku List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, createReqVO.getProducts(), BargainProductCreateReqVO::getSkuId); + validateProductSkuAllExists(skus, createReqVO.getProducts(), BargainProductBaseVO::getSkuId); // 插入砍价活动 - BargainActivityDO activityDO = BargainActivityConvert.INSTANCE.convert(createReqVO); + BargainActivityDO activity = BargainActivityConvert.INSTANCE.convert(createReqVO); // TODO 营销相关属性初始化 砍价成功更新相关属性 - activityDO.setSuccessCount(0); + activity.setSuccessCount(0); // 活动总库存 - activityDO.setStock(getSumValue(createReqVO.getProducts(), BargainProductCreateReqVO::getStock, Integer::sum)); - activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - bargainActivityMapper.insert(activityDO); + activity.setStock(getSumValue(createReqVO.getProducts(), BargainProductBaseVO::getStock, Integer::sum)); + activity.setStatus(CommonStatusEnum.ENABLE.getStatus()); + bargainActivityMapper.insert(activity); // 插入商品 - List productDOs = BargainActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activityDO); + List productDOs = BargainActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activity); bargainProductMapper.insertBatch(productDOs); // 返回 - return activityDO.getId(); + return activity.getId(); } private void validateProductBargainConflict(Long spuId, Long activityId) { @@ -113,12 +110,12 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord // 获取所选 spu下的所有 sku List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, updateReqVO.getProducts(), BargainProductUpdateReqVO::getSkuId); + validateProductSkuAllExists(skus, updateReqVO.getProducts(), BargainProductBaseVO::getSkuId); // 更新 BargainActivityDO updateObj = BargainActivityConvert.INSTANCE.convert(updateReqVO); // 更新活动库存 - updateObj.setStock(getSumValue(updateReqVO.getProducts(), BargainProductUpdateReqVO::getStock, Integer::sum)); + updateObj.setStock(getSumValue(updateReqVO.getProducts(), BargainProductBaseVO::getStock, Integer::sum)); bargainActivityMapper.updateById(updateObj); // 更新商品 updateBargainProduct(updateObj, updateReqVO.getProducts()); @@ -130,7 +127,7 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord * @param updateObj 更新的活动 * @param products 商品配置 */ - private void updateBargainProduct(BargainActivityDO updateObj, List products) { + private void updateBargainProduct(BargainActivityDO updateObj, List products) { // 默认全部新增 List defaultNewList = BargainActivityConvert.INSTANCE.convertList(products, updateObj); // 数据库中的老数据 @@ -181,7 +178,7 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord @Override public BargainActivityDO getBargainActivity(Long id) { - return validateBargainActivityExists(id); + return bargainActivityMapper.selectById(id); } @Override @@ -190,8 +187,8 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord } @Override - public List getBargainProductsByActivityIds(Collection ids) { - return bargainProductMapper.selectListByActivityIds(ids); + public List getBargainProductsByActivityIds(Collection activityIds) { + return bargainProductMapper.selectListByActivityIds(activityIds); } }