From 0376bf1453e5ac4172b579a76aa8eb1d97665521 Mon Sep 17 00:00:00 2001 From: DB <2502523450@qq.com> Date: Wed, 1 Nov 2023 00:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=9B=B4=E6=96=B0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=BC=82=E6=AD=A5=E9=87=8D=E6=96=B0=E5=8F=91=E8=B5=B7?= =?UTF-8?q?=E4=B8=8E=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/OrderServiceImpl.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java index 559696f..6593d46 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java @@ -28,8 +28,10 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.row.Db; import com.mybatisflex.spring.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -314,7 +316,7 @@ public class OrderServiceImpl extends ServiceImpl implements productRecords.forEach(item -> { item.setRecordNum(item.getRecordNum() - orderNumMap.get(item.getId())); }); - productRecordService.updateBatch(productRecords); + asyncUpdateRecords(productRecords,0); //TODO:分账先注释 /*ProfitSharing profitSharing = new ProfitSharing(); profitSharing.setOrderId(orderId) @@ -344,6 +346,30 @@ public class OrderServiceImpl extends ServiceImpl implements } } + /** + * @Description: 异步更新数据库 + * @param productRecords 产品记录 + * @param flag 成功标志 + * @return + * @Author DB + * @Date: 2023/11/1 0:09 + */ + @Async("customAsyncThreadPool") + public void asyncUpdateRecords(List productRecords, Integer flag) { + ProductRecordService productRecordService = SpringUtils.getBean(ProductRecordService.class); + if (flag > 5) { + //TODO:通知到系统库存减扣失败,需要人为操作 + throw new ServiceException("更新订单失败"); + } else { + boolean tx = Db.tx(() -> productRecordService.updateBatch(productRecords)); + if (!tx){ + //更新失败 + flag++; + asyncUpdateRecords(productRecords, flag); + } + } + } + /** * @descriptions 取消订单 * @author DB