mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 20:54:26 +08:00
refactor: seata实验室逻辑优化
This commit is contained in:
parent
8bc5ed4877
commit
2677bfa34a
@ -36,49 +36,6 @@ public class SeataServiceImpl implements SeataService {
|
|||||||
private static Long memberId = 1l; // 会员ID
|
private static Long memberId = 1l; // 会员ID
|
||||||
private static Long orderId = 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
|
@Override
|
||||||
public boolean resetData() {
|
public boolean resetData() {
|
||||||
skuFeignClient.updateStock(skuId, 999); // 还原库存
|
skuFeignClient.updateStock(skuId, 999); // 还原库存
|
||||||
memberFeignClient.updateBalance(memberId, 10000000 * 100); // 还原余额
|
|
||||||
orderFeignClient.updateOrderStatus(orderId, 101, false); // 待支付
|
orderFeignClient.updateOrderStatus(orderId, 101, false); // 待支付
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -44,5 +44,5 @@ public interface OrderFeignClient {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/api/v1/orders")
|
@PostMapping("/api/v1/orders")
|
||||||
Result<String> createOrder(SeataOrderDTO orderDTO, boolean openEx);
|
Result<String> createOrder(@RequestBody SeataOrderDTO orderDTO, @RequestParam boolean openEx);
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,9 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 订单控制层
|
||||||
|
*
|
||||||
* @author huawei
|
* @author huawei
|
||||||
* @email huawei_code@163.com
|
|
||||||
* @date 2020/12/30
|
* @date 2020/12/30
|
||||||
*/
|
*/
|
||||||
@Api(tags = "「管理端」订单管理")
|
@Api(tags = "「管理端」订单管理")
|
||||||
|
Loading…
Reference in New Issue
Block a user