|
5 | 5 | import io.seata.core.context.RootContext; |
6 | 6 | import io.seata.spring.annotation.GlobalTransactional; |
7 | 7 | import lombok.extern.slf4j.Slf4j; |
| 8 | +import org.jeecg.common.api.vo.Result; |
| 9 | +import org.jeecg.common.exception.JeecgBootBizTipException; |
| 10 | +import org.jeecg.common.util.oConvertUtils; |
8 | 11 | import org.jeecg.modules.test.seata.order.dto.PlaceOrderRequest; |
9 | 12 | import org.jeecg.modules.test.seata.order.entity.SeataOrder; |
10 | 13 | import org.jeecg.modules.test.seata.order.enums.OrderStatus; |
@@ -59,13 +62,20 @@ public void placeOrder(PlaceOrderRequest request) { |
59 | 62 | orderMapper.insert(order); |
60 | 63 | log.info("订单一阶段生成,等待扣库存付款中"); |
61 | 64 | // 扣减库存并计算总价 |
62 | | - BigDecimal amount = productClient.reduceStock(productId, count); |
| 65 | + Result<BigDecimal> productRes = productClient.reduceStock(productId, count); |
| 66 | + if (!productRes.isSuccess()) { |
| 67 | + String message = productRes.getMessage(); |
| 68 | + message = oConvertUtils.isEmpty(message) ? "操作失败" : message; |
| 69 | + throw new JeecgBootBizTipException(message); |
| 70 | + } |
| 71 | + BigDecimal amount = productRes.getResult(); |
63 | 72 | // 扣减余额 |
64 | | - String str = accountClient.reduceBalance(userId, amount); |
| 73 | + Result<?> accountRes = accountClient.reduceBalance(userId, amount); |
65 | 74 | // feign响应被二次封装,判断使主事务回滚 |
66 | | - JSONObject jsonObject = JSONObject.parseObject(str); |
67 | | - if (jsonObject.getInteger("code") != 200) { |
68 | | - throw new RuntimeException(); |
| 75 | + if (!accountRes.isSuccess()) { |
| 76 | + String message = accountRes.getMessage(); |
| 77 | + message = oConvertUtils.isEmpty(message) ? "操作失败" : message; |
| 78 | + throw new JeecgBootBizTipException(message); |
69 | 79 | } |
70 | 80 |
|
71 | 81 | order.setStatus(OrderStatus.SUCCESS); |
|
0 commit comments