From a10d77cdfeb008a95b310178066d1ea14aa23be9 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 13 Sep 2023 12:04:13 +0800 Subject: [PATCH] =?UTF-8?q?mall+order:=20=E5=AE=8C=E5=96=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=20TODO=20=E6=8F=90=E5=88=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/sku/dto/ProductSkuRespDTO.java | 5 +-- .../admin/sku/vo/ProductSkuBaseVO.java | 4 +- .../dal/dataobject/sku/ProductSkuDO.java | 4 +- .../spu/ProductSpuServiceImplTest.java | 8 ++-- .../combination/CombinationActivityApi.java | 20 +++++++++ .../api/combination/CombinationApi.java | 21 --------- .../api/combination/CombinationRecordApi.java | 25 +---------- .../CombinationActivityUpdateStockReqDTO.java | 42 ------------------ .../dto/CombinationRecordCreateReqDTO.java | 29 +++++++++---- .../api/seckill/SeckillActivityApi.java | 8 ++-- .../dto/SeckillActivityUpdateStockReqDTO.java | 42 ------------------ ...l.java => CombinationActivityApiImpl.java} | 9 ++-- .../combination/CombinationRecordApiImpl.java | 13 ------ .../api/seckill/SeckillActivityApiImpl.java | 5 +-- .../CombinationActivityConvert.java | 15 +++++++ .../mysql/bargain/BargainActivityMapper.java | 2 +- .../seckillactivity/SeckillProductMapper.java | 2 +- .../CombinationActivityService.java | 10 +++-- .../CombinationActivityServiceImpl.java | 43 +++++++++---------- .../combination/CombinationRecordService.java | 10 ----- .../CombinationRecordServiceImpl.java | 29 ++----------- .../seckill/SeckillActivityService.java | 7 +-- .../seckill/SeckillActivityServiceImpl.java | 17 ++++---- .../convert/order/TradeOrderConvert.java | 10 +---- .../order/TradeOrderUpdateServiceImpl.java | 5 ++- .../order/bo/TradeBeforeOrderCreateReqBO.java | 28 ++++-------- .../order/handler/TradeBargainHandler.java | 4 +- .../handler/TradeCombinationHandler.java | 8 ++-- .../order/handler/TradeOrderHandler.java | 4 +- .../order/handler/TradeSeckillHandler.java | 5 +-- 30 files changed, 145 insertions(+), 289 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApi.java delete mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java delete mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationActivityUpdateStockReqDTO.java delete mode 100644 yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/{CombinationApiImpl.java => CombinationActivityApiImpl.java} (52%) diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java index 03641012f..338c4dd85 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java @@ -59,14 +59,13 @@ public class ProductSkuRespDTO { * 商品体积,单位:m^3 平米 */ private Double volume; - // TODO @puhui999:firstBrokeragePrice ;尴尬,我当时打错了;secondBrokeragePrice /** * 一级分销的佣金,单位:分 */ - private Integer firstBrokerageRecord; + private Integer firstBrokeragePrice; /** * 二级分销的佣金,单位:分 */ - private Integer secondBrokerageRecord; + private Integer secondBrokeragePrice; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java index f3eee6123..8f47e9392 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java @@ -51,10 +51,10 @@ public class ProductSkuBaseVO { private Double volume; @Schema(description = "一级分销的佣金,单位:分", example = "199") - private Integer firstBrokerageRecord; + private Integer firstBrokeragePrice; @Schema(description = "二级分销的佣金,单位:分", example = "19") - private Integer secondBrokerageRecord; + private Integer secondBrokeragePrice; @Schema(description = "属性数组") private List properties; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java index e164915dd..dacb02ec8 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java @@ -81,11 +81,11 @@ public class ProductSkuDO extends BaseDO { /** * 一级分销的佣金,单位:分 */ - private Integer firstBrokerageRecord; + private Integer firstBrokeragePrice; /** * 二级分销的佣金,单位:分 */ - private Integer secondBrokerageRecord; + private Integer secondBrokeragePrice; // ========== 营销相关字段 ========= diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java index b505ad161..dcda35550 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java @@ -92,8 +92,8 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { o.setMarketPrice(generaInt()); o.setStock(generaInt()); o.setWarnStock(10); - o.setFirstBrokerageRecord(generaInt()); - o.setSecondBrokerageRecord(generaInt()); + o.setFirstBrokeragePrice(generaInt()); + o.setSecondBrokeragePrice(generaInt()); // 限制分数为两位数 o.setWeight(RandomUtil.randomDouble(10,2, RoundingMode.HALF_UP)); o.setVolume(RandomUtil.randomDouble(10,2, RoundingMode.HALF_UP)); @@ -143,8 +143,8 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { o.setMarketPrice(generaInt()); o.setStock(generaInt()); o.setWarnStock(10); - o.setFirstBrokerageRecord(generaInt()); - o.setSecondBrokerageRecord(generaInt()); + o.setFirstBrokeragePrice(generaInt()); + o.setSecondBrokeragePrice(generaInt()); // 限制分数为两位数 o.setWeight(RandomUtil.randomDouble(10,2, RoundingMode.HALF_UP)); o.setVolume(RandomUtil.randomDouble(10,2, RoundingMode.HALF_UP)); diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApi.java new file mode 100644 index 000000000..ad78aaa0d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApi.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.promotion.api.combination; + +/** + * 拼团活动 Api 接口 + * + * @author HUIHUI + */ +public interface CombinationActivityApi { + + /** + * 校验是否满足拼团条件 + * + * @param activityId 活动编号 + * @param userId 用户编号 + * @param skuId sku 编号 + * @param count 数量 + */ + void validateCombination(Long activityId, Long userId, Long skuId, Integer count); + +} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java deleted file mode 100644 index 11ea1c4f3..000000000 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApi.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.promotion.api.combination; - -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationActivityUpdateStockReqDTO; - -// TODO @puhui999:是不是改成 CombinationActivityApi -/** - * 拼团活动 Api 接口 - * - * @author HUIHUI - */ -public interface CombinationApi { - - /** - * 更新活动库存 - * - * @param reqDTO 请求 - */ - // TODO @puhui999:应该是更新哇?还是校验哈; - void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO); - -} 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 859eb5c7e..5f9b5fba8 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,9 @@ 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 javax.validation.Valid; import java.time.LocalDateTime; -import java.util.List; // TODO @芋艿:后面也再撸撸这几个接口 @@ -33,26 +31,7 @@ public interface CombinationRecordApi { boolean isCombinationRecordSuccess(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); - - /** - * 更新拼团状态为成功 + * 更新拼团状态为 成功 * * @param userId 用户编号 * @param orderId 订单编号 @@ -60,7 +39,7 @@ public interface CombinationRecordApi { void updateRecordStatusToSuccess(Long userId, Long orderId); /** - * 更新拼团状态为失败 + * 更新拼团状态为 失败 * * @param userId 用户编号 * @param orderId 订单编号 diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationActivityUpdateStockReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationActivityUpdateStockReqDTO.java deleted file mode 100644 index 078f22fb0..000000000 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationActivityUpdateStockReqDTO.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.promotion.api.combination.dto; - -import lombok.Data; - -import javax.validation.Valid; -import javax.validation.constraints.NotNull; - -/** - * 拼团活动更新活动库存 Request DTO - * - * @author HUIHUI - */ -@Data -public class CombinationActivityUpdateStockReqDTO { - - // TODO @puhui999:是不是一个 activityId、count、skuId 参数就完事啦。 - - @NotNull(message = "活动编号不能为空") - private Long activityId; - - @NotNull(message = "购买数量不能为空") - private Integer count; - - @NotNull(message = "活动商品不能为空") - private Item item; - - @Data - @Valid - public static class Item { - - @NotNull(message = "SPU 编号不能为空") - private Long spuId; - - @NotNull(message = "SKU 编号活动商品不能为空") - private Long skuId; - - @NotNull(message = "购买数量不能为空") - private Integer count; - - } - -} diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java index 21e6d4965..34d667fe3 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/dto/CombinationRecordCreateReqDTO.java @@ -13,26 +13,39 @@ import javax.validation.constraints.NotNull; @Data public class CombinationRecordCreateReqDTO { - // TODO @puhui999:注释还是要的哈 - + /** + * 拼团活动编号 + */ @NotNull(message = "拼团活动编号不能为空") private Long activityId; - + /** + * spu 编号 + */ @NotNull(message = "spu 编号不能为空") private Long spuId; - + /** + * sku 编号 + */ @NotNull(message = "sku 编号不能为空") private Long skuId; - + /** + * 订单编号 + */ @NotNull(message = "订单编号不能为空") private Long orderId; - + /** + * 用户编号 + */ @NotNull(message = "用户编号不能为空") private Long userId; - + /** + * 团长编号 + */ @NotNull(message = "团长编号不能为空") private Long headId; - + /** + * 拼团商品单价 + */ @NotNull(message = "拼团商品单价不能为空") private Integer combinationPrice; diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java index 9c5cf1d35..1e5d50621 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java @@ -1,7 +1,5 @@ package cn.iocoder.yudao.module.promotion.api.seckill; -import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateStockReqDTO; - /** * 秒杀活动 API 接口 * @@ -12,8 +10,10 @@ public interface SeckillActivityApi { /** * 更新秒杀库存 * - * @param updateStockReqDTO 请求 + * @param activityId 活动编号 + * @param skuId sku 编号 + * @param count 数量 */ - void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO); + void updateSeckillStock(Long activityId, Long skuId, Integer count); } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java deleted file mode 100644 index fa274744d..000000000 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/dto/SeckillActivityUpdateStockReqDTO.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.promotion.api.seckill.dto; - -import lombok.Data; - -import javax.validation.Valid; -import javax.validation.constraints.NotNull; - -/** - * 更新秒杀库存 request DTO - * - * @author HUIHUI - */ -@Data -public class SeckillActivityUpdateStockReqDTO { - - // TODO @puhui999:可以不用 dto,直接 activityId、skuId、count 即可 - - @NotNull(message = "活动编号不能为空") - private Long activityId; - - @NotNull(message = "购买数量不能为空") - private Integer count; - - @NotNull(message = "活动商品不能为空") - private Item item; - - @Data - @Valid - public static class Item { - - @NotNull(message = "SPU 编号不能为空") - private Long spuId; - - @NotNull(message = "SKU 编号活动商品不能为空") - private Long skuId; - - @NotNull(message = "购买数量不能为空") - private Integer count; - - } - -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApiImpl.java similarity index 52% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApiImpl.java index 767b2e680..14eb9dd41 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationActivityApiImpl.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.promotion.api.combination; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; +import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -10,14 +10,15 @@ import javax.annotation.Resource; * * @author HUIHUI */ -public class CombinationApiImpl implements CombinationApi { +@Service +public class CombinationActivityApiImpl implements CombinationActivityApi { @Resource private CombinationActivityService activityService; @Override - public void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO) { - activityService.validateCombination(reqDTO); + public void validateCombination(Long activityId, Long userId, Long skuId, Integer count) { + activityService.validateCombination(activityId, userId, skuId, count); } } 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 7f7ec6170..24d42482a 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,15 +1,12 @@ 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.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.time.LocalDateTime; -import java.util.List; /** * 拼团活动 API 实现类 @@ -32,16 +29,6 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { 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 updateRecordStatusToSuccess(Long userId, Long orderId) { recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.SUCCESS.getStatus(), userId, orderId); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java index f8840415a..624af86c6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.promotion.api.seckill; -import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService; import org.springframework.stereotype.Service; @@ -18,8 +17,8 @@ public class SeckillActivityApiImpl implements SeckillActivityApi { private SeckillActivityService activityService; @Override - public void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO) { - activityService.updateSeckillStock(updateStockReqDTO); + public void updateSeckillStock(Long activityId, Long skuId, Integer count) { + activityService.updateSeckillStock(activityId, skuId, count); } } 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 21943de17..a6e086cc2 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 @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.promotion.convert.combination; 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.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; 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; @@ -92,6 +94,19 @@ public interface CombinationActivityConvert { CombinationRecordDO convert(CombinationRecordCreateReqDTO reqDTO); + default CombinationRecordDO convert1(CombinationRecordCreateReqDTO reqDTO, CombinationActivityDO activity, MemberUserRespDTO user, + ProductSpuRespDTO spu, ProductSkuRespDTO sku) { + CombinationRecordDO record = convert(reqDTO); + record.setVirtualGroup(false); + record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration())); + record.setUserSize(activity.getUserSize()); + record.setNickname(user.getNickname()); + record.setAvatar(user.getAvatar()); + record.setSpuName(spu.getName()); + record.setPicUrl(sku.getPicUrl()); + return record; + } + List convert(List bean); } 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 94d46d1eb..ae88ab2bd 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 @@ -39,7 +39,7 @@ public interface BargainActivityMapper extends BaseMapperX { default int updateActivityStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(BargainActivityDO::getId, id) - .gt(BargainActivityDO::getStock, 0) // TODO @puhui999:不是 > 0,是要大于 count 哈 + .gt(BargainActivityDO::getStock, count) .setSql("stock = stock - " + count)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index 13e2c1e2f..5ca2dae24 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java @@ -34,7 +34,7 @@ public interface SeckillProductMapper extends BaseMapperX { default int updateActivityStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(SeckillProductDO::getId, id) - .gt(SeckillProductDO::getStock, 0) // TODO @puhui999:不是 > 0,是要大于 count 哈 + .gt(SeckillProductDO::getStock, count) .setSql("stock = stock - " + count)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index c3ee01fcc..c3e0f5313 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationActivityUpdateStockReqDTO; 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; @@ -74,10 +73,13 @@ public interface CombinationActivityService { List getCombinationProductsByActivityIds(Collection activityIds); /** - * 更新拼图活动库存 + * 校验是否满足拼团条件 * - * @param reqDTO 请求 + * @param activityId 活动编号 + * @param userId 用户编号 + * @param skuId sku 编号 + * @param count 数量 */ - void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO); + void validateCombination(Long activityId, Long userId, Long skuId, Integer count); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 1471353e8..d6faf82ae 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -9,7 +9,6 @@ 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.CombinationActivityUpdateStockReqDTO; 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; @@ -33,7 +32,6 @@ import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; 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.*; @@ -85,7 +83,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic /** * 校验拼团商品参与的活动是否存在冲突 * - * @param spuId 商品 SPU 编号 + * @param spuId 商品 SPU 编号 * @param activityId 拼团活动编号 */ private void validateProductConflict(Long spuId, Long activityId) { @@ -104,7 +102,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic /** * 校验拼团商品是否都存在 * - * @param spuId 商品 SPU 编号 + * @param spuId 商品 SPU 编号 * @param products 拼团商品 */ private void validateProductExists(Long spuId, List products) { @@ -149,7 +147,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic * 更新拼团商品 * * @param activity 拼团活动 - * @param products 该活动的最新商品配置 + * @param products 该活动的最新商品配置 */ private void updateCombinationProduct(CombinationActivityDO activity, List products) { // 第一步,对比新老数据,获得添加、修改、删除的列表 @@ -214,35 +212,34 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic } @Override - public void validateCombination(CombinationActivityUpdateStockReqDTO reqDTO) { + public void validateCombination(Long activityId, Long userId, Long skuId, Integer count) { // 1.1 校验拼团活动是否存在 - CombinationActivityDO activity = validateCombinationActivityExists(reqDTO.getActivityId()); + CombinationActivityDO activity = validateCombinationActivityExists(activityId); // 1.2 校验活动是否开启 if (ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { throw exception(COMBINATION_ACTIVITY_STATUS_DISABLE); } // 1.3 校验是否超出单次限购数量 - if (activity.getSingleLimitCount() < reqDTO.getCount()) { + if (activity.getSingleLimitCount() < count) { throw exception(COMBINATION_RECORD_FAILED_SINGLE_LIMIT_COUNT_EXCEED); } // 2. 校验是否超出总限购数量 - // TODO @puhui999:userId 应该接口传递哈;要保证 service 无状态 - List recordList = combinationRecordService.getRecordListByUserIdAndActivityId( - getLoginUserId(), reqDTO.getActivityId()); - // TODO @puhui999:最好 if true return;减少括号层数 - if (CollUtil.isNotEmpty(recordList)) { - // 过滤出拼团成功的 - // TODO @puhui999:count 要不存一个在 record 里? - List skuIds = convertList(recordList, CombinationRecordDO::getSkuId, - item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())); - Integer countSum = tradeOrderApi.getOrderItemCountSumByOrderIdAndSkuId(convertList(recordList, - CombinationRecordDO::getOrderId, - item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds); - if (activity.getTotalLimitCount() < countSum) { - throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); - } + List recordList = combinationRecordService.getRecordListByUserIdAndActivityId(userId, activityId); + if (CollUtil.isEmpty(recordList)) { + return; } + // 过滤出拼团成功的 + // TODO @puhui999:count 要不存一个在 record 里? + List skuIds = convertList(recordList, CombinationRecordDO::getSkuId, + item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())); + Integer countSum = tradeOrderApi.getOrderItemCountSumByOrderIdAndSkuId(convertList(recordList, + CombinationRecordDO::getOrderId, + item -> ObjectUtil.equals(item.getStatus(), CombinationRecordStatusEnum.SUCCESS.getStatus())), skuIds); + if (activity.getTotalLimitCount() < countSum) { + throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); + } + } } 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 fbc51c6b9..e75440edd 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 @@ -57,14 +57,4 @@ public interface CombinationRecordService { */ 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/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 556e47363..70cbe90e8 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 @@ -128,19 +128,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } // 2. 创建拼团记录 - // TODO @puhui999:可以把 user、spu、sku 一起放 convert 里哈; - CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO); - record.setVirtualGroup(false); - record.setExpireTime(record.getStartTime().plusHours(activity.getLimitDuration())); - record.setUserSize(activity.getUserSize()); MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); - record.setNickname(user.getNickname()); - record.setAvatar(user.getAvatar()); - ProductSpuRespDTO spu = productSpuApi.getSpu(record.getSpuId()); - record.setSpuName(spu.getName()); - ProductSkuRespDTO sku = productSkuApi.getSku(record.getSkuId()); - record.setPicUrl(sku.getPicUrl()); - recordMapper.insert(record); + ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); + ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); + recordMapper.insert(CombinationActivityConvert.INSTANCE.convert1(reqDTO, activity, user, spu, sku)); } @Override @@ -153,20 +144,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { 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/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index 89fa6fb84..6ed4f3f87 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.seckill; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; @@ -37,9 +36,11 @@ public interface SeckillActivityService { /** * 更新秒杀库存 * - * @param updateStockReqDTO 更新信息 + * @param activityId 活动编号 + * @param skuId sku 编号 + * @param count 数量 */ - void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO); + void updateSeckillStock(Long activityId, Long skuId, Integer count); /** * 关闭秒杀活动 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index da098914c..43f595dbf 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -7,7 +7,6 @@ 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.seckill.dto.SeckillActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO; @@ -147,32 +146,32 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override @Transactional(rollbackFor = Exception.class) - public void updateSeckillStock(SeckillActivityUpdateStockReqDTO updateStockReqDTO) { + public void updateSeckillStock(Long activityId, Long skuId, Integer count) { // 1、校验秒杀活动是否存在 - SeckillActivityDO seckillActivity = getSeckillActivity(updateStockReqDTO.getActivityId()); + SeckillActivityDO seckillActivity = getSeckillActivity(activityId); // 1.1、校验库存是否充足 - if (seckillActivity.getTotalStock() < updateStockReqDTO.getCount()) { + if (seckillActivity.getTotalStock() < count) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } // 2、获取活动商品 - List products = getSeckillProductListByActivityId(updateStockReqDTO.getActivityId()); + List products = getSeckillProductListByActivityId(activityId); // 2.1、过滤出购买的商品 - SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(updateStockReqDTO.getItem().getSkuId(), item.getSkuId())); + SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(skuId, item.getSkuId())); // 2.2、检查活动商品库存是否充足 - boolean isSufficient = product == null || (product.getStock() == 0 || (product.getStock() < updateStockReqDTO.getItem().getCount()) || (product.getStock() - updateStockReqDTO.getItem().getCount()) < 0); + boolean isSufficient = product == null || (product.getStock() == 0 || (product.getStock() < count) || (product.getStock() - count) < 0); if (isSufficient) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } // 3、更新活动商品库存 - int updateCount = seckillProductMapper.updateActivityStock(product.getId(), updateStockReqDTO.getItem().getCount()); + int updateCount = seckillProductMapper.updateActivityStock(product.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } // 4、更新活动库存 - updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), updateStockReqDTO.getCount()); + updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index b31aaa007..08fa629c2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -14,9 +14,7 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; -import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; -import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; @@ -280,15 +278,9 @@ public interface TradeOrderConvert { return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId()) .setBasePrice(item.getPayPrice() * item.getCount()) .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:标题类似:木晴冰雪成功购买云时代的JVM原理与实战;茫农成功购买深入拆解消息队列47讲 - .setFirstFixedPrice(sku.getFirstBrokerageRecord()).setSecondFixedPrice(sku.getSecondBrokerageRecord()); + .setFirstFixedPrice(sku.getFirstBrokeragePrice()).setSecondFixedPrice(sku.getSecondBrokeragePrice()); } - @Mapping(target = "activityId", source = "reqBO.seckillActivityId") - SeckillActivityUpdateStockReqDTO convert(TradeBeforeOrderCreateReqBO reqBO); - - @Mapping(target = "activityId", source = "reqBO.combinationActivityId") - CombinationActivityUpdateStockReqDTO convert1(TradeBeforeOrderCreateReqBO reqBO); - TradeBeforeOrderCreateReqBO convert(AppTradeOrderCreateReqVO createReqVO); @Mappings({ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 9a2b34a93..621cc4d04 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -180,9 +180,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Transactional(rollbackFor = Exception.class) public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { // 1、执行订单创建前置处理器 - // TODO @puhui999:最好也抽个 beforeOrderCreate 方法; + // TODO @puhui999:最好也抽个 beforeOrderCreate 方法;不要 BO 各自处理参数岂不美哉? TradeBeforeOrderCreateReqBO beforeOrderCreateReqBO = TradeOrderConvert.INSTANCE.convert(createReqVO); beforeOrderCreateReqBO.setOrderType(validateActivity(createReqVO)); + beforeOrderCreateReqBO.setUserId(userId); beforeOrderCreateReqBO.setCount(getSumValue(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCount, Integer::sum)); // TODO @puhui999:这里有个纠结点;handler 的定义是只处理指定类型的订单的拓展逻辑;还是通用的 handler,类似可以处理优惠劵等等 tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(beforeOrderCreateReqBO)); @@ -726,7 +727,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来 - tradeOrderHandlers.forEach(handler -> handler.rollbackStock()); + tradeOrderHandlers.forEach(handler -> handler.rollback()); // 2.回滚库存 List orderItems = tradeOrderItemMapper.selectListByOrderId(id); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java index e78c4a460..d4e421880 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeBeforeOrderCreateReqBO.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.service.order.bo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import javax.validation.Valid; import javax.validation.constraints.NotNull; // TODO 芋艿:在想想这些参数的定义 @@ -34,25 +33,16 @@ public class TradeBeforeOrderCreateReqBO { @Schema(description = "砍价活动编号", example = "123") private Long bargainActivityId; + @NotNull(message = "SPU 编号不能为空") + private Long spuId; + + @NotNull(message = "SKU 编号活动商品不能为空") + private Long skuId; + + @NotNull(message = "用户编号不能为空") + private Long userId; + @NotNull(message = "购买数量不能为空") private Integer count; - @NotNull(message = "活动商品不能为空") - private Item item; - - @Data - @Valid - public static class Item { - - @NotNull(message = "SPU 编号不能为空") - private Long spuId; - - @NotNull(message = "SKU 编号活动商品不能为空") - private Long skuId; - - @NotNull(message = "购买数量不能为空") - private Integer count; - - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java index fc410963a..72def213d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java @@ -22,7 +22,7 @@ public class TradeBargainHandler implements TradeOrderHandler { @Override public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { - // 如果是秒杀订单 + // 如果是砍价订单 if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), reqBO.getOrderType())) { return; } @@ -37,7 +37,7 @@ public class TradeBargainHandler implements TradeOrderHandler { } @Override - public void rollbackStock() { + public void rollback() { } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index f9fce744b..ad777b380 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.trade.service.order.handler; import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.module.promotion.api.combination.CombinationApi; +import cn.iocoder.yudao.module.promotion.api.combination.CombinationActivityApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; @@ -20,7 +20,7 @@ import javax.annotation.Resource; public class TradeCombinationHandler implements TradeOrderHandler { @Resource - private CombinationApi combinationApi; + private CombinationActivityApi combinationActivityApi; @Resource private CombinationRecordApi combinationRecordApi; @@ -32,7 +32,7 @@ public class TradeCombinationHandler implements TradeOrderHandler { } // 校验是否满足拼团活动相关限制 - combinationApi.validateCombination(TradeOrderConvert.INSTANCE.convert1(reqBO)); + combinationActivityApi.validateCombination(reqBO.getCombinationActivityId(), reqBO.getUserId(), reqBO.getSkuId(), reqBO.getCount()); } @Override @@ -42,7 +42,7 @@ public class TradeCombinationHandler implements TradeOrderHandler { } @Override - public void rollbackStock() { + public void rollback() { } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index 37dda82ce..b747e35d4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -25,8 +25,8 @@ public interface TradeOrderHandler { void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO); /** - * 回滚活动相关库存 + * 回滚 */ - void rollbackStock(); + void rollback(); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java index 0774543a5..ce1dfdb05 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; -import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; @@ -28,7 +27,7 @@ public class TradeSeckillHandler implements TradeOrderHandler { return; } - seckillActivityApi.updateSeckillStock(TradeOrderConvert.INSTANCE.convert(reqBO)); + seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount()); } @Override @@ -37,7 +36,7 @@ public class TradeSeckillHandler implements TradeOrderHandler { } @Override - public void rollbackStock() { + public void rollback() { }