事务执行消息推送
This commit is contained in:
@@ -55,6 +55,8 @@ import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -1026,13 +1028,29 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
shopTableService.updateById(table);
|
||||
}
|
||||
}
|
||||
orderDetailService.updateChain().set(OrderDetail::getStatus, OrderStatusEnums.DONE.getCode()).eq(OrderDetail::getOrderId, orderInfo.getId()).update();
|
||||
// if (!"after-pay".equals(orderInfo.getPayMode())) {
|
||||
//发送打票信息
|
||||
// 保存消息参数(避免闭包中引用的变量被修改)
|
||||
final Long orderId = orderInfo.getId();
|
||||
final boolean isPrint = orderInfo.getIsPrint() == 1;
|
||||
final String payMode = orderInfo.getPayMode();
|
||||
|
||||
// 【关键改造】注册事务同步器,在事务提交后发送消息
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
// 事务成功提交后执行消息发送
|
||||
String printParam = orderId + "_" + (!"after-pay".equals(payMode) ? 1 : 0) + "_1";
|
||||
rabbitPublisher.sendOrderPrintMsg(printParam, isPrint);
|
||||
// log.info("订单{}事务提交后,发送打印消息", orderId);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 非事务环境下直接发送(兼容无事务场景)
|
||||
String printParam = orderId + "_" + (!"after-pay".equals(payMode) ? 1 : 0) + "_1";
|
||||
rabbitPublisher.sendOrderPrintMsg(printParam, isPrint);
|
||||
// log.info("非事务环境下,直接发送订单{}打印消息", orderId);
|
||||
}
|
||||
|
||||
//orderId_0_0 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_1", orderInfo.getIsPrint() == 1);
|
||||
// }
|
||||
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user