code review:订单部分逻辑

This commit is contained in:
YunaiV 2023-09-12 23:01:12 +08:00
parent e8bdd8349c
commit 9358639c41
3 changed files with 11 additions and 6 deletions

View File

@ -7,7 +7,6 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum; 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.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.AddressApi;
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
@ -90,8 +89,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
private TradeOrderItemMapper tradeOrderItemMapper; private TradeOrderItemMapper tradeOrderItemMapper;
@Resource @Resource
private TradeOrderNoRedisDAO orderNoRedisDAO; private TradeOrderNoRedisDAO orderNoRedisDAO;
@Resource @Resource
private List<TradeOrderHandler> orderHandlers; private List<TradeOrderHandler> tradeOrderHandlers;
@Resource @Resource
private CartService cartService; private CartService cartService;
@ -180,10 +180,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) {
// 1执行订单创建前置处理器 // 1执行订单创建前置处理器
// TODO @puhui999最好也抽个 beforeOrderCreate 方法
TradeBeforeOrderCreateReqBO beforeOrderCreateReqBO = TradeOrderConvert.INSTANCE.convert(createReqVO); TradeBeforeOrderCreateReqBO beforeOrderCreateReqBO = TradeOrderConvert.INSTANCE.convert(createReqVO);
beforeOrderCreateReqBO.setOrderType(validateActivity(createReqVO)); beforeOrderCreateReqBO.setOrderType(validateActivity(createReqVO));
beforeOrderCreateReqBO.setCount(CollectionUtils.getSumValue(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCount, Integer::sum)); beforeOrderCreateReqBO.setCount(getSumValue(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCount, Integer::sum));
orderHandlers.forEach(handler -> handler.beforeOrderCreate(beforeOrderCreateReqBO)); // TODO @puhui999这里有个纠结点handler 的定义是只处理指定类型的订单的拓展逻辑还是通用的 handler类似可以处理优惠劵等等
tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(beforeOrderCreateReqBO));
// 2. 价格计算 // 2. 价格计算
TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO);
@ -282,7 +284,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> orderItems, TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> orderItems,
TradePriceCalculateRespBO calculateRespBO) { 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 芋艿待实现需要前置 // 扣减积分 TODO 芋艿待实现需要前置
// 这个是不是应该放到支付成功之后如果支付后的话可能积分可以重复使用哈资源类都要预扣 // 这个是不是应该放到支付成功之后如果支付后的话可能积分可以重复使用哈资源类都要预扣
@ -723,7 +726,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
} }
// TODO 活动相关库存回滚需要活动 id活动 id 怎么获取app 端能否传过来 // TODO 活动相关库存回滚需要活动 id活动 id 怎么获取app 端能否传过来
orderHandlers.forEach(handler -> handler.rollbackStock()); tradeOrderHandlers.forEach(handler -> handler.rollbackStock());
// 2.回滚库存 // 2.回滚库存
List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id); List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id);

View File

@ -5,6 +5,7 @@ import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
// TODO 芋艿在想想这些参数的定义
/** /**
* 订单创建之后 Request BO * 订单创建之后 Request BO
* *

View File

@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
// TODO 芋艿在想想这些参数的定义
/** /**
* 订单创建之前 Request BO * 订单创建之前 Request BO
* *