From 1fb89c443428510515c8e8057af0143c88c062d1 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Sun, 4 Dec 2022 09:57:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Seata=E5=AE=9E=E9=AA=8C=E5=AE=A4?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../laboratory/seata/controller/SeataController.java | 12 ++++++------ .../laboratory/seata/service/SeataService.java | 12 +++++------- .../seata/service/impl/SeataServiceImpl.java | 9 ++++----- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/laboratory/src/main/java/com/youlai/laboratory/seata/controller/SeataController.java b/laboratory/src/main/java/com/youlai/laboratory/seata/controller/SeataController.java index 10b27ba6c..9d6b73ed0 100644 --- a/laboratory/src/main/java/com/youlai/laboratory/seata/controller/SeataController.java +++ b/laboratory/src/main/java/com/youlai/laboratory/seata/controller/SeataController.java @@ -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); } } diff --git a/laboratory/src/main/java/com/youlai/laboratory/seata/service/SeataService.java b/laboratory/src/main/java/com/youlai/laboratory/seata/service/SeataService.java index 94fe5b51f..5958976dc 100644 --- a/laboratory/src/main/java/com/youlai/laboratory/seata/service/SeataService.java +++ b/laboratory/src/main/java/com/youlai/laboratory/seata/service/SeataService.java @@ -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); } diff --git a/laboratory/src/main/java/com/youlai/laboratory/seata/service/impl/SeataServiceImpl.java b/laboratory/src/main/java/com/youlai/laboratory/seata/service/impl/SeataServiceImpl.java index 2d23bc31d..72f3f9872 100644 --- a/laboratory/src/main/java/com/youlai/laboratory/seata/service/impl/SeataServiceImpl.java +++ b/laboratory/src/main/java/com/youlai/laboratory/seata/service/impl/SeataServiceImpl.java @@ -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 result = orderFeignClient.payOrder(orderId, seataOrderDTO); - String orderSn = result.getData(); + orderFeignClient.payOrder(orderId, seataOrderDTO); - return orderSn; + return true; } /**