Commit 5ecd0d94eb47aa7a81575a1b9405210bdda25497
1 parent
bce96b29
订单:添加 order handler 默认抽象实现类,子类可以选择性地实现抽象方法,而不必实现所有方法
Showing
5 changed files
with
58 additions
and
37 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; | ||
| 3 | import cn.hutool.core.util.ObjectUtil; | 3 | import cn.hutool.core.util.ObjectUtil; |
| 4 | import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; | 4 | import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; |
| 5 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; | 5 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; |
| 6 | -import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; | ||
| 7 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; | 6 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; |
| 8 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
| 9 | 8 | ||
| @@ -15,7 +14,7 @@ import javax.annotation.Resource; | @@ -15,7 +14,7 @@ import javax.annotation.Resource; | ||
| 15 | * @author HUIHUI | 14 | * @author HUIHUI |
| 16 | */ | 15 | */ |
| 17 | @Component | 16 | @Component |
| 18 | -public class TradeBargainHandler implements TradeOrderHandler { | 17 | +public class TradeBargainHandler extends TradeOrderDefaultHandler { |
| 19 | 18 | ||
| 20 | @Resource | 19 | @Resource |
| 21 | private BargainActivityApi bargainActivityApi; | 20 | private BargainActivityApi bargainActivityApi; |
| @@ -34,14 +33,4 @@ public class TradeBargainHandler implements TradeOrderHandler { | @@ -34,14 +33,4 @@ public class TradeBargainHandler implements TradeOrderHandler { | ||
| 34 | bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount()); | 33 | bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount()); |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | - @Override | ||
| 38 | - public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) { | ||
| 39 | - | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - @Override | ||
| 43 | - public void rollback() { | ||
| 44 | - | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | } | 36 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java
| 1 | package cn.iocoder.yudao.module.trade.service.order.handler; | 1 | package cn.iocoder.yudao.module.trade.service.order.handler; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.ObjectUtil; | 3 | import cn.hutool.core.util.ObjectUtil; |
| 4 | -import cn.iocoder.yudao.module.promotion.api.combination.CombinationActivityApi; | ||
| 5 | import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; | 4 | import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; |
| 6 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; | 5 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 7 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; | 6 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; |
| 8 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; | 7 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; |
| 8 | +import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterPayOrderReqBO; | ||
| 9 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; | 9 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; |
| 10 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
| 11 | 11 | ||
| @@ -17,28 +17,25 @@ import javax.annotation.Resource; | @@ -17,28 +17,25 @@ import javax.annotation.Resource; | ||
| 17 | * @author HUIHUI | 17 | * @author HUIHUI |
| 18 | */ | 18 | */ |
| 19 | @Component | 19 | @Component |
| 20 | -public class TradeCombinationHandler implements TradeOrderHandler { | 20 | +public class TradeCombinationHandler extends TradeOrderDefaultHandler { |
| 21 | 21 | ||
| 22 | @Resource | 22 | @Resource |
| 23 | - private CombinationActivityApi combinationActivityApi; | ||
| 24 | - @Resource | ||
| 25 | private CombinationRecordApi combinationRecordApi; | 23 | private CombinationRecordApi combinationRecordApi; |
| 26 | 24 | ||
| 27 | @Override | 25 | @Override |
| 28 | public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { | 26 | public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { |
| 29 | - // 如果是拼团订单; | 27 | + // 如果不是拼团订单则结束 |
| 30 | if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), reqBO.getOrderType())) { | 28 | if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), reqBO.getOrderType())) { |
| 31 | return; | 29 | return; |
| 32 | } | 30 | } |
| 33 | 31 | ||
| 34 | // 校验是否满足拼团活动相关限制 | 32 | // 校验是否满足拼团活动相关限制 |
| 35 | - combinationActivityApi.validateCombination(reqBO.getCombinationActivityId(), reqBO.getUserId(), reqBO.getSkuId(), reqBO.getCount()); | 33 | + combinationRecordApi.validateCombinationRecord(reqBO.getCombinationActivityId(), reqBO.getUserId(), reqBO.getSkuId(), reqBO.getCount()); |
| 36 | } | 34 | } |
| 37 | 35 | ||
| 38 | @Override | 36 | @Override |
| 39 | public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) { | 37 | public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) { |
| 40 | - // TODO @puhui999:需要判断下; | ||
| 41 | - if (true) { | 38 | + if (reqBO.getCombinationActivityId() == null) { |
| 42 | return; | 39 | return; |
| 43 | } | 40 | } |
| 44 | 41 | ||
| @@ -47,8 +44,14 @@ public class TradeCombinationHandler implements TradeOrderHandler { | @@ -47,8 +44,14 @@ public class TradeCombinationHandler implements TradeOrderHandler { | ||
| 47 | } | 44 | } |
| 48 | 45 | ||
| 49 | @Override | 46 | @Override |
| 50 | - public void rollback() { | 47 | + public void afterPayOrder(TradeAfterPayOrderReqBO reqBO) { |
| 48 | + // 如果不是拼团订单则结束 | ||
| 49 | + if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), reqBO.getOrderType())) { | ||
| 50 | + return; | ||
| 51 | + } | ||
| 51 | 52 | ||
| 53 | + // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | ||
| 54 | + combinationRecordApi.updateRecordStatusToInProgress(reqBO.getUserId(), reqBO.getOrderId(), reqBO.getPayTime()); | ||
| 52 | } | 55 | } |
| 53 | 56 | ||
| 54 | } | 57 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderDefaultHandler.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.trade.service.order.handler; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; | ||
| 4 | +import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterPayOrderReqBO; | ||
| 5 | +import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 订单活动特殊逻辑处理器 handler 默认抽象实现类 | ||
| 9 | + * | ||
| 10 | + * @author HUIHUI | ||
| 11 | + */ | ||
| 12 | +public abstract class TradeOrderDefaultHandler implements TradeOrderHandler { | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { | ||
| 16 | + | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) { | ||
| 21 | + | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public void afterPayOrder(TradeAfterPayOrderReqBO reqBO) { | ||
| 26 | + | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public void cancelOrder() { | ||
| 31 | + | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | +} |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java
| 1 | package cn.iocoder.yudao.module.trade.service.order.handler; | 1 | package cn.iocoder.yudao.module.trade.service.order.handler; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; | 3 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; |
| 4 | +import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterPayOrderReqBO; | ||
| 4 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; | 5 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; |
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 7 | * 订单活动特殊逻辑处理器 handler 接口 | 8 | * 订单活动特殊逻辑处理器 handler 接口 |
| 9 | + * 提供订单生命周期钩子接口;订单创建前、订单创建后、订单支付后、订单取消 | ||
| 8 | * | 10 | * |
| 9 | * @author HUIHUI | 11 | * @author HUIHUI |
| 10 | */ | 12 | */ |
| @@ -24,12 +26,16 @@ public interface TradeOrderHandler { | @@ -24,12 +26,16 @@ public interface TradeOrderHandler { | ||
| 24 | */ | 26 | */ |
| 25 | void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO); | 27 | void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO); |
| 26 | 28 | ||
| 27 | - // TODO @puhui999:这个搞成订单取消 | ||
| 28 | /** | 29 | /** |
| 29 | - * 回滚 | 30 | + * 支付订单后 |
| 31 | + * | ||
| 32 | + * @param reqBO 请求 | ||
| 30 | */ | 33 | */ |
| 31 | - void rollback(); | 34 | + void afterPayOrder(TradeAfterPayOrderReqBO reqBO); |
| 32 | 35 | ||
| 33 | - // TODO @puhui999:再搞个订单项取消哈 | 36 | + /** |
| 37 | + * 订单取消 | ||
| 38 | + */ | ||
| 39 | + void cancelOrder(); | ||
| 34 | 40 | ||
| 35 | } | 41 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; | ||
| 3 | import cn.hutool.core.util.ObjectUtil; | 3 | import cn.hutool.core.util.ObjectUtil; |
| 4 | import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; | 4 | import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; |
| 5 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; | 5 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; |
| 6 | -import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO; | ||
| 7 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; | 6 | import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO; |
| 8 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
| 9 | 8 | ||
| @@ -15,7 +14,7 @@ import javax.annotation.Resource; | @@ -15,7 +14,7 @@ import javax.annotation.Resource; | ||
| 15 | * @author HUIHUI | 14 | * @author HUIHUI |
| 16 | */ | 15 | */ |
| 17 | @Component | 16 | @Component |
| 18 | -public class TradeSeckillHandler implements TradeOrderHandler { | 17 | +public class TradeSeckillHandler extends TradeOrderDefaultHandler { |
| 19 | 18 | ||
| 20 | @Resource | 19 | @Resource |
| 21 | private SeckillActivityApi seckillActivityApi; | 20 | private SeckillActivityApi seckillActivityApi; |
| @@ -34,14 +33,4 @@ public class TradeSeckillHandler implements TradeOrderHandler { | @@ -34,14 +33,4 @@ public class TradeSeckillHandler implements TradeOrderHandler { | ||
| 34 | seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount()); | 33 | seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount()); |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | - @Override | ||
| 38 | - public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) { | ||
| 39 | - | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - @Override | ||
| 43 | - public void rollback() { | ||
| 44 | - | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | } | 36 | } |