From 651725e3e80e8fc352b8c9e51edec4c99e020adf Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 14 Aug 2023 21:20:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=91=E8=B4=A7=E9=80=BB=E8=BE=91=E3=80=81=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=A0=8D=E4=BB=B7=E6=B4=BB=E5=8A=A8=E3=80=81=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95=E5=88=9B=E5=BB=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bargain/BargainRecordApi.java | 11 ++- .../api/combination/CombinationRecordApi.java | 26 +++++- .../dto/CombinationRecordRespDTO.java | 46 +++++++++++ .../promotion/enums/ErrorCodeConstants.java | 11 +-- .../combination/CombinationRecordApiImpl.java | 17 +++- .../bargain/BargainActivityController.java | 27 ++----- .../{activity => }/BargainActivityBaseVO.java | 18 ++++- ...O.java => BargainActivityCreateReqVO.java} | 6 +- .../bargain/vo/BargainActivityPageReqVO.java | 21 +++++ .../{activity => }/BargainActivityRespVO.java | 16 +--- .../BargainActivityUpdateReqVO.java | 9 +-- .../activity/BargainActivityCreateReqVO.java | 22 ----- .../vo/activity/BargainActivityPageReqVO.java | 65 --------------- .../vo/product/BargainProductBaseVO.java | 35 -------- .../vo/product/BargainProductCreateReqVO.java | 15 ---- .../vo/product/BargainProductRespVO.java | 22 ----- .../CombinationActivityPageReqVO.java | 43 ---------- .../bargain/BargainActivityConvert.java | 67 +--------------- .../CombinationActivityConvert.java | 3 + .../dataobject/bargain/BargainActivityDO.java | 15 +++- .../dataobject/bargain/BargainProductDO.java | 70 ---------------- .../mysql/bargain/BargainActivityMapper.java | 3 +- .../mysql/bargain/BargainProductMapper.java | 22 ----- .../CombinationActivityMapper.java | 1 + .../combination/CombinationRecordMapper.java | 26 ++++-- .../bargain/BargainActivityService.java | 16 +--- .../service/bargain/BargainServiceImpl.java | 80 ++++--------------- .../combination/CombinationRecordService.java | 21 +++++ .../combination/CombinationServiceImpl.java | 40 ++++++++-- .../SeckillConfigServiceImpl.java | 1 - .../CombinationActivityServiceImplTest.java | 13 --- .../trade/enums/ErrorCodeConstants.java | 5 +- .../order/vo/TradeOrderDeliveryReqVO.java | 2 - .../app/order/AppTradeOrderController.java | 3 +- .../dal/mysql/order/TradeOrderItemMapper.java | 6 ++ .../service/order/TradeOrderService.java | 5 +- .../service/order/TradeOrderServiceImpl.java | 71 ++++++++-------- 37 files changed, 316 insertions(+), 564 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordRespDTO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/{activity => }/BargainActivityBaseVO.java (77%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/{product/BargainProductUpdateReqVO.java => BargainActivityCreateReqVO.java} (64%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityPageReqVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/{activity => }/BargainActivityRespVO.java (75%) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/{activity => }/BargainActivityUpdateReqVO.java (66%) delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java 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/BargainProductRespVO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainProductMapper.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java index 5639ab1d7..58add749a 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApi.java @@ -14,10 +14,19 @@ import javax.validation.Valid; public interface BargainRecordApi { /** - * 创建开团记录 + * 创建砍价记录 * * @param reqDTO 请求 DTO */ void createRecord(@Valid BargainRecordCreateReqDTO reqDTO); + /** + * 查询砍价是否成功 + * + * @param userId 用户编号 + * @param orderId 订单编号 + * @return 砍价是否成功 + */ + boolean validateRecordSuccess(Long userId, Long orderId); + } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index 2a83ed984..c9e683e8a 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java @@ -1,11 +1,14 @@ package cn.iocoder.yudao.module.promotion.api.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import javax.validation.Valid; +import java.util.List; // TODO @芋艿:后面也再撸撸这几个接口 + /** * 拼团记录 API 接口 * @@ -18,7 +21,7 @@ public interface CombinationRecordApi { * * @param reqDTO 请求 DTO */ - void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); + void createRecord(@Valid CombinationRecordCreateReqDTO reqDTO); /** * 查询拼团记录是否成功 @@ -27,7 +30,26 @@ public interface CombinationRecordApi { * @param orderId 订单编号 * @return 拼团是否成功 */ - boolean isCombinationRecordSuccess(Long userId, Long orderId); + boolean validateRecordSuccess(Long userId, Long orderId); + + /** + * 获取拼团记录 + * + * @param userId 用户编号 + * @param activityId 活动编号 + * @return 拼团记录列表 + */ + List getRecordListByUserIdAndActivityId(Long userId, Long activityId); + + /** + * 验证组合限制数 + * 校验是否满足限购要求 + * + * @param count 本次购买数量 + * @param sumCount 已购买数量合计 + * @param activityId 活动编号 + */ + void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount); // TODO @puhui999:是不是搞成具体的方法,拼团成功,拼团失败,这种方法; diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordRespDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordRespDTO.java new file mode 100644 index 000000000..486200d3f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordRespDTO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.promotion.api.combination.dto; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 拼团记录 Response DTO + * + * @author HUIHUI + */ +@Data +public class CombinationRecordRespDTO { + + /** + * 拼团活动编号 + */ + @NotNull(message = "拼团活动编号不能为空") + private Long activityId; + /** + * spu 编号 + */ + @NotNull(message = "spu 编号不能为空") + private Long spuId; + /** + * sku 编号 + */ + @NotNull(message = "sku 编号不能为空") + private Long skuId; + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Long userId; + /** + * 订单编号 + */ + @NotNull(message = "订单编号不能为空") + private Long orderId; + /** + * 开团状态:正在开团 拼团成功 拼团失败 + */ + @NotNull(message = "开团状态不能为空") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index e2f2bb98c..8770045e9 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -67,17 +67,18 @@ public interface ErrorCodeConstants { ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013010004, "拼团不存在"); ErrorCode COMBINATION_RECORD_EXISTS = new ErrorCode(1013010005, "拼团失败,已参与过该拼团"); ErrorCode COMBINATION_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1013010006, "拼团失败,父拼团不存在"); - ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1013010006, "拼团失败,拼团人数已满"); + ErrorCode COMBINATION_RECORD_USER_FULL = new ErrorCode(1013010007, "拼团失败,拼团人数已满"); + ErrorCode COMBINATION_RECORD_FAILED_HAVE_JOINED = new ErrorCode(1013010008, "拼团失败,已参与其它拼团"); + ErrorCode COMBINATION_RECORD_FAILED_TIME_END = new ErrorCode(1013010009, "拼团失败,活动已经结束"); + ErrorCode COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED = new ErrorCode(1013010010, "拼团失败,单次限购超出"); + ErrorCode COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED = new ErrorCode(1013010011, "拼团失败,单次限购超出"); // ========== 砍价活动 1013011000 ========== ErrorCode BARGAIN_ACTIVITY_NOT_EXISTS = new ErrorCode(1013011000, "砍价活动不存在"); ErrorCode BARGAIN_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1013011001, "存在商品参加了其它砍价活动"); ErrorCode BARGAIN_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013011002, "砍价活动已关闭不能修改"); ErrorCode BARGAIN_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013011003, "砍价活动未关闭或未结束,不能删除"); - - // TODO @puhui999:拆分成砍价记录 - - ErrorCode BARGAIN_RECORD_NOT_EXISTS = new ErrorCode(1013011004, "砍价不存在"); + ErrorCode BARGAIN_RECORD_NOT_EXISTS = new ErrorCode(1013011004, "砍价记录不存在"); ErrorCode BARGAIN_RECORD_EXISTS = new ErrorCode(1013011005, "砍价失败,已参与过该砍价"); ErrorCode BARGAIN_RECORD_HEAD_NOT_EXISTS = new ErrorCode(1013011006, "砍价失败,父砍价不存在"); ErrorCode BARGAIN_RECORD_USER_FULL = new ErrorCode(1013011007, "砍价失败,砍价人数已满"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java index b21f7bee9..855c51074 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java @@ -1,12 +1,15 @@ package cn.iocoder.yudao.module.promotion.api.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; +import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.List; /** * 拼团活动 API 实现类 @@ -20,15 +23,25 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { private CombinationRecordService recordService; @Override - public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + public void createRecord(CombinationRecordCreateReqDTO reqDTO) { recordService.createCombinationRecord(reqDTO); } @Override - public boolean isCombinationRecordSuccess(Long userId, Long orderId) { + public boolean validateRecordSuccess(Long userId, Long orderId) { return CombinationRecordStatusEnum.isSuccess(recordService.getCombinationRecord(userId, orderId).getStatus()); } + @Override + public List getRecordListByUserIdAndActivityId(Long userId, Long activityId) { + return CombinationActivityConvert.INSTANCE.convert(recordService.getRecordListByUserIdAndActivityId(userId, activityId)); + } + + @Override + public void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount) { + recordService.validateCombinationLimitCount(activityId, count, sumCount); + } + @Override public void updateCombinationRecordStatus(CombinationRecordUpdateStatusReqDTO reqDTO) { if (null == reqDTO.getStartTime()) { 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..673d4dd09 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 @@ -3,13 +3,11 @@ package cn.iocoder.yudao.module.promotion.controller.admin.bargain; 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.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; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; 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.service.bargain.BargainActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -20,12 +18,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -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; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - 砍价活动") @RestController @@ -68,9 +62,7 @@ public class BargainActivityController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('promotion:bargain-activity:query')") public CommonResult getBargainActivity(@RequestParam("id") Long id) { - BargainActivityDO activity = activityService.getBargainActivity(id); - List products = activityService.getBargainProductsByActivityIds(newArrayList(id)); - return success(BargainActivityConvert.INSTANCE.convert(activity, products)); + return success(BargainActivityConvert.INSTANCE.convert(activityService.getBargainActivity(id))); } @GetMapping("/page") @@ -78,14 +70,7 @@ public class BargainActivityController { @PreAuthorize("@ss.hasPermission('promotion:bargain-activity:query')") public CommonResult> getBargainActivityPage( @Valid BargainActivityPageReqVO pageVO) { - // 查询砍价活动 - PageResult pageResult = activityService.getBargainActivityPage(pageVO); - // 拼接数据 - 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))); + return success(BargainActivityConvert.INSTANCE.convertPage(activityService.getBargainActivityPage(pageVO))); } } 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/BargainActivityBaseVO.java similarity index 77% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityBaseVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityBaseVO.java index 560c88bcf..ec969c2c3 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/BargainActivityBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -26,6 +26,22 @@ public class BargainActivityBaseVO { @NotNull(message = "砍价商品不能为空") private Long spuId; + @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "商品 skuId 不能为空") + private Long skuId; + + @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "砍价起始价格不能为空") + private Integer bargainFirstPrice; + + @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "砍价底价不能为空") + private Integer bargainPrice; + + @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") + @NotNull(message = "活动库存不能为空") + private Integer stock; + @Schema(description = "总限购数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "16218") @NotNull(message = "总限购数量不能为空") private Integer totalLimitCount; 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/BargainActivityCreateReqVO.java similarity index 64% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductUpdateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityCreateReqVO.java index 986a4c8f8..f49b489ea 100644 --- 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/BargainActivityCreateReqVO.java @@ -1,14 +1,14 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -@Schema(description = "管理后台 - 砍价商品更新 Request VO") +@Schema(description = "管理后台 - 砍价活动创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class BargainProductUpdateReqVO extends BargainProductBaseVO { +public class BargainActivityCreateReqVO extends BargainActivityBaseVO { } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityPageReqVO.java new file mode 100644 index 000000000..9412c6292 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityPageReqVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +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 BargainActivityPageReqVO extends PageParam { + + @Schema(description = "砍价名称", example = "赵六") + private String name; + + @Schema(description = "活动状态:0开启 1关闭", example = "0") + private Integer status; + +} 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/BargainActivityRespVO.java similarity index 75% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityRespVO.java index 064e4e8ac..2e5b6a008 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/BargainActivityRespVO.java @@ -1,24 +1,18 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductRespVO; import io.swagger.v3.oas.annotations.media.Schema; 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; - @Schema(description = "管理后台 - 砍价活动 Response VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class BargainActivityRespVO extends BargainActivityBaseVO { - // TODO @puhui999:example 补全 - @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618大促") private String spuName; @@ -28,18 +22,14 @@ public class BargainActivityRespVO extends BargainActivityBaseVO { @Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901") private Long id; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2022-07-01 23:59:59") private LocalDateTime createTime; - @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "砍价成功数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "999") private Integer successCount; @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") @NotNull(message = "活动状态不能为空") 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/BargainActivityUpdateReqVO.java similarity index 66% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityUpdateReqVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/BargainActivityUpdateReqVO.java index 242288c30..849616af5 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/BargainActivityUpdateReqVO.java @@ -1,14 +1,11 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; +package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductUpdateReqVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import javax.validation.Valid; import javax.validation.constraints.NotNull; -import java.util.List; @Schema(description = "管理后台 - 砍价活动更新 Request VO") @Data @@ -20,8 +17,4 @@ public class BargainActivityUpdateReqVO extends BargainActivityBaseVO { @NotNull(message = "活动编号不能为空") private Long id; - @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/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 deleted file mode 100644 index 38e6fb403..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityCreateReqVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; - -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.product.BargainProductCreateReqVO; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.Valid; -import java.util.List; - -@Schema(description = "管理后台 - 砍价活动创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BargainActivityCreateReqVO extends BargainActivityBaseVO { - - @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/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 deleted file mode 100644 index 1845a929e..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/activity/BargainActivityPageReqVO.java +++ /dev/null @@ -1,65 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 砍价活动分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -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; - - @Schema(description = "结束时间") - @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/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 deleted file mode 100644 index 2c5ca7ef8..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductBaseVO.java +++ /dev/null @@ -1,35 +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 javax.validation.constraints.NotNull; - -/** - * 砍价商品 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ -@Data -public class BargainProductBaseVO { - - @Schema(description = "商品 spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "123") - @NotNull(message = "商品 spuId 不能为空") - private Long spuId; - - @Schema(description = "商品 skuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @NotNull(message = "商品 skuId 不能为空") - private Long skuId; - - @Schema(description = "砍价起始价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @NotNull(message = "砍价起始价格不能为空") - private Integer bargainFirstPrice; - - @Schema(description = "砍价底价", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @NotNull(message = "砍价底价不能为空") - private Integer bargainPrice; - - @Schema(description = "活动库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "23") - @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/BargainProductRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductRespVO.java deleted file mode 100644 index d0baec008..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/bargain/vo/product/BargainProductRespVO.java +++ /dev/null @@ -1,22 +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; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 砍价商品 Response VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BargainProductRespVO extends BargainProductBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28322") - private Long id; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java index bcd06fdc8..bbef1ab58 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/activity/CombinationActivityPageReqVO.java @@ -5,11 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @Schema(description = "管理后台 - 拼团活动分页 Request VO") @Data @@ -20,46 +15,8 @@ public class CombinationActivityPageReqVO 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; - - @Schema(description = "结束时间") - @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/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..290f2ab4e 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 @@ -1,26 +1,14 @@ package cn.iocoder.yudao.module.promotion.convert.bargain; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -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.BargainActivityRespVO; -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.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * 拼团活动 Convert @@ -38,57 +26,8 @@ public interface BargainActivityConvert { BargainActivityRespVO convert(BargainActivityDO bean); - BargainProductRespVO convert(BargainProductDO bean); - - default BargainActivityRespVO convert(BargainActivityDO bean, List productDOs) { - return convert(bean).setProducts(convertList2(productDOs)); - } - List convertList(List list); PageResult convertPage(PageResult page); - default PageResult convertPage(PageResult page, - List productList, - List spuList) { - Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); - PageResult pageResult = convertPage(page); - pageResult.getList().forEach(item -> { - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { - item.setSpuName(spu.getName()); - item.setPicUrl(spu.getPicUrl()); - }); - item.setProducts(convertList2(productList)); - }); - 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") - }) - BargainProductDO convert(BargainActivityDO activityDO, BargainProductBaseVO vo); - - default List convertList(List products, BargainActivityDO activityDO) { - return CollectionUtils.convertList(products, item -> convert(activityDO, item).setActivityStatus(activityDO.getStatus())); - } - - 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) - .setId(productMap.get(updateProductVO.getSkuId())) - .setActivityStatus(activity.getStatus())); - } - } 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 436067ed8..6e73510e9 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 @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; @@ -93,4 +94,6 @@ public interface CombinationActivityConvert { CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); + List convert(List bean); + } 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..d912542c1 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 @@ -53,7 +53,18 @@ public class BargainActivityDO extends BaseDO { * 商品 SPU 编号 */ private Long spuId; - + /** + * 商品 SKU 编号 + */ + private Long skuId; + /** + * 砍价起始价格,单位分 + */ + private Integer bargainFirstPrice; + /** + * 砍价底价,单位:分 + */ + private Integer bargainPrice; /** * 达到该人数,才能砍到低价 */ @@ -70,7 +81,7 @@ public class BargainActivityDO extends BaseDO { private Integer totalLimitCount; /** - * 砍价库存 + * 砍价活动库存 */ private Integer stock; 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 deleted file mode 100644 index 8f47ce1da..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/bargain/BargainProductDO.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.iocoder.yudao.module.promotion.dal.dataobject.bargain; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -import java.time.LocalDateTime; - -/** - * 砍价商品 DO - * - * @author HUIHUI - */ -@TableName("promotion_bargain_product") -@KeySequence("promotion_bargain_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class BargainProductDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 砍价活动编号 - */ - private Long activityId; - /** - * 商品 SPU 编号 - */ - private Long spuId; - /** - * 商品 SKU 编号 - */ - private Long skuId; - /** - * 砍价商品状态 - * - * 关联 {@link BargainActivityDO#getStatus()} - */ - private Integer activityStatus; - /** - * 活动开始时间点 - */ - private LocalDateTime activityStartTime; - /** - * 活动结束时间点 - */ - private LocalDateTime activityEndTime; - /** - * 砍价起始价格,单位分 - */ - private Integer bargainFirstPrice; - /** - * 砍价底价,单位:分 - */ - private Integer bargainPrice; - /** - * 活动库存 - */ - private Integer stock; - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index af150ef3e..836127ab9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.bargain; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import org.apache.ibatis.annotations.Mapper; @@ -20,6 +20,7 @@ public interface BargainActivityMapper extends BaseMapperX { default PageResult selectPage(BargainActivityPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(BargainActivityDO::getName, reqVO.getName()) + .eqIfPresent(BargainActivityDO::getStatus, reqVO.getStatus()) .orderByDesc(BargainActivityDO::getId)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainProductMapper.java deleted file mode 100644 index f35999e8e..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainProductMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.promotion.dal.mysql.bargain; - -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.Collection; -import java.util.List; - -/** - * 砍价商品 Mapper - * - * @author HUIHUI - */ -@Mapper -public interface BargainProductMapper extends BaseMapperX { - - default List selectListByActivityIds(Collection ids) { - return selectList(BargainProductDO::getActivityId, ids); - } - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index a04018772..c2868d191 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -20,6 +20,7 @@ public interface CombinationActivityMapper extends BaseMapperX selectPage(CombinationActivityPageReqVO reqVO) { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(CombinationActivityDO::getName, reqVO.getName()) + .eqIfPresent(CombinationActivityDO::getStatus, reqVO.getStatus()) .orderByDesc(CombinationActivityDO::getId)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index 8c05b3024..218a24897 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -20,18 +20,20 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByUserIdAndStatus(Long userId, Integer status) { + return selectList(new LambdaQueryWrapperX() + .eq(CombinationRecordDO::getUserId, userId) + .eq(CombinationRecordDO::getStatus, status)); + } /** * 查询拼团记录 * - * @param headId 团长编号 - * @param activityId 活动编号 + * @param headId 团长编号 * @return 拼团记录 */ - default CombinationRecordDO selectRecordByHeadId(Long headId, Long activityId, Integer status) { + default CombinationRecordDO selectOneByHeadId(Long headId, Integer status) { return selectOne(new LambdaQueryWrapperX() - .eq(CombinationRecordDO::getUserId, headId) - .eq(CombinationRecordDO::getActivityId, activityId) + .eq(CombinationRecordDO::getId, headId) .eq(CombinationRecordDO::getStatus, status)); } @@ -45,4 +47,16 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByUserIdAndActivityId(Long userId, Long activityId) { + return selectList(new LambdaQueryWrapperX() + .eq(CombinationRecordDO::getUserId, userId) + .eq(CombinationRecordDO::getActivityId, activityId)); + } } 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..1c49155a8 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 @@ -1,15 +1,12 @@ package cn.iocoder.yudao.module.promotion.service.bargain; import cn.iocoder.yudao.framework.common.pojo.PageResult; -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.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainProductDO; import javax.validation.Valid; -import java.util.Collection; -import java.util.List; /** * 砍价活动 Service 接口 @@ -56,12 +53,5 @@ public interface BargainActivityService { */ PageResult getBargainActivityPage(BargainActivityPageReqVO pageReqVO); - /** - * 获得砍价活动商品列表 - * - * @param ids 砍价活动 ids - * @return 砍价活动的商品列表 - */ - List getBargainProductsByActivityIds(Collection ids); } 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/BargainServiceImpl.java index 1a314ebab..96d9d32b1 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/BargainServiceImpl.java @@ -10,31 +10,25 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; 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.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.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; 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; import javax.annotation.Resource; -import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuAllExists; /** * 砍价活动 Service 实现类 @@ -50,38 +44,37 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord @Resource private BargainRecordMapper recordMapper; @Resource - private BargainProductMapper bargainProductMapper; - @Resource private ProductSpuApi productSpuApi; @Resource private ProductSkuApi productSkuApi; + private static void validateSku(Long skuId, List skus) { + // 校验商品 sku 是否存在 + if (!CollectionUtils.convertSet(skus, ProductSkuRespDTO::getId).contains(skuId)) { + throw exception(SKU_NOT_EXISTS); + } + } + @Override @Transactional(rollbackFor = Exception.class) public Long createBargainActivity(BargainActivityCreateReqVO createReqVO) { // 校验商品 SPU 是否存在是否参加的别的活动 - validateProductBargainConflict(createReqVO.getSpuId(), null); + validateBargainConflict(createReqVO.getSpuId(), null); // 获取所选 spu下的所有 sku List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); - // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, createReqVO.getProducts(), BargainProductCreateReqVO::getSkuId); + validateSku(createReqVO.getSkuId(), skus); // 插入砍价活动 BargainActivityDO activityDO = BargainActivityConvert.INSTANCE.convert(createReqVO); // TODO 营销相关属性初始化 砍价成功更新相关属性 activityDO.setSuccessCount(0); - // 活动总库存 - activityDO.setStock(getSumValue(createReqVO.getProducts(), BargainProductCreateReqVO::getStock, Integer::sum)); activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); bargainActivityMapper.insert(activityDO); - // 插入商品 - List productDOs = BargainActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activityDO); - bargainProductMapper.insertBatch(productDOs); // 返回 return activityDO.getId(); } - private void validateProductBargainConflict(Long spuId, Long activityId) { + private void validateBargainConflict(Long spuId, Long activityId) { // 校验商品 spu 是否存在 List spuList = productSpuApi.getSpuList(CollUtil.newArrayList(spuId)); if (CollUtil.isEmpty(spuList)) { @@ -109,52 +102,16 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord throw exception(BARGAIN_ACTIVITY_STATUS_DISABLE); } // 校验商品冲突 - validateProductBargainConflict(updateReqVO.getSpuId(), updateReqVO.getId()); + validateBargainConflict(updateReqVO.getSpuId(), updateReqVO.getId()); // 获取所选 spu下的所有 sku List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, updateReqVO.getProducts(), BargainProductUpdateReqVO::getSkuId); + validateSku(updateReqVO.getSkuId(), skus); // 更新 BargainActivityDO updateObj = BargainActivityConvert.INSTANCE.convert(updateReqVO); - // 更新活动库存 - updateObj.setStock(getSumValue(updateReqVO.getProducts(), BargainProductUpdateReqVO::getStock, Integer::sum)); bargainActivityMapper.updateById(updateObj); - // 更新商品 - updateBargainProduct(updateObj, updateReqVO.getProducts()); - } - /** - * 更新砍价商品 - * - * @param updateObj 更新的活动 - * @param products 商品配置 - */ - private void updateBargainProduct(BargainActivityDO updateObj, List products) { - // 默认全部新增 - List defaultNewList = BargainActivityConvert.INSTANCE.convertList(products, updateObj); - // 数据库中的老数据 - List oldList = bargainProductMapper.selectListByActivityIds(CollUtil.newArrayList(updateObj.getId())); - List> lists = CollectionUtils.diffList(oldList, defaultNewList, (oldVal, newVal) -> { - boolean same = ObjectUtil.equal(oldVal.getSkuId(), newVal.getSkuId()); - if (same) { - newVal.setId(oldVal.getId()); - } - return same; - }); - - // create - if (CollUtil.isNotEmpty(lists.get(0))) { - bargainProductMapper.insertBatch(lists.get(0)); - } - // update - if (CollUtil.isNotEmpty(lists.get(1))) { - bargainProductMapper.updateBatch(lists.get(1)); - } - // delete - if (CollUtil.isNotEmpty(lists.get(2))) { - bargainProductMapper.deleteBatchIds(CollectionUtils.convertList(lists.get(2), BargainProductDO::getId)); - } } @Override @@ -189,9 +146,4 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord return bargainActivityMapper.selectPage(pageReqVO); } - @Override - public List getBargainProductsByActivityIds(Collection ids) { - return bargainProductMapper.selectListByActivityIds(ids); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index 93473893c..72d68c780 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; +import java.util.List; + /** * 商品活动记录 service * @@ -41,4 +43,23 @@ public interface CombinationRecordService { */ CombinationRecordDO getCombinationRecord(Long userId, Long orderId); + /** + * 获取拼团记录 + * + * @param userId 用户 id + * @param activityId 活动 id + * @return 拼团记录列表 + */ + List getRecordListByUserIdAndActivityId(Long userId, Long activityId); + + /** + * 验证组合限制数 + * 校验是否满足限购要求 + * + * @param count 本次购买数量 + * @param sumCount 已购买数量合计 + * @param activityId 活动编号 + */ + void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java index e8efcc2b0..1b6ffd69f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java @@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -68,8 +69,6 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi // 校验商品 sku 是否存在 validateProductSkuAllExists(skus, createReqVO.getProducts(), CombinationProductCreateReqVO::getSkuId); - // TODO 艿艿 有个小问题:现在有活动时间和限制时长,活动时间的结束时间早于设置的限制时间怎么算状态比如: - // 活动时间 2023-08-05 15:00:00 - 2023-08-05 15:20:00 限制时长 2小时,那么活动时间结束就结束还是加时到满两小时 // 插入拼团活动 CombinationActivityDO activityDO = CombinationActivityConvert.INSTANCE.convert(createReqVO); // TODO 营销相关属性初始化 拼团成功更新相关属性 @@ -132,7 +131,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi * 更新拼团商品 * * @param activity 拼团活动 - * @param products 该活动的最新商品配置 + * @param products 该活动的最新商品配置 */ private void updateCombinationProduct(CombinationActivityDO activity, List products) { // 第一步,对比新老数据,获得添加、修改、删除的列表 @@ -201,6 +200,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi } @Override + @Transactional(rollbackFor = Exception.class) public void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) { // 校验拼团是否存在 CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); @@ -244,6 +244,7 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi } @Override + @Transactional(rollbackFor = Exception.class) public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1.1 校验拼团活动 CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId()); @@ -252,9 +253,19 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi if (recordDO != null) { throw exception(COMBINATION_RECORD_EXISTS); } - // 1.3 父拼团是否存在,是否已经满了 + // 1.3 校验用户是否参加了其它拼团 + List recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + if (CollUtil.isNotEmpty(recordDOList)) { + throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); + } + // 1.4 校验当前活动是否过期 + if (LocalDateTime.now().isAfter(activity.getEndTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } + // 1.5 父拼团是否存在,是否已经满了 if (reqDTO.getHeadId() != null) { - CombinationRecordDO recordDO1 = recordMapper.selectRecordByHeadId(reqDTO.getHeadId(), reqDTO.getActivityId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + // 查询进行中的父拼团 + CombinationRecordDO recordDO1 = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); if (recordDO1 == null) { throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); } @@ -263,7 +274,6 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi throw exception(COMBINATION_RECORD_USER_FULL); } } - // TODO @puhui999:应该还有一些校验,后续补噶;例如说,一个团,自己已经参与进去了,不能再参与进去; // 2. 创建拼团记录 CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); @@ -288,4 +298,22 @@ public class CombinationServiceImpl implements CombinationActivityService, Combi return recordMapper.selectListByStatus(status); } + public List getRecordListByUserIdAndActivityId(Long userId, Long activityId) { + return recordMapper.selectListByUserIdAndActivityId(userId, activityId); + } + + @Override + public void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount) { + // 1.1 校验拼团活动 + CombinationActivityDO activity = validateCombinationActivityExists(activityId); + // 校验是否达到限购总限购标准 + if ((sumCount + count) > activity.getTotalLimitCount()) { + throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); + } + // 单次购买是否达到限购标准 + if (count > activity.getSingleLimitCount()) { + throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); + } + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java index 537cb1e27..4ba3b26a5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/seckillconfig/SeckillConfigServiceImpl.java @@ -62,7 +62,6 @@ public class SeckillConfigServiceImpl implements SeckillConfigService { seckillConfigMapper.updateById(updateObj); } - // TODO @puhui999: 这个要不合并到更新操作里? 不单独有个操作咧; fix: 更新状态不用那么多必须的参数,更新的时候需要校验时间段 @Override public void updateSeckillConfigStatus(Long id, Integer status) { // 校验秒杀时段是否存在 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java index 2bf583144..81ce84dd4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java @@ -13,7 +13,6 @@ import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; @@ -152,19 +151,7 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // 准备参数 CombinationActivityPageReqVO reqVO = new CombinationActivityPageReqVO(); reqVO.setName(null); - reqVO.setSpuId(null); - reqVO.setTotalLimitCount(null); - reqVO.setSingleLimitCount(null); - reqVO.setStartTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - reqVO.setEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - reqVO.setUserSize(null); - reqVO.setTotalNum(null); - reqVO.setSuccessNum(null); - reqVO.setOrderUserCount(null); - reqVO.setVirtualGroup(null); reqVO.setStatus(null); - reqVO.setLimitDuration(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 PageResult pageResult = combinationActivityService.getCombinationActivityPage(reqVO); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 7a3e0292b..1be549a0a 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -31,10 +31,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_COMMENT_STATUS_NOT_FALSE = new ErrorCode(1011000020, "创建交易订单项的评价失败,订单已评价"); ErrorCode ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE = new ErrorCode(1011000021, "交易订单发货失败,订单已退款或部分退款"); ErrorCode ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000022, "交易订单发货失败,拼团未成功"); - // TODO 已移除订单单独发货 - ErrorCode ORDER_DELIVERY_FAILED_ITEMS_NOT_EMPTY = new ErrorCode(1011000023, "订单发货失败,请选择发货商品"); - ErrorCode ORDER_DELIVERY_FAILED_ITEM_NOT_EXISTS = new ErrorCode(1011000024, "订单发货失败,所选发货商品不存在"); - ErrorCode ORDER_DELIVERY_FAILED_ITEM_ALREADY_DELIVERY = new ErrorCode(1011000025, "订单发货失败,所选商品已发货"); + ErrorCode ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000023, "交易订单发货失败,砍价未成功"); // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java index 67b130ca0..c80bf133a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/vo/TradeOrderDeliveryReqVO.java @@ -29,7 +29,5 @@ public class TradeOrderDeliveryReqVO { @NotEmpty(message = "发货物流单号不能为空") private String logisticsNo; - // =============== 同城配送 ================ - // TODO } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 765ed58c4..c20742a67 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -126,8 +126,7 @@ public class AppTradeOrderController { @Operation(summary = "确认交易订单收货") @Parameter(name = "id", description = "交易订单编号") public CommonResult takeOrder(@RequestParam("id") Long id) { - // TODO @芋艿:未实现,mock 用 - return success(true); + return success(tradeOrderService.receiveOrder(getLoginUserId(), id)); } @DeleteMapping("/cancel") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java index 62cccf0f7..553bd5697 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java @@ -25,6 +25,12 @@ public interface TradeOrderItemMapper extends BaseMapperX { return selectList(TradeOrderItemDO::getOrderId, orderIds); } + default List selectListByOrderIdAnSkuId(Collection orderIds, Collection skuIds) { + return selectList(new LambdaQueryWrapperX() + .in(TradeOrderItemDO::getOrderId, orderIds) + .eq(TradeOrderItemDO::getSkuId, skuIds)); + } + default TradeOrderItemDO selectOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) { return selectOne(new LambdaQueryWrapperX() .eq(TradeOrderItemDO::getId, orderItemId) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java index bb234ab85..642c8f464 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java @@ -65,9 +65,10 @@ public interface TradeOrderService { * 【会员】收货交易订单 * * @param userId 用户编号 - * @param id 订单编号 + * @param id 订单编号 + * @return 成功/失败 */ - void receiveOrder(Long userId, Long id); + Boolean receiveOrder(Long userId, Long id); /** * 获得指定编号的交易订单 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index 64e90eb52..0a37021fd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; @@ -22,7 +23,9 @@ import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; +import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; @@ -108,6 +111,9 @@ public class TradeOrderServiceImpl implements TradeOrderService { @Resource private CombinationRecordApi combinationRecordApi; + @Resource + private BargainRecordApi bargainRecordApi; + // =================== Order =================== @Override @@ -173,8 +179,18 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 拼团 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { MemberUserRespDTO user = memberUserApi.getUser(userId); + List recordRespDTOS = combinationRecordApi.getRecordListByUserIdAndActivityId(userId, createReqVO.getCombinationActivityId()); // TODO 拼团一次应该只能选择一种规格的商品 - combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user)); + TradeOrderItemDO orderItemDO = orderItems.get(0); + if (CollUtil.isNotEmpty(recordRespDTOS)) { + List skuIds = convertList(recordRespDTOS, CombinationRecordRespDTO::getSkuId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())); + List tradeOrderItemDOS = tradeOrderItemMapper.selectListByOrderIdAnSkuId(convertList(recordRespDTOS, + CombinationRecordRespDTO::getOrderId, item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds); + combinationRecordApi.validateCombinationLimitCount(createReqVO.getCombinationActivityId(), + CollectionUtils.getSumValue(tradeOrderItemDOS, TradeOrderItemDO::getCount, Integer::sum), orderItemDO.getCount()); + } + + combinationRecordApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItemDO, createReqVO, user)); } // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 if (Objects.equals(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { @@ -382,33 +398,23 @@ public class TradeOrderServiceImpl implements TradeOrderService { public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) { // 1.1 校验并获得交易订单(可发货) TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); - - /* TODO - * fix: 首先需要店铺设置配送方式如: 自提 、配送、物流-配送、物流-配送-自提、商家配送 - * 1.如果店铺有设置配送方式用户只填写收货地址的情况下店家后台自己选择配送方式 - * 2.如果店铺只支持到店自提那么下单后默认发货不需要物流 - * 3.如果店铺支持 物流-配送-自提 的情况下后台不需要选择配送方式按前端用户选择的配送方式发货即可 - */ TradeOrderDO updateOrderObj = new TradeOrderDO(); // 判断发货类型 // 2.1 快递发货 if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) { // 校验快递公司 - validateDeliveryExpress(deliveryReqVO); - updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); + DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); + if (deliveryExpress == null) { + throw exception(EXPRESS_NOT_EXISTS); + } + if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { + throw exception(EXPRESS_STATUS_NOT_ENABLE); + } + updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()).setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode()); } - // 2.2 用户自提 - if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.PICK_UP.getMode())) { - // TODO 校验自提门店是否存在 - // 重置一下确保快递公司和快递单号为空 - updateOrderObj.setLogisticsId(null).setLogisticsNo(""); - } - // 2.3 TODO 芋艿:如果无需发货,需要怎么存储?回复:需要把 deliverType 设置为 DeliveryTypeEnum.NULL + // 2.2 无需发货 if (Objects.equals(deliveryReqVO.getType(), DeliveryTypeEnum.NULL.getMode())) { - // TODO 情况一:正常走发货逻辑和用户自提有点像 不同点:不需要自提门店只需要用户确认收货 - // TODO 情况二:用户下单付款后直接确认收货或等待用户确认收货 - // 重置一下确保快递公司和快递单号为空 - updateOrderObj.setLogisticsId(null).setLogisticsNo(""); + updateOrderObj.setLogisticsId(null).setLogisticsNo("").setDeliveryType(DeliveryTypeEnum.NULL.getMode()); } // 更新 TradeOrderDO 状态为已发货,等待收货 @@ -428,16 +434,6 @@ public class TradeOrderServiceImpl implements TradeOrderService { // TODO 设计:lili:是不是发货后,才支持售后? } - private void validateDeliveryExpress(TradeOrderDeliveryReqVO deliveryReqVO) { - DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); - if (deliveryExpress == null) { - throw exception(EXPRESS_NOT_EXISTS); - } - if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { - throw exception(EXPRESS_STATUS_NOT_ENABLE); - } - } - /** * 校验交易订单满足被发货的条件 * @@ -464,17 +460,23 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 订单类型:拼团 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { // 校验订单拼团是否成功 - if (combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { + if (combinationRecordApi.validateRecordSuccess(order.getUserId(), order.getId())) { throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); } } - // TODO puhui999: 校验订单砍价是否成功 + // 订单类类型:砍价 + if (Objects.equals(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) { + // 校验订单砍价是否成功 + if (bargainRecordApi.validateRecordSuccess(order.getUserId(), order.getId())) { + throw exception(ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS); + } + } return order; } @Override @Transactional(rollbackFor = Exception.class) - public void receiveOrder(Long userId, Long id) { + public Boolean receiveOrder(Long userId, Long id) { // 校验并获得交易订单(可收货) TradeOrderDO order = validateOrderReceivable(userId, id); @@ -490,6 +492,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { // TODO 芋艿:lili 发送订单变化的消息 // TODO 芋艿:lili 发送商品被购买完成的数据 + return Boolean.TRUE; } @Override From e2a8f7b38973b21ff8f5293fb90cf23391839dd2 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 14 Aug 2023 21:26:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=91=E8=B4=A7=E9=80=BB=E8=BE=91=E3=80=81=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=A0=8D=E4=BB=B7=E6=B4=BB=E5=8A=A8=E3=80=81=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95=E5=88=9B=E5=BB=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationActivityConvert.java | 19 ++++++++------- .../SeckillActivityConvert.java | 23 +++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) 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 6e73510e9..7977d8fa9 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 @@ -68,20 +68,19 @@ public interface CombinationActivityConvert { 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 = "activePrice", source = "vo.activePrice"), - @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 = "activePrice", source = "product.activePrice"), + @Mapping(target = "activityStartTime", source = "activity.startTime"), + @Mapping(target = "activityEndTime", source = "activity.endTime") }) - CombinationProductDO convert(CombinationActivityDO activityDO, CombinationProductBaseVO vo); + CombinationProductDO convert(CombinationActivityDO activity, CombinationProductBaseVO product); - default List convertList(List products, CombinationActivityDO activityDO) { - return CollectionUtils.convertList(products, item -> convert(activityDO, item).setActivityStatus(activityDO.getStatus())); + default List convertList(List products, CombinationActivityDO activity) { + return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus())); } default List convertList(List updateProductVOs, diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index 65f3b9b0c..43b114bde 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -56,22 +56,21 @@ public interface SeckillActivityConvert { return convert1(seckillActivity).setProducts(convertList2(seckillProducts)); } - // TODO @puhui999:参数改成 activity、product 会不会干净一点哈 @Mappings({ @Mapping(target = "id", ignore = true), - @Mapping(target = "activityId", source = "activityDO.id"), - @Mapping(target = "configIds", source = "activityDO.configIds"), - @Mapping(target = "spuId", source = "activityDO.spuId"), - @Mapping(target = "skuId", source = "vo.skuId"), - @Mapping(target = "seckillPrice", source = "vo.seckillPrice"), - @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 = "configIds", source = "activity.configIds"), + @Mapping(target = "spuId", source = "activity.spuId"), + @Mapping(target = "skuId", source = "product.skuId"), + @Mapping(target = "seckillPrice", source = "product.seckillPrice"), + @Mapping(target = "stock", source = "product.stock"), + @Mapping(target = "activityStartTime", source = "activity.startTime"), + @Mapping(target = "activityEndTime", source = "activity.endTime") }) - SeckillProductDO convert(SeckillActivityDO activityDO, SeckillProductBaseVO vo); + SeckillProductDO convert(SeckillActivityDO activity, SeckillProductBaseVO product); - default List convertList(List products, SeckillActivityDO activityDO) { - return CollectionUtils.convertList(products, item -> convert(activityDO, item).setActivityStatus(activityDO.getStatus())); + default List convertList(List products, SeckillActivityDO activity) { + return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus())); } List convertList2(List productDOs); From 5c2723c7bfd26d1b431cdc669e77f1647a0e5a90 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 15 Aug 2023 00:02:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bargain/BargainRecordApiImpl.java | 24 ++ .../bargain/BargainActivityController.java | 22 +- .../bargain/BargainActivityConvert.java | 4 +- .../CombinationActivityConvert.java | 5 +- .../SeckillActivityConvert.java | 10 +- .../bargain/BargainActivityService.java | 4 +- .../bargain/BargainActivityServiceImpl.java | 7 +- .../service/bargain/BargainRecordService.java | 2 +- .../bargain/BargainRecordServiceImpl.java | 14 + .../CombinationRecordServiceImpl.java | 38 ++- .../combination/CombinationServiceImpl.java | 319 ------------------ .../CombinationActivityServiceImplTest.java | 22 +- 12 files changed, 107 insertions(+), 364 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApiImpl.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApiImpl.java new file mode 100644 index 000000000..16ff03c44 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApiImpl.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.promotion.api.bargain; + +import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainRecordCreateReqDTO; +import org.springframework.stereotype.Service; + +/** + * 砍价活动 API 实现类 TODO @puhui999 + * + * @author HUIHUI + */ +@Service +public class BargainRecordApiImpl implements BargainRecordApi { + + @Override + public void createRecord(BargainRecordCreateReqDTO reqDTO) { + + } + + @Override + public boolean validateRecordSuccess(Long userId, Long orderId) { + return false; + } + +} 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 5f7e50a03..a6d131b94 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 @@ -4,12 +4,12 @@ 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; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityBaseVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; 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.service.bargain.BargainActivityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -20,8 +20,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Collections; -import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -40,7 +38,7 @@ public class BargainActivityController { @PostMapping("/create") @Operation(summary = "创建砍价活动") @PreAuthorize("@ss.hasPermission('promotion:bargain-activity:create')") - public CommonResult createBargainActivity(@Valid @RequestBody BargainActivityCreateReqVO createReqVO) { + public CommonResult createBargainActivity(@Valid @RequestBody BargainActivityBaseVO createReqVO) { return success(activityService.createBargainActivity(createReqVO)); } @@ -79,14 +77,6 @@ public class BargainActivityController { if (CollUtil.isEmpty(pageResult.getList())) { return success(PageResult.empty(pageResult.getTotal())); } - - // 拼接数据 -// 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)); return success(BargainActivityConvert.INSTANCE.convertPage(activityService.getBargainActivityPage(pageVO))); } 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 290f2ab4e..d3ef255f9 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 @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.promotion.convert.bargain; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; @@ -20,7 +20,7 @@ public interface BargainActivityConvert { BargainActivityConvert INSTANCE = Mappers.getMapper(BargainActivityConvert.class); - BargainActivityDO convert(BargainActivityCreateReqVO bean); + BargainActivityDO convert(BargainActivityBaseVO bean); BargainActivityDO convert(BargainActivityUpdateReqVO bean); 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 7977d8fa9..0eb511474 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 @@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; @@ -73,7 +72,7 @@ public interface CombinationActivityConvert { @Mapping(target = "activityId", source = "activity.id"), @Mapping(target = "spuId", source = "activity.spuId"), @Mapping(target = "skuId", source = "product.skuId"), - @Mapping(target = "activePrice", source = "product.activePrice"), + @Mapping(target = "combinationPrice", source = "product.combinationPrice"), @Mapping(target = "activityStartTime", source = "activity.startTime"), @Mapping(target = "activityEndTime", source = "activity.endTime") }) @@ -83,7 +82,7 @@ public interface CombinationActivityConvert { return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus())); } - default List convertList(List updateProductVOs, + default List convertList(List updateProductVOs, List products, CombinationActivityDO activity) { Map productMap = convertMap(products, CombinationProductDO::getSkuId, CombinationProductDO::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/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index 43b114bde..96ca1ef8c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO; @@ -40,11 +41,14 @@ public interface SeckillActivityConvert { PageResult convertPage(PageResult page); default PageResult convertPage(PageResult page, List seckillProducts, List spuList) { - Map spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId, c -> c); + Map spuMap = CollectionUtils.convertMap(spuList, ProductSpuRespDTO::getId); PageResult pageResult = convertPage(page); pageResult.getList().forEach(item -> { - item.setSpuName(spuMap.get(item.getSpuId()).getName()); - item.setPicUrl(spuMap.get(item.getSpuId()).getPicUrl()); + MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { + item.setSpuName(spu.getName()); + item.setPicUrl(spu.getPicUrl()); + }); + item.setProducts(convertList2(seckillProducts)); }); return pageResult; 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 1c49155a8..e7a1240cb 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 @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.promotion.service.bargain; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; @@ -21,7 +21,7 @@ public interface BargainActivityService { * @param createReqVO 创建信息 * @return 编号 */ - Long createBargainActivity(@Valid BargainActivityCreateReqVO createReqVO); + Long createBargainActivity(@Valid BargainActivityBaseVO createReqVO); /** * 更新砍价活动 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 96d9d32b1..51551e6e0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; 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.BargainActivityCreateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityBaseVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.BargainActivityUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.bargain.BargainActivityConvert; @@ -37,7 +37,8 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; */ @Service @Validated -public class BargainServiceImpl implements BargainActivityService, BargainRecordService { +public class BargainActivityServiceImpl implements BargainActivityService { + @Resource private BargainActivityMapper bargainActivityMapper; @@ -57,7 +58,7 @@ public class BargainServiceImpl implements BargainActivityService, BargainRecord @Override @Transactional(rollbackFor = Exception.class) - public Long createBargainActivity(BargainActivityCreateReqVO createReqVO) { + public Long createBargainActivity(BargainActivityBaseVO createReqVO) { // 校验商品 SPU 是否存在是否参加的别的活动 validateBargainConflict(createReqVO.getSpuId(), null); // 获取所选 spu下的所有 sku diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java index fda991a72..dc5ab1ef9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordService.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.promotion.service.bargain; /** - * 商品活动记录 service + * 砍价记录 service 接口 * * @author HUIHUI */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java new file mode 100644 index 000000000..78780c97b --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.promotion.service.bargain; + +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +/** + * 砍价记录 Service 实现类 + * + * @author HUIHUI + */ +@Service +@Validated +public class BargainRecordServiceImpl implements BargainRecordService { +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index efbc0d1d0..4e2f85e27 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -14,11 +14,11 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_RECORD_USER_FULL; // TODO 芋艿:等拼团记录做完,完整 review 下 /** @@ -37,6 +37,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { private CombinationRecordMapper recordMapper; @Override + @Transactional(rollbackFor = Exception.class) public void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) { // 校验拼团是否存在 CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); @@ -80,6 +81,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override + @Transactional(rollbackFor = Exception.class) public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1.1 校验拼团活动 CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(reqDTO.getActivityId()); @@ -88,9 +90,19 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { if (recordDO != null) { throw exception(COMBINATION_RECORD_EXISTS); } - // 1.3 父拼团是否存在,是否已经满了 + // 1.3 校验用户是否参加了其它拼团 + List recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + if (CollUtil.isNotEmpty(recordDOList)) { + throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); + } + // 1.4 校验当前活动是否过期 + if (LocalDateTime.now().isAfter(activity.getEndTime())) { + throw exception(COMBINATION_RECORD_FAILED_TIME_END); + } + // 1.5 父拼团是否存在,是否已经满了 if (reqDTO.getHeadId() != null) { - CombinationRecordDO recordDO1 = recordMapper.selectRecordByHeadId(reqDTO.getHeadId(), reqDTO.getActivityId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + // 查询进行中的父拼团 + CombinationRecordDO recordDO1 = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); if (recordDO1 == null) { throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); } @@ -99,7 +111,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { throw exception(COMBINATION_RECORD_USER_FULL); } } - // TODO @puhui999:应该还有一些校验,后续补噶;例如说,一个团,自己已经参与进去了,不能再参与进去; // 2. 创建拼团记录 CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); @@ -115,6 +126,25 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return validateCombinationRecord(userId, orderId); } + @Override + public List getRecordListByUserIdAndActivityId(Long userId, Long activityId) { + return recordMapper.selectListByUserIdAndActivityId(userId, activityId); + } + + @Override + public void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount) { + // 1.1 校验拼团活动 + CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(activityId); + // 校验是否达到限购总限购标准 + if ((sumCount + count) > activity.getTotalLimitCount()) { + throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); + } + // 单次购买是否达到限购标准 + if (count > activity.getSingleLimitCount()) { + throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); + } + } + /** * APP 端获取开团记录 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java deleted file mode 100644 index 1b6ffd69f..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationServiceImpl.java +++ /dev/null @@ -1,319 +0,0 @@ -package cn.iocoder.yudao.module.promotion.service.combination; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; -import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; -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.api.combination.dto.CombinationRecordCreateReqDTO; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateStatusReqDTO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductUpdateReqVO; -import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; -import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; -import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationActivityMapper; -import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationProductMapper; -import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; -import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.module.promotion.util.PromotionUtils.validateProductSkuAllExists; - -/** - * 拼团活动 Service 实现类 - * - * @author HUIHUI - */ -@Service -@Validated -public class CombinationServiceImpl implements CombinationActivityService, CombinationRecordService { - - @Resource - private CombinationActivityMapper combinationActivityMapper; - @Resource - private CombinationRecordMapper recordMapper; - @Resource - private CombinationProductMapper combinationProductMapper; - @Resource - private ProductSpuApi productSpuApi; - @Resource - private ProductSkuApi productSkuApi; - - @Override - @Transactional(rollbackFor = Exception.class) - public Long createCombinationActivity(CombinationActivityCreateReqVO createReqVO) { - // 校验商品 SPU 是否存在是否参加的别的活动 - validateProductCombinationConflict(createReqVO.getSpuId(), null); - // 获取所选 spu下的所有 sku - List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(createReqVO.getSpuId())); - // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, createReqVO.getProducts(), CombinationProductCreateReqVO::getSkuId); - - // 插入拼团活动 - CombinationActivityDO activityDO = CombinationActivityConvert.INSTANCE.convert(createReqVO); - // TODO 营销相关属性初始化 拼团成功更新相关属性 - activityDO.setTotalNum(0); - activityDO.setSuccessNum(0); - activityDO.setOrderUserCount(0); - activityDO.setVirtualGroup(0); - activityDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - combinationActivityMapper.insert(activityDO); - // 插入商品 - List productDOs = CombinationActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activityDO); - combinationProductMapper.insertBatch(productDOs); - // 返回 - return activityDO.getId(); - } - - private void validateProductCombinationConflict(Long spuId, Long activityId) { - // 校验商品 spu 是否存在 - List spuList = productSpuApi.getSpuList(CollUtil.newArrayList(spuId)); - if (CollUtil.isEmpty(spuList)) { - throw exception(SPU_NOT_EXISTS); - } - // 查询所有开启的拼团活动 - List activityDOs = combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus()); - // 更新时排除自己 - if (activityId != null) { - activityDOs.removeIf(item -> ObjectUtil.equal(item.getId(), activityId)); - } - // 过滤出所有 spuIds 有交集的活动 - List doList = CollectionUtils.convertList(activityDOs, c -> c, s -> ObjectUtil.equal(s.getId(), spuId)); - if (CollUtil.isNotEmpty(doList)) { - throw exception(COMBINATION_ACTIVITY_SPU_CONFLICTS); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateCombinationActivity(CombinationActivityUpdateReqVO updateReqVO) { - // 校验存在 - CombinationActivityDO activityDO = validateCombinationActivityExists(updateReqVO.getId()); - // 校验状态 - if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { - throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); - } - // 校验商品冲突 - validateProductCombinationConflict(updateReqVO.getSpuId(), updateReqVO.getId()); - // 获取所选 spu下的所有 sku - List skus = productSkuApi.getSkuListBySpuId(CollectionUtil.newArrayList(updateReqVO.getSpuId())); - // 校验商品 sku 是否存在 - validateProductSkuAllExists(skus, updateReqVO.getProducts(), CombinationProductUpdateReqVO::getSkuId); - - // 更新 - CombinationActivityDO updateObj = CombinationActivityConvert.INSTANCE.convert(updateReqVO); - combinationActivityMapper.updateById(updateObj); - // 更新商品 - updateCombinationProduct(updateObj, updateReqVO.getProducts()); - } - - /** - * 更新拼团商品 - * - * @param activity 拼团活动 - * @param products 该活动的最新商品配置 - */ - private void updateCombinationProduct(CombinationActivityDO activity, List products) { - // 第一步,对比新老数据,获得添加、修改、删除的列表 - List newList = CombinationActivityConvert.INSTANCE.convertList(products, activity); - List oldList = combinationProductMapper.selectListByActivityIds(CollUtil.newArrayList(activity.getId())); - List> diffList = CollectionUtils.diffList(oldList, newList, (oldVal, newVal) -> { - boolean same = ObjectUtil.equal(oldVal.getSkuId(), newVal.getSkuId()); - if (same) { - newVal.setId(oldVal.getId()); - } - return same; - }); - - // 第二步,批量添加、修改、删除 - if (CollUtil.isNotEmpty(diffList.get(0))) { - combinationProductMapper.insertBatch(diffList.get(0)); - } - if (CollUtil.isNotEmpty(diffList.get(1))) { - combinationProductMapper.updateBatch(diffList.get(1)); - } - if (CollUtil.isNotEmpty(diffList.get(2))) { - combinationProductMapper.deleteBatchIds(CollectionUtils.convertList(diffList.get(2), CombinationProductDO::getId)); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteCombinationActivity(Long id) { - // 校验存在 - CombinationActivityDO activityDO = validateCombinationActivityExists(id); - // 校验状态 - if (ObjectUtil.equal(activityDO.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { - throw exception(COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END); - } - - // 删除 - combinationActivityMapper.deleteById(id); - } - - private CombinationActivityDO validateCombinationActivityExists(Long id) { - CombinationActivityDO activityDO = combinationActivityMapper.selectById(id); - if (activityDO == null) { - throw exception(COMBINATION_ACTIVITY_NOT_EXISTS); - } - return activityDO; - } - - @Override - public CombinationActivityDO getCombinationActivity(Long id) { - return validateCombinationActivityExists(id); - } - - @Override - public List getCombinationActivityList(Collection ids) { - return combinationActivityMapper.selectBatchIds(ids); - } - - @Override - public PageResult getCombinationActivityPage(CombinationActivityPageReqVO pageReqVO) { - return combinationActivityMapper.selectPage(pageReqVO); - } - - @Override - public List getCombinationProductsByActivityIds(Collection ids) { - return combinationProductMapper.selectListByActivityIds(ids); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) { - // 校验拼团是否存在 - CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); - - // 更新状态 - recordDO.setStatus(reqDTO.getStatus()); - recordMapper.updateById(recordDO); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateCombinationRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordUpdateStatusReqDTO reqDTO) { - CombinationRecordDO recordDO = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getOrderId()); - // 更新状态 - recordDO.setStatus(reqDTO.getStatus()); - // 更新开始时间 - recordDO.setStartTime(reqDTO.getStartTime()); - recordMapper.updateById(recordDO); - - // 更新拼团参入人数 - List recordDOs = recordMapper.selectListByHeadIdAndStatus(recordDO.getHeadId(), reqDTO.getStatus()); - if (CollUtil.isNotEmpty(recordDOs)) { - recordDOs.forEach(item -> { - item.setUserCount(recordDOs.size()); - // 校验拼团是否满足要求 - if (ObjectUtil.equal(recordDOs.size(), recordDO.getUserSize())) { - item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); - } - }); - } - recordMapper.updateBatch(recordDOs); - } - - private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { - // 校验拼团是否存在 - CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId); - if (recordDO == null) { - throw exception(COMBINATION_RECORD_NOT_EXISTS); - } - return recordDO; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { - // 1.1 校验拼团活动 - CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId()); - // 1.2 需要校验下,他当前是不是已经参加了该拼团; - CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(reqDTO.getUserId(), reqDTO.getOrderId()); - if (recordDO != null) { - throw exception(COMBINATION_RECORD_EXISTS); - } - // 1.3 校验用户是否参加了其它拼团 - List recordDOList = recordMapper.selectListByUserIdAndStatus(reqDTO.getUserId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); - if (CollUtil.isNotEmpty(recordDOList)) { - throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); - } - // 1.4 校验当前活动是否过期 - if (LocalDateTime.now().isAfter(activity.getEndTime())) { - throw exception(COMBINATION_RECORD_FAILED_TIME_END); - } - // 1.5 父拼团是否存在,是否已经满了 - if (reqDTO.getHeadId() != null) { - // 查询进行中的父拼团 - CombinationRecordDO recordDO1 = recordMapper.selectOneByHeadId(reqDTO.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); - if (recordDO1 == null) { - throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); - } - // 校验拼团是否满足要求 - if (ObjectUtil.equal(recordDO1.getUserCount(), recordDO1.getUserSize())) { - throw exception(COMBINATION_RECORD_USER_FULL); - } - } - - // 2. 创建拼团记录 - CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); - record.setVirtualGroup(false); - // TODO @puhui999:过期时间,应该是 Date 哈; - record.setExpireTime(activity.getLimitDuration()); - record.setUserSize(activity.getUserSize()); - recordMapper.insert(record); - } - - @Override - public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { - return validateCombinationRecord(userId, orderId); - } - - /** - * APP 端获取开团记录 - * - * @return 开团记录 - */ - public List getRecordListByStatus(Integer status) { - return recordMapper.selectListByStatus(status); - } - - public List getRecordListByUserIdAndActivityId(Long userId, Long activityId) { - return recordMapper.selectListByUserIdAndActivityId(userId, activityId); - } - - @Override - public void validateCombinationLimitCount(Long activityId, Integer count, Integer sumCount) { - // 1.1 校验拼团活动 - CombinationActivityDO activity = validateCombinationActivityExists(activityId); - // 校验是否达到限购总限购标准 - if ((sumCount + count) > activity.getTotalLimitCount()) { - throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); - } - // 单次购买是否达到限购标准 - if (count > activity.getSingleLimitCount()) { - throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); - } - } - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java index 81ce84dd4..86d58d747 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java @@ -23,15 +23,15 @@ import static org.junit.jupiter.api.Assertions.*; // TODO 芋艿:等完成后,在补全单测 /** - * {@link CombinationServiceImpl} 的单元测试类 + * {@link CombinationActivityServiceImpl} 的单元测试类 * * @author HUIHUI */ -@Import(CombinationServiceImpl.class) +@Import(CombinationActivityServiceImpl.class) public class CombinationActivityServiceImplTest extends BaseDbUnitTest { @Resource - private CombinationServiceImpl combinationActivityService; + private CombinationActivityServiceImpl combinationActivityService; @Resource private CombinationActivityMapper combinationActivityMapper; @@ -111,8 +111,8 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { o.setStartTime(null); o.setEndTime(null); o.setUserSize(null); - o.setTotalNum(null); - o.setSuccessNum(null); + o.setTotalCount(null); + o.setSuccessCount(null); o.setOrderUserCount(null); o.setVirtualGroup(null); o.setStatus(null); @@ -135,9 +135,9 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // 测试 userSize 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); // 测试 totalNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalNum(null))); + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalCount(null))); // 测试 successNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessNum(null))); + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessCount(null))); // 测试 orderUserCount 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); // 测试 virtualGroup 不匹配 @@ -173,8 +173,8 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { o.setStartTime(null); o.setEndTime(null); o.setUserSize(null); - o.setTotalNum(null); - o.setSuccessNum(null); + o.setTotalCount(null); + o.setSuccessCount(null); o.setOrderUserCount(null); o.setVirtualGroup(null); o.setStatus(null); @@ -197,9 +197,9 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // 测试 userSize 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setUserSize(null))); // 测试 totalNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalNum(null))); + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setTotalCount(null))); // 测试 successNum 不匹配 - combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessNum(null))); + combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setSuccessCount(null))); // 测试 orderUserCount 不匹配 combinationActivityMapper.insert(cloneIgnoreId(dbCombinationActivity, o -> o.setOrderUserCount(null))); // 测试 virtualGroup 不匹配