diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java index 7b734e85..22363695 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java @@ -68,6 +68,8 @@ public class ShopSyncServiceImpl implements ShopSyncService { @Resource private ProdConsRelationService prodConsRelationService; @Resource + private ProductRpcService productRpcService; + @Resource private ShopUserService shopUserService; @Resource private ShopVendorService vendorService; @@ -158,6 +160,9 @@ public class ShopSyncServiceImpl implements ShopSyncService { syncConsPro(sourceShopId, targetShopId, consInfoMap, proMap); syncVendor(sourceShopId, targetShopId, mainMapList); syncNoticeService.addNotice(targetShopId, sysUserId, "数据同步", JSON.toJSONString(mainMapList), null); + categoryMap.forEach((k, v) -> { + productRpcService.cleanCategoryProduct(targetShopId, v); + }); } catch (Exception e) { log.error("同步异常", e); throw new CzgException("同步失败"); @@ -617,6 +622,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { } Map finalMap = map; for (Long shopId : shopIds) { + List cateGoryIds = new ArrayList<>(); List> mainMapList = new ArrayList<>(); Map dataMap = new HashMap<>(); Product newEntity = BeanUtil.copyProperties(mainEntity, Product.class); @@ -631,6 +637,9 @@ public class ShopSyncServiceImpl implements ShopSyncService { } if (finalMap.containsKey(shopId)) { Product childEntity = finalMap.get(shopId); + if (childEntity.getCategoryId() != null) { + cateGoryIds.add(childEntity.getCategoryId()); + } newEntity.setId(childEntity.getId()); newEntity.setStartTime(null); newEntity.setEndTime(null); @@ -648,6 +657,9 @@ public class ShopSyncServiceImpl implements ShopSyncService { newEntity.setStockNumber(0); productService.save(newEntity); } + if (newEntity.getCategoryId() != null) { + cateGoryIds.add(newEntity.getCategoryId()); + } syncSkuBySourceShop(sourceShopId, shopId, productId, newEntity.getId()); if ("package".equals(newEntity.getType()) || "coupon".equals(newEntity.getType())) { syncProductPackageBySourceShop(newEntity, shopId); @@ -655,6 +667,11 @@ public class ShopSyncServiceImpl implements ShopSyncService { dataMap.put(newEntity.getId(), newEntity.getName()); buildNotice(mainMapList, "商品变动", 1, "product", dataMap); syncNoticeService.addNotice(shopId, sysUserId, "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newEntity)); + if (CollUtil.isNotEmpty(cateGoryIds)) { + for (Long cateGoryId : cateGoryIds) { + productRpcService.cleanCategoryProduct(shopId, cateGoryId); + } + } } } catch (Exception e) { log.error("商品同步异常", e);