refactor: seata实验室逻辑优化

This commit is contained in:
haoxr 2022-11-30 01:05:00 +08:00
parent 8bc5ed4877
commit 2677bfa34a
3 changed files with 3 additions and 46 deletions

View File

@ -36,49 +36,6 @@ public class SeataServiceImpl implements SeataService {
private static Long memberId = 1l; // 会员ID
private static Long orderId = 1l; // 订单ID
/**
* 模拟订单支付
*
* @return
*/
@Override
public boolean payOrder(SeataForm seataForm) {
log.info("========扣减商品库存========");
skuFeignClient.deductStock(skuId, 1); // 扣减库存
log.info("========扣减账户余额========");
memberFeignClient.deductBalance(memberId, 1000 * 100l); // 扣款1000
log.info("========修改订单状态========");
orderFeignClient.updateOrderStatus(orderId, 201, seataForm.isOrderEx()); // 已支付
return true;
}
/**
* 模拟订单支付(分布式事务)
*
* @param seataForm
* @return
*/
@Override
@GlobalTransactional
public boolean payOrderWithGlobalTx(SeataForm seataForm) {
log.info("========扣减商品库存(Seata)========");
skuFeignClient.deductStock(skuId, 1); // 扣减库存
log.info("========修改订单状态(Seata)========");
orderFeignClient.createOrder(orderId, 201, seataForm.isOrderEx()); // 已支付
log.info("========修改订单状态(Seata)========");
orderFeignClient.updateOrderStatus(orderId, 201, seataForm.isOrderEx()); // 已支付
log.info("========扣减账户余额(Seata)========");
memberFeignClient.deductBalance(memberId, 1000 * 100l); // 扣款1000
return true;
}
/**
* 获取模拟数据
*
@ -115,7 +72,6 @@ public class SeataServiceImpl implements SeataService {
@Override
public boolean resetData() {
skuFeignClient.updateStock(skuId, 999); // 还原库存
memberFeignClient.updateBalance(memberId, 10000000 * 100); // 还原余额
orderFeignClient.updateOrderStatus(orderId, 101, false); // 待支付
return true;

View File

@ -44,5 +44,5 @@ public interface OrderFeignClient {
* @return
*/
@PostMapping("/api/v1/orders")
Result<String> createOrder(SeataOrderDTO orderDTO, boolean openEx);
Result<String> createOrder(@RequestBody SeataOrderDTO orderDTO, @RequestParam boolean openEx);
}

View File

@ -23,8 +23,9 @@ import java.util.List;
import java.util.Optional;
/**
* 订单控制层
*
* @author huawei
* @email huawei_code@163.com
* @date 2020/12/30
*/
@Api(tags = "「管理端」订单管理")