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