From e935d5932c73d5616ab34c8e6d89325d34b1e2f3 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 10 Apr 2025 17:52:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=90=8C=E6=AD=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ShopSyncServiceImpl.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) 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 e0a9e4ecd..982a657a9 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 @@ -459,20 +459,28 @@ public class ShopSyncServiceImpl implements ShopSyncService { if (CollUtil.isNotEmpty(list)) { map = list.stream().collect(Collectors.toMap(Product::getShopId, t -> t)); } - List specList = specService.queryChain().eq(ShopProdSpec::getSyncId, productId).in(ShopProdSpec::getShopId, shopIds).list(); Map specMap = new HashMap<>(); - if (CollUtil.isNotEmpty(specList)) { - specMap = specList.stream().collect(Collectors.toMap(ShopProdSpec::getShopId, ShopProdSpec::getId)); + if (mainEntity.getSpecId() != null) { + List specList = specService.queryChain().eq(ShopProdSpec::getSyncId, mainEntity.getSpecId()) + .in(ShopProdSpec::getShopId, shopIds).list(); + if (CollUtil.isNotEmpty(specList)) { + specMap = specList.stream().collect(Collectors.toMap(ShopProdSpec::getShopId, ShopProdSpec::getId)); + } } - List unitList = unitService.queryChain().eq(ShopProdUnit::getSyncId, productId).in(ShopProdUnit::getShopId, shopIds).list(); Map unitMap = new HashMap<>(); - if (CollUtil.isNotEmpty(unitList)) { - unitMap = unitList.stream().collect(Collectors.toMap(ShopProdUnit::getShopId, ShopProdUnit::getId)); + if (mainEntity.getUnitId() != null) { + List unitList = unitService.queryChain().eq(ShopProdUnit::getSyncId, mainEntity.getUnitId()) + .in(ShopProdUnit::getShopId, shopIds).list(); + if (CollUtil.isNotEmpty(unitList)) { + unitMap = unitList.stream().collect(Collectors.toMap(ShopProdUnit::getShopId, ShopProdUnit::getId)); + } } - List categoryList = categoryService.queryChain().eq(ShopProdCategory::getSyncId, productId).in(ShopProdCategory::getShopId, shopIds).list(); Map categoryMap = new HashMap<>(); - if (CollUtil.isNotEmpty(categoryList)) { - categoryMap = categoryList.stream().collect(Collectors.toMap(ShopProdCategory::getShopId, ShopProdCategory::getId)); + if (mainEntity.getCategoryId() != null) { + List categoryList = categoryService.queryChain().eq(ShopProdCategory::getSyncId, mainEntity.getCategoryId()).in(ShopProdCategory::getShopId, shopIds).list(); + if (CollUtil.isNotEmpty(categoryList)) { + categoryMap = categoryList.stream().collect(Collectors.toMap(ShopProdCategory::getShopId, ShopProdCategory::getId)); + } } Map finalMap = map; for (Long shopId : shopIds) { @@ -481,9 +489,9 @@ public class ShopSyncServiceImpl implements ShopSyncService { Product newEntity = BeanUtil.copyProperties(mainEntity, Product.class); newEntity.setSyncId(mainEntity.getSyncId()); newEntity.setShopId(shopId); - newEntity.setCategoryId(newEntity.getCategoryId() != null ? categoryMap.get(newEntity.getSpecId()) : null); - newEntity.setSpecId(newEntity.getSpecId() != null ? specMap.get(newEntity.getSpecId()) : null); - newEntity.setUnitId(newEntity.getUnitId() != null ? unitMap.get(newEntity.getUnitId()) : null); + newEntity.setCategoryId(newEntity.getCategoryId() != null ? categoryMap.get(shopId) : null); + newEntity.setSpecId(newEntity.getSpecId() != null ? specMap.get(shopId) : null); + newEntity.setUnitId(newEntity.getUnitId() != null ? unitMap.get(shopId) : null); if (finalMap.containsKey(shopId)) { Product childEntity = finalMap.get(shopId); newEntity.setId(childEntity.getId());