From 0374e2d9706efc8a487767919f07afdc76d2b950 Mon Sep 17 00:00:00 2001 From: qiushengjie Date: Sun, 17 Sep 2023 11:02:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=84=E4=B8=AA=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=B9=B6=E5=8F=91=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ms/api/biz/MoveService.java | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java index 9bf62522..68f210a9 100644 --- a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java +++ b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java @@ -626,35 +626,45 @@ public class MoveService { } public void processDsProduct(long shopId, long detailId, String status, String sourceItemId, Ret addProductRet) { - // 分销关系填入 if (!status.equals(StatusConst.success)) { log.info("状态不为成功,不进行分销关系填入"); return; } ProductAddV2Data productAddV2Data = (ProductAddV2Data) addProductRet.getData().get("data"); - String productId = String.valueOf(productAddV2Data.getProductId()); - ProductToDsItem productToDsItem = new ProductToDsItem(); - productToDsItem.setProductId(productId); - productToDsItem.setSourceSellerId((String) addProductRet.getData().getOrDefault("sourceSellerId", "")); - productToDsItem.setShopId(shopId); - productToDsItem.setSourceItemId(sourceItemId); - productToDsItem.setGmtCreate(new Date()); - productToDsItem.setGmtModified(new Date()); - productToDsItemService.insertSelective(productToDsItem); - - // 加入订单需要的队列 - DsRelateProductAnalysisOpOrderQueue dsQueue = new DsRelateProductAnalysisOpOrderQueue(); - dsQueue.setShopId(shopId); - dsQueue.setProductId(Long.valueOf(productId)); - dsRelateProductAnalysisOpOrderQueueService.insertSelective(dsQueue); - try { - // 请求上报分销关系,可以失败不会滚,失败异步任务进行同步 - addPlatformItemToSourceItemRelation(shopId, sourceItemId, productId); - } catch (Throwable e) { - e.printStackTrace(); - E.throwMSException("分销关系推送失败"); + // 请求上报分销关系,重试3次, 可以失败,失败异步任务进行同步 + JSONObject dsResult = null; + for (int i = 0; i < 3; i++) { + dsResult = addPlatformItemToSourceItemRelation(shopId, sourceItemId, productId); + if (ObjectUtil.isNotEmpty(dsResult)) { + break; + } + CommonTool.randomSleep(); + } + if (ObjectUtil.isNotEmpty(dsResult)) { + try { + // 保存分销关系 + ProductToDsItem productToDsItem = new ProductToDsItem(); + productToDsItem.setProductId(productId); + productToDsItem.setSourceSellerId((String) addProductRet.getData().getOrDefault("sourceSellerId", "")); + productToDsItem.setShopId(shopId); + productToDsItem.setSourceItemId(sourceItemId); + productToDsItem.setGmtCreate(new Date()); + productToDsItem.setGmtModified(new Date()); + productToDsItemService.insertSelective(productToDsItem); + + // 给订单模块进行同步历史订单的分销关系 + DsRelateProductAnalysisOpOrderQueue dsQueue = new DsRelateProductAnalysisOpOrderQueue(); + dsQueue.setShopId(shopId); + dsQueue.setProductId(Long.valueOf(productId)); + dsRelateProductAnalysisOpOrderQueueService.insertSelective(dsQueue); + } catch (Throwable e) { + E.throwMSException("分销关系推送失败"); + } + } else { + // 存入失败的分销关系中,异步任务进行同步 + } }