fix: Seata实验室错误修复

This commit is contained in:
haoxr 2022-12-04 09:57:25 +08:00
parent a46173d3c1
commit 1fb89c4434
3 changed files with 15 additions and 18 deletions

View File

@ -39,18 +39,18 @@ public class SeataController {
return Result.success(result);
}
@ApiOperation("购买商品")
@PostMapping("/_purchase")
@ApiOperation("订单支付")
@PostMapping("/_pay")
public Result payOrder(@RequestBody SeataForm seataForm) {
boolean openTx = seataForm.isOpenTx();
String orderSn = null;
boolean result;
if (openTx) {
// 开启全局事务
orderSn = seataService.payOrderWithGlobalTx(seataForm);
result = seataService.payOrderWithGlobalTx(seataForm);
} else {
orderSn = seataService.payOrder(seataForm);
result = seataService.payOrder(seataForm);
}
return Result.success(orderSn);
return Result.success(result);
}
}

View File

@ -4,6 +4,8 @@ import com.youlai.laboratory.seata.pojo.form.SeataForm;
import com.youlai.laboratory.seata.pojo.vo.SeataVO;
/**
* Seata 实验室接口层
*
* @author haoxr
* @date 2022/4/16 20:49
*/
@ -24,16 +26,12 @@ public interface SeataService {
boolean resetData();
/**
* 购买商品
*
* @return 订单号
* 订单支付
*/
String payOrder(SeataForm seataForm);
boolean payOrder(SeataForm seataForm);
/**
* 购买商品(全局事务)
*
* @return 订单号
* 订单支付(全局事务)
*/
boolean payOrderWithGlobalTx(SeataForm seataForm);
}

View File

@ -18,7 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* Seata实验室业务类接口
* Seata 实验室业务类接口
*
* @author haoxr
* @date 2022/4/16 20:49
@ -86,7 +86,7 @@ public class SeataServiceImpl implements SeataService {
* 订单支付
*/
@Override
public String payOrder(SeataForm seataForm) {
public boolean payOrder(SeataForm seataForm) {
log.info("========扣减商品库存(全局事务)========");
skuFeignClient.deductStock(skuId, 1); // 扣减库存
@ -97,10 +97,9 @@ public class SeataServiceImpl implements SeataService {
seataForm.getAmount(),
seataForm.isOpenEx()
);
Result<String> result = orderFeignClient.payOrder(orderId, seataOrderDTO);
String orderSn = result.getData();
orderFeignClient.payOrder(orderId, seataOrderDTO);
return orderSn;
return true;
}
/**