From 9358639c417849bf2591c551a8720f42a404a091 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 12 Sep 2023 23:01:12 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderUpdateServiceImpl.java | 15 +++++++++------ .../order/bo/TradeAfterOrderCreateReqBO.java | 1 + .../order/bo/TradeBeforeOrderCreateReqBO.java | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) 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 d8e82c3e3..9a2b34a93 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 @@ -7,7 +7,6 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.TerminalEnum; -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; @@ -90,8 +89,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private TradeOrderItemMapper tradeOrderItemMapper; @Resource private TradeOrderNoRedisDAO orderNoRedisDAO; + @Resource - private List orderHandlers; + private List tradeOrderHandlers; @Resource private CartService cartService; @@ -180,10 +180,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Transactional(rollbackFor = Exception.class) public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { // 1、执行订单创建前置处理器 + // TODO @puhui999:最好也抽个 beforeOrderCreate 方法; TradeBeforeOrderCreateReqBO beforeOrderCreateReqBO = TradeOrderConvert.INSTANCE.convert(createReqVO); beforeOrderCreateReqBO.setOrderType(validateActivity(createReqVO)); - beforeOrderCreateReqBO.setCount(CollectionUtils.getSumValue(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCount, Integer::sum)); - orderHandlers.forEach(handler -> handler.beforeOrderCreate(beforeOrderCreateReqBO)); + beforeOrderCreateReqBO.setCount(getSumValue(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCount, Integer::sum)); + // TODO @puhui999:这里有个纠结点;handler 的定义是只处理指定类型的订单的拓展逻辑;还是通用的 handler,类似可以处理优惠劵等等 + tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(beforeOrderCreateReqBO)); // 2. 价格计算 TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); @@ -282,7 +284,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderDO tradeOrderDO, List orderItems, TradePriceCalculateRespBO calculateRespBO) { // 执行订单创建后置处理器 - orderHandlers.forEach(handler -> handler.afterOrderCreate(TradeOrderConvert.INSTANCE.convert(userId, createReqVO, tradeOrderDO, orderItems.get(0)))); + tradeOrderHandlers.forEach(handler -> handler.afterOrderCreate(TradeOrderConvert.INSTANCE.convert(userId, createReqVO, tradeOrderDO, orderItems.get(0)))); + // 扣减积分 TODO 芋艿:待实现,需要前置; // 这个是不是应该放到支付成功之后?如果支付后的话,可能积分可以重复使用哈。资源类,都要预扣 @@ -723,7 +726,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来 - orderHandlers.forEach(handler -> handler.rollbackStock()); + tradeOrderHandlers.forEach(handler -> handler.rollbackStock()); // 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/TradeAfterOrderCreateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeAfterOrderCreateReqBO.java index 8a33e3eaf..0a96745d9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeAfterOrderCreateReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/TradeAfterOrderCreateReqBO.java @@ -5,6 +5,7 @@ import lombok.Data; import javax.validation.constraints.NotNull; +// TODO 芋艿:在想想这些参数的定义 /** * 订单创建之后 Request BO * 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 e1b7faa35..e78c4a460 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 @@ -6,6 +6,7 @@ import lombok.Data; import javax.validation.Valid; import javax.validation.constraints.NotNull; +// TODO 芋艿:在想想这些参数的定义 /** * 订单创建之前 Request BO *