支付事务手动提交测试
This commit is contained in:
@@ -1302,7 +1302,7 @@ public class OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (orderInfo.getOrderType().equals("return")) {
|
if (orderInfo.getOrderType() != null && orderInfo.getOrderType().equals("return")) {
|
||||||
List<SkuInfoPo> skuInfoPos = tbOrderInfoMapper.selectSkuByOrderIdAndType(orderInfo.getId().toString());
|
List<SkuInfoPo> skuInfoPos = tbOrderInfoMapper.selectSkuByOrderIdAndType(orderInfo.getId().toString());
|
||||||
if (Objects.isNull(skuInfoPos) || skuInfoPos.size() < 0) {
|
if (Objects.isNull(skuInfoPos) || skuInfoPos.size() < 0) {
|
||||||
skuInfoPos = new ArrayList<>();
|
skuInfoPos = new ArrayList<>();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.service;
|
package com.chaozhanggui.system.cashierservice.service;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
@@ -37,7 +38,13 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
|
import org.springframework.transaction.TransactionStatus;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||||
|
import org.springframework.transaction.support.TransactionCallback;
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -120,9 +127,14 @@ public class PayService {
|
|||||||
private MPOrderDetailMapper mPOrderDetailMapper;
|
private MPOrderDetailMapper mPOrderDetailMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RabbitMsgUtils rabbitMsgUtils;
|
private RabbitMsgUtils rabbitMsgUtils;
|
||||||
|
@Autowired
|
||||||
|
private TransactionTemplate transactionTemplate;
|
||||||
|
|
||||||
public PayService(RedisTemplate<String, Object> redisTemplate) {
|
private final Utils utils;
|
||||||
|
|
||||||
|
public PayService(RedisTemplate<String, Object> redisTemplate, Utils utils) {
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
|
this.utils = utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -568,7 +580,6 @@ public class PayService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||||
if (ObjectUtil.isEmpty(orderInfo)) {
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||||
return Result.fail(CodeEnum.ORDERNOEXIST);
|
return Result.fail(CodeEnum.ORDERNOEXIST);
|
||||||
@@ -672,13 +683,14 @@ public class PayService {
|
|||||||
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
log.info("更新购物车:{}", cartCount);
|
log.info("更新购物车:{}", cartCount);
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("token", token);
|
jsonObject.put("token", token);
|
||||||
jsonObject.put("type", "create");
|
jsonObject.put("type", "create");
|
||||||
jsonObject.put("orderId", orderId);
|
jsonObject.put("orderId", orderId);
|
||||||
|
|
||||||
producer.putOrderCollect(jsonObject.toJSONString());
|
producer.putOrderCollect(jsonObject.toJSONString());
|
||||||
|
|
||||||
// 打印消息
|
// 打印消息
|
||||||
@@ -1007,6 +1019,13 @@ public class PayService {
|
|||||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
|
||||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||||
|
ThreadUtil.sleep(10);
|
||||||
|
// 提交当前事务
|
||||||
|
transactionTemplate.execute((TransactionCallback<Void>) status -> {
|
||||||
|
status.flush(); // 提交
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
//更新购物车状态
|
//更新购物车状态
|
||||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user