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 { + // 存入失败的分销关系中,异步任务进行同步 + } }