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); return Result.success(result);
} }
@ApiOperation("购买商品") @ApiOperation("订单支付")
@PostMapping("/_purchase") @PostMapping("/_pay")
public Result payOrder(@RequestBody SeataForm seataForm) { public Result payOrder(@RequestBody SeataForm seataForm) {
boolean openTx = seataForm.isOpenTx(); boolean openTx = seataForm.isOpenTx();
String orderSn = null; boolean result;
if (openTx) { if (openTx) {
// 开启全局事务 // 开启全局事务
orderSn = seataService.payOrderWithGlobalTx(seataForm); result = seataService.payOrderWithGlobalTx(seataForm);
} else { } 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; import com.youlai.laboratory.seata.pojo.vo.SeataVO;
/** /**
* Seata 实验室接口层
*
* @author haoxr * @author haoxr
* @date 2022/4/16 20:49 * @date 2022/4/16 20:49
*/ */
@ -24,16 +26,12 @@ public interface SeataService {
boolean resetData(); boolean resetData();
/** /**
* 购买商品 * 订单支付
*
* @return 订单号
*/ */
String payOrder(SeataForm seataForm); boolean payOrder(SeataForm seataForm);
/** /**
* 购买商品(全局事务) * 订单支付(全局事务)
*
* @return 订单号
*/ */
boolean payOrderWithGlobalTx(SeataForm seataForm); boolean payOrderWithGlobalTx(SeataForm seataForm);
} }

View File

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