支付事务手动提交测试
This commit is contained in:
@@ -972,7 +972,6 @@ public class PayService {
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result cashPay(String orderId, String token, BigDecimal payAmount, BigDecimal discountAmount) {
|
||||
if (ObjectUtil.isEmpty(orderId)) {
|
||||
return Result.fail(CodeEnum.PARAM);
|
||||
@@ -1013,49 +1012,39 @@ public class PayService {
|
||||
return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||
}
|
||||
|
||||
utils.runFunAndTransactional(() -> {
|
||||
orderInfo.setPayAmount(ObjectUtil.isEmpty(payAmount) ? orderInfo.getOrderAmount() : payAmount);
|
||||
orderInfo.setDiscountAmount(ObjectUtil.isEmpty(discountAmount) ? null : discountAmount);
|
||||
orderInfo.setStaffId(ObjectUtil.isEmpty(staff) ? null : staff.getId());
|
||||
orderInfo.setDiscountRatio(ObjectUtil.isNotEmpty(payAmount) ? payAmount.divide(orderInfo.getOrderAmount(), 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_DOWN) : null);
|
||||
orderInfo.setPayType("cash");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
|
||||
orderInfo.setPayAmount(ObjectUtil.isEmpty(payAmount) ? orderInfo.getOrderAmount() : payAmount);
|
||||
orderInfo.setDiscountAmount(ObjectUtil.isEmpty(discountAmount) ? null : discountAmount);
|
||||
orderInfo.setStaffId(ObjectUtil.isEmpty(staff) ? null : staff.getId());
|
||||
orderInfo.setDiscountRatio(ObjectUtil.isNotEmpty(payAmount) ? payAmount.divide(orderInfo.getOrderAmount(), 2, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_DOWN) : null);
|
||||
orderInfo.setPayType("cash");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
// 创建一个新的事务定义
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
TransactionStatus status = transactionManager.getTransaction(def);
|
||||
try {
|
||||
// 提交当前事务
|
||||
transactionManager.commit(status);
|
||||
} catch (Exception e) {
|
||||
transactionManager.rollback(status); // 回滚
|
||||
throw e; // 重新抛出异常
|
||||
}
|
||||
log.info("已经手动提交事务");
|
||||
//更新购物车状态
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
|
||||
|
||||
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.parseInt(orderId), "closed", orderInfo.getDiscountRatio());
|
||||
} else {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.parseInt(orderId), "closed", null);
|
||||
}
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
return orderInfo;
|
||||
});
|
||||
|
||||
log.info("事务已提交");
|
||||
ThreadUtil.sleep(10, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
|
||||
|
||||
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
|
||||
} else {
|
||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
||||
}
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
jsonObject.put("orderId", orderId);
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
|
||||
// 打印消息
|
||||
if (!OrderUseTypeEnum.DINE_IN_AFTER.getValue().equals(orderInfo.getUseType())) {
|
||||
List<TbOrderDetail> detailList = mPOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
@@ -1071,7 +1060,6 @@ public class PayService {
|
||||
mqData.put("type", "pc");
|
||||
producer.sendStockSaleMsg(mqData);
|
||||
|
||||
|
||||
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
|
||||
|
||||
// 小程序购物车缓存
|
||||
|
||||
Reference in New Issue
Block a user