订单:添加 order handler 默认抽象实现类,子类可以选择性地实现抽象方法,而不必实现所有方法

This commit is contained in:
puhui999 2023-09-30 11:24:52 +08:00
parent bce96b29a6
commit 5ecd0d94eb
5 changed files with 58 additions and 37 deletions

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi;
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;
import org.springframework.stereotype.Component;
@ -15,7 +14,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Component
public class TradeBargainHandler implements TradeOrderHandler {
public class TradeBargainHandler extends TradeOrderDefaultHandler {
@Resource
private BargainActivityApi bargainActivityApi;
@ -34,14 +33,4 @@ public class TradeBargainHandler implements TradeOrderHandler {
bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount());
}
@Override
public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) {
}
@Override
public void rollback() {
}
}

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.hutool.core.util.ObjectUtil;
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;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterPayOrderReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO;
import org.springframework.stereotype.Component;
@ -17,28 +17,25 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Component
public class TradeCombinationHandler implements TradeOrderHandler {
public class TradeCombinationHandler extends TradeOrderDefaultHandler {
@Resource
private CombinationActivityApi combinationActivityApi;
@Resource
private CombinationRecordApi combinationRecordApi;
@Override
public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) {
// 如果是拼团订单
// 如果不是拼团订单则结束
if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), reqBO.getOrderType())) {
return;
}
// 校验是否满足拼团活动相关限制
combinationActivityApi.validateCombination(reqBO.getCombinationActivityId(), reqBO.getUserId(), reqBO.getSkuId(), reqBO.getCount());
combinationRecordApi.validateCombinationRecord(reqBO.getCombinationActivityId(), reqBO.getUserId(), reqBO.getSkuId(), reqBO.getCount());
}
@Override
public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) {
// TODO @puhui999需要判断下
if (true) {
if (reqBO.getCombinationActivityId() == null) {
return;
}
@ -47,8 +44,14 @@ public class TradeCombinationHandler implements TradeOrderHandler {
}
@Override
public void rollback() {
public void afterPayOrder(TradeAfterPayOrderReqBO reqBO) {
// 如果不是拼团订单则结束
if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), reqBO.getOrderType())) {
return;
}
// 更新拼团状态 TODO puhui999订单支付失败或订单支付过期删除这条拼团记录
combinationRecordApi.updateRecordStatusToInProgress(reqBO.getUserId(), reqBO.getOrderId(), reqBO.getPayTime());
}
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterPayOrderReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO;
/**
* 订单活动特殊逻辑处理器 handler 默认抽象实现类
*
* @author HUIHUI
*/
public abstract class TradeOrderDefaultHandler implements TradeOrderHandler {
@Override
public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) {
}
@Override
public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) {
}
@Override
public void afterPayOrder(TradeAfterPayOrderReqBO reqBO) {
}
@Override
public void cancelOrder() {
}
}

View File

@ -1,10 +1,12 @@
package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterPayOrderReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO;
/**
* 订单活动特殊逻辑处理器 handler 接口
* 提供订单生命周期钩子接口订单创建前订单创建后订单支付后订单取消
*
* @author HUIHUI
*/
@ -24,12 +26,16 @@ public interface TradeOrderHandler {
*/
void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO);
// TODO @puhui999这个搞成订单取消
/**
* 回滚
* 支付订单后
*
* @param reqBO 请求
*/
void rollback();
void afterPayOrder(TradeAfterPayOrderReqBO reqBO);
// TODO @puhui999再搞个订单项取消哈
/**
* 订单取消
*/
void cancelOrder();
}

View File

@ -3,7 +3,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.enums.order.TradeOrderTypeEnum;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeAfterOrderCreateReqBO;
import cn.iocoder.yudao.module.trade.service.order.bo.TradeBeforeOrderCreateReqBO;
import org.springframework.stereotype.Component;
@ -15,7 +14,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Component
public class TradeSeckillHandler implements TradeOrderHandler {
public class TradeSeckillHandler extends TradeOrderDefaultHandler {
@Resource
private SeckillActivityApi seckillActivityApi;
@ -34,14 +33,4 @@ public class TradeSeckillHandler implements TradeOrderHandler {
seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount());
}
@Override
public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) {
}
@Override
public void rollback() {
}
}