From 86370e97814130391e5e685140ac763904336434 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 12 Apr 2025 15:09:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=97=B6=20=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E5=90=8C=E6=AD=A5=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ShopSyncServiceImpl.java | 188 ++++++++++++++++-- 1 file changed, 166 insertions(+), 22 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 d7783a1d..fda39d45 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 @@ -196,14 +196,15 @@ public class ShopSyncServiceImpl implements ShopSyncService { public Map syncUnit(Long sourceShopId, Long pointShopId, List> mainMapList) { Map unitMap = new HashMap<>(); + Map unitEntityMap = new HashMap<>(); List pointShopUnits = new ArrayList<>(); - List pointUnits = unitService.queryChain() + List pointUnits = unitService.queryChain().select(ShopProdUnit::getSyncId) .eq(ShopProdUnit::getShopId, pointShopId) .isNotNull(ShopProdUnit::getSyncId) .list(); pointUnits.stream().forEach(tbShopUnit -> { - unitMap.put(tbShopUnit.getSyncId(), tbShopUnit.getId()); pointShopUnits.add(tbShopUnit.getSyncId()); + unitEntityMap.put(tbShopUnit.getSyncId(), tbShopUnit); }); List list = unitService.queryChain().eq(ShopProdUnit::getShopId, sourceShopId).list(); list.forEach(tbShopUnit -> { @@ -214,9 +215,17 @@ public class ShopSyncServiceImpl implements ShopSyncService { unitNew.setShopId(pointShopId); unitService.save(unitNew); unitMap.put(tbShopUnit.getId(), unitNew.getId()); + } else { + ShopProdUnit unit = unitEntityMap.get(tbShopUnit.getId()); + unit.setUnitType(tbShopUnit.getUnitType()); + unit.setName(tbShopUnit.getName()); + unit.setStatus(tbShopUnit.getStatus()); + unitService.updateById(unit, false); + unitMap.put(tbShopUnit.getSyncId(), tbShopUnit.getId()); } }); - buildNotice(mainMapList, "单位同步", unitMap.size() - pointShopUnits.size(), null, null); + buildNotice(mainMapList, "单位同步", pointShopUnits.size(), null, null); + buildNotice(mainMapList, "单位新增", unitMap.size() - pointShopUnits.size(), null, null); log.info("单位同步,源{}个,已有{}个,同步{}个", list.size(), pointShopUnits.size(), unitMap.size() - pointShopUnits.size()); return unitMap; } @@ -262,14 +271,16 @@ public class ShopSyncServiceImpl implements ShopSyncService { //规格 public Map syncSpec(Long sourceShopId, Long pointShopId, List> mainMapList) { Map specMap = new HashMap<>(); + Map specEntityMap = new HashMap<>(); List pointShopSpecs = new ArrayList<>(); + List newPointList = new ArrayList<>(); List pointList = specService.queryChain() .eq(ShopProdSpec::getShopId, pointShopId) .isNotNull(ShopProdSpec::getSyncId) .list(); for (ShopProdSpec shopProdSpec : pointList) { pointShopSpecs.add(shopProdSpec.getSyncId()); - specMap.put(shopProdSpec.getSyncId(), shopProdSpec.getId()); + specEntityMap.put(shopProdSpec.getSyncId(), shopProdSpec); } List list = specService.queryChain().eq(ShopProdSpec::getShopId, sourceShopId.toString()).list(); list.forEach(spec -> { @@ -279,11 +290,37 @@ public class ShopSyncServiceImpl implements ShopSyncService { newSpec.setSyncId(spec.getId()); newSpec.setShopId(pointShopId); specService.save(newSpec); + newPointList.add(newSpec); specMap.put(spec.getId(), newSpec.getId()); + } else { + ShopProdSpec newSpec = specEntityMap.get(spec.getId()); + newSpec.setName(spec.getName()); + newSpec.setFullName(spec.getFullName()); + newSpec.setLevel(spec.getLevel()); + newSpec.setSort(spec.getSort()); + newSpec.setStatus(spec.getStatus()); + specService.updateById(newSpec, false); + specMap.put(spec.getId(), newSpec.getId()); + newPointList.add(newSpec); } }); + for (ShopProdSpec shopProdSpec : newPointList) { + if (shopProdSpec.getPid() != null && !shopProdSpec.getPid().equals(0L)) { + shopProdSpec.setPid(specMap.get(shopProdSpec.getPid())); + String[] split = shopProdSpec.getPids().split(","); + for (String pid : split) { + if ("0".equals(pid)) { + shopProdSpec.setPids("0,"); + } else { + shopProdSpec.setPids(shopProdSpec.getPids() + specMap.get(Long.valueOf(pid)) + ","); + } + } + specService.updateById(shopProdSpec); + } + } log.info("规格同步,源{}个,已有{}个,同步{}个", list.size(), pointShopSpecs.size(), specMap.size() - pointShopSpecs.size()); - buildNotice(mainMapList, "规格同步", specMap.size() - pointShopSpecs.size(), null, null); + buildNotice(mainMapList, "规格同步", pointShopSpecs.size(), null, null); + buildNotice(mainMapList, "规格新增", specMap.size() - pointShopSpecs.size(), null, null); return specMap; } @@ -328,14 +365,16 @@ public class ShopSyncServiceImpl implements ShopSyncService { // 分类 public Map syncCategory(Long sourceShopId, Long pointShopId, List> mainMapList) { Map categoryMap = new HashMap<>(); + Map categoryEntityMap = new HashMap<>(); List pointShopCateGory = new ArrayList<>(); + List newPointShopCateGory = new ArrayList<>(); List pointList = categoryService.queryChain() .eq(ShopProdCategory::getShopId, pointShopId) .isNotNull(ShopProdCategory::getSyncId) .list(); for (ShopProdCategory shopProdCategory : pointList) { pointShopCateGory.add(shopProdCategory.getSyncId()); - categoryMap.put(shopProdCategory.getSyncId(), shopProdCategory.getId()); + categoryEntityMap.put(shopProdCategory.getSyncId(), shopProdCategory); } List tbShopCategories = categoryService.queryChain() .eq(ShopProdCategory::getShopId, sourceShopId) @@ -351,10 +390,22 @@ public class ShopSyncServiceImpl implements ShopSyncService { tbShopCategoryNew.setSyncId(shopProdCategory.getId()); categoryService.save(tbShopCategoryNew); categoryMap.put(shopProdCategory.getId(), tbShopCategoryNew.getId()); + newPointShopCateGory.add(tbShopCategoryNew); + } else { + ShopProdCategory tbShopCategoryNew = categoryEntityMap.get(shopProdCategory.getId()); + tbShopCategoryNew.setName(shopProdCategory.getName()); + tbShopCategoryNew.setShortName(shopProdCategory.getShortName()); + tbShopCategoryNew.setPic(shopProdCategory.getPic()); + tbShopCategoryNew.setDetail(shopProdCategory.getDetail()); + tbShopCategoryNew.setSort(shopProdCategory.getSort()); + tbShopCategoryNew.setKeyWord(shopProdCategory.getKeyWord()); + tbShopCategoryNew.setStatus(shopProdCategory.getStatus()); + categoryService.updateById(tbShopCategoryNew, false); + categoryMap.put(shopProdCategory.getId(), tbShopCategoryNew.getId()); + newPointShopCateGory.add(tbShopCategoryNew); } } int childrenSize = 0; - int syncSize = categoryMap.size(); if (CollectionUtil.isNotEmpty(treeIds)) { List children = categoryService.queryChain() .eq(ShopProdCategory::getShopId, sourceShopId) @@ -370,12 +421,28 @@ public class ShopSyncServiceImpl implements ShopSyncService { tbShopCategoryNew.setPid(categoryMap.get(child.getPid())); categoryService.save(tbShopCategoryNew); categoryMap.put(child.getId(), tbShopCategoryNew.getId()); + newPointShopCateGory.add(tbShopCategoryNew); + } else { + ShopProdCategory tbShopCategoryNew = categoryEntityMap.get(child.getId()); + tbShopCategoryNew.setName(child.getName()); + tbShopCategoryNew.setShortName(child.getShortName()); + tbShopCategoryNew.setPic(child.getPic()); + tbShopCategoryNew.setDetail(child.getDetail()); + tbShopCategoryNew.setSort(child.getSort()); + tbShopCategoryNew.setKeyWord(child.getKeyWord()); + tbShopCategoryNew.setStatus(child.getStatus()); + categoryService.updateById(tbShopCategoryNew, false); + categoryMap.put(child.getId(), tbShopCategoryNew.getId()); + newPointShopCateGory.add(tbShopCategoryNew); } } } - log.info("分类同步,源 父类分类{}个,同步{}个", tbShopCategories.size(), syncSize); - log.info("分类同步,源 子类分类{}个,同步{}个", childrenSize, categoryMap.size() - syncSize); - buildNotice(mainMapList, "分类同步", categoryMap.size(), null, null); +// for (ShopProdCategory shopProdCategory : newPointShopCateGory) { +// shopProdCategory.getPid() +// } + log.info("分类同步,同步{}个", categoryMap.size()); + buildNotice(mainMapList, "分类同步", tbShopCategories.size() + childrenSize - pointShopCateGory.size(), null, null); + buildNotice(mainMapList, "分类新增", categoryMap.size() - pointShopCateGory.size(), null, null); return categoryMap; } @@ -427,6 +494,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { public Map syncProduct(Long sourceShopId, Long pointShopId, Map unitMap, Map specMap, Map cateGoryMap, List> mainMapList) { Map proMap = new HashMap<>(); + Map pointMap = new HashMap<>(); List pointProducts = new ArrayList<>(); List pointList = productService.queryChain() .eq(Product::getShopId, pointShopId) @@ -434,7 +502,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { .list(); for (Product product : pointList) { pointProducts.add(product.getSyncId()); - proMap.put(product.getSyncId(), product.getId()); + pointMap.put(product.getSyncId(), product); } List products = productService.queryChain().eq(Product::getShopId, sourceShopId).list(); if (CollectionUtil.isNotEmpty(products)) { @@ -456,11 +524,31 @@ public class ShopSyncServiceImpl implements ShopSyncService { } productService.save(tbProductNew); proMap.put(tbProduct.getId(), tbProductNew.getId()); + } else { + Product tbProductNew = pointMap.get(tbProduct.getId()); + tbProductNew.setCategoryId(tbProduct.getCategoryId() != null ? cateGoryMap.get(tbProduct.getCategoryId()) : null); + tbProductNew.setSpecId(tbProduct.getSpecId() != null ? specMap.get(tbProduct.getSpecId()) : null); + tbProductNew.setUnitId(tbProduct.getUnitId() != null ? unitMap.get(tbProduct.getUnitId()) : null); + tbProductNew.setName(tbProduct.getName()); + tbProductNew.setShortTitle(tbProduct.getShortTitle()); + tbProductNew.setType(tbProduct.getType()); + tbProductNew.setGroupType(tbProduct.getGroupType()); + tbProductNew.setPackFee(tbProduct.getPackFee()); + tbProductNew.setCoverImg(tbProduct.getCoverImg()); + tbProductNew.setImages(tbProduct.getImages()); + tbProductNew.setWarnLine(tbProduct.getWarnLine()); + tbProductNew.setWeight(tbProduct.getWeight()); + tbProductNew.setSelectSpecInfo(tbProduct.getSelectSpecInfo()); + tbProductNew.setSort(tbProduct.getSort()); + tbProductNew.setIsDel(tbProduct.getIsDel()); + productService.updateById(tbProductNew, false); + proMap.put(tbProductNew.getSyncId(), tbProductNew.getId()); } } } log.info("商品同步,源{}个,已有{}个,同步{}个", products.size(), pointProducts.size(), proMap.size() - pointProducts.size()); - buildNotice(mainMapList, "商品同步", proMap.size() - pointProducts.size(), null, null); + buildNotice(mainMapList, "商品同步", pointProducts.size(), null, null); + buildNotice(mainMapList, "商品新增", proMap.size() - pointProducts.size(), null, null); return proMap; } @@ -751,10 +839,16 @@ public class ShopSyncServiceImpl implements ShopSyncService { //分组 public Map syncSku(Long sourceShopId, Long pointShopId, Map prods) { Map skuMap = new HashMap<>(); - List pointSkus = skuService.queryChain().select(ProdSku::getSyncId) + Map pointSkuMap = new HashMap<>(); + List pointSkus = new ArrayList<>(); + List skus = skuService.queryChain() .eq(ProdSku::getShopId, pointShopId) .isNotNull(ProdSku::getSyncId) - .listAs(Long.class); + .list(); + skus.forEach(tbShopSku -> { + pointSkus.add(tbShopSku.getSyncId()); + pointSkuMap.put(tbShopSku.getSyncId(), tbShopSku); + }); List list = skuService.queryChain().eq(ProdSku::getShopId, sourceShopId).list(); for (ProdSku prodSku : list) { if (prods.containsKey(prodSku.getProductId()) && (CollUtil.isEmpty(pointSkus) || !pointSkus.contains(prodSku.getId()))) { @@ -765,6 +859,13 @@ public class ShopSyncServiceImpl implements ShopSyncService { newSku.setSyncId(prodSku.getId()); skuService.save(newSku); skuMap.put(prodSku.getId(), newSku.getId()); + } else { + ProdSku newSku = pointSkuMap.get(prodSku.getId()); + newSku.setSpecInfo(prodSku.getSpecInfo()); + newSku.setCoverImg(prodSku.getCoverImg()); + newSku.setIsDel(prodSku.getIsDel()); + skuService.updateById(newSku, false); + skuMap.put(prodSku.getId(), newSku.getId()); } } log.info("商品SKU同步,源{}个,已有{}个,同步{}个", list.size(), pointSkus.size(), skuMap.size()); @@ -805,6 +906,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { public Map syncConsGroup(Long sourceShopId, Long pointShopId, List> mainMapList) { Map consGroupMap = new HashMap<>(); + Map pointConsGroupMap = new HashMap<>(); List pointConsGroup = new ArrayList<>(); List consGroupList = consGroupService.queryChain() .eq(ConsGroup::getShopId, pointShopId) @@ -812,7 +914,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { .list(); for (ConsGroup consGroup : consGroupList) { pointConsGroup.add(consGroup.getSyncId()); - consGroupMap.put(consGroup.getSyncId(), consGroup.getId()); + pointConsGroupMap.put(consGroup.getSyncId(), consGroup); } List list = consGroupService.queryChain().eq(ConsGroup::getShopId, sourceShopId).list(); for (ConsGroup consGroup : list) { @@ -823,10 +925,17 @@ public class ShopSyncServiceImpl implements ShopSyncService { newConsGroup.setShopId(pointShopId); consGroupService.save(newConsGroup); consGroupMap.put(consGroup.getId(), newConsGroup.getId()); + } else { + ConsGroup newConsGroup = pointConsGroupMap.get(consGroup.getId()); + newConsGroup.setName(consGroup.getName()); + newConsGroup.setStatus(consGroup.getStatus()); + consGroupService.updateById(newConsGroup, false); + consGroupMap.put(consGroup.getId(), newConsGroup.getId()); } } log.info("耗材分组同步,源{}个,已有{}个,同步{}个", list.size(), pointConsGroup.size(), consGroupMap.size() - pointConsGroup.size()); - buildNotice(mainMapList, "耗材分组同步", consGroupMap.size() - pointConsGroup.size(), null, null); + buildNotice(mainMapList, "耗材分组同步", pointConsGroup.size(), null, null); + buildNotice(mainMapList, "耗材分组新增", consGroupMap.size() - pointConsGroup.size(), null, null); return consGroupMap; } @@ -870,6 +979,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { // 耗材 public Map syncConsInfo(Long sourceShopId, Long pointShopId, Map consGroupMap, List> mainMapList) { Map consMap = new HashMap<>(); + Map pointConsMap = new HashMap<>(); List pointConsInfo = new ArrayList<>(); List pointList = consInfoService.queryChain() .eq(ConsInfo::getShopId, pointShopId) @@ -877,7 +987,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { .list(); for (ConsInfo consInfo : pointList) { pointConsInfo.add(consInfo.getSyncId()); - consMap.put(consInfo.getSyncId(), consInfo.getId()); + pointConsMap.put(consInfo.getSyncId(), consInfo); } List list = consInfoService.queryChain().eq(ConsInfo::getShopId, sourceShopId).list(); for (ConsInfo cons : list) { @@ -890,10 +1000,25 @@ public class ShopSyncServiceImpl implements ShopSyncService { conInfo.setStockNumber(BigDecimal.ZERO); consInfoService.save(conInfo); consMap.put(cons.getId(), conInfo.getId()); + } else { + ConsInfo conInfo = pointConsMap.get(cons.getId()); + conInfo.setConsGroupId(consGroupMap.get(conInfo.getConsGroupId())); + conInfo.setConName(cons.getConName()); + conInfo.setPrice(cons.getPrice()); + conInfo.setStatus(cons.getStatus()); + conInfo.setConUnit(cons.getConUnit()); + conInfo.setConWarning(cons.getConWarning()); + conInfo.setIsStock(cons.getIsStock()); + conInfo.setConUnitTwo(cons.getConUnitTwo()); + conInfo.setConUnitTwoConvert(cons.getConUnitTwoConvert()); + conInfo.setDefaultUnit(cons.getDefaultUnit()); + consInfoService.updateById(conInfo, false); + consMap.put(cons.getId(), conInfo.getId()); } } log.info("耗材同步,源{}个,已有{}个,同步{}个", list.size(), pointConsInfo.size(), consMap.size() - pointConsInfo.size()); - buildNotice(mainMapList, "耗材信息同步", consMap.size() - pointConsInfo.size(), null, null); + buildNotice(mainMapList, "耗材信息同步", pointConsInfo.size(), null, null); + buildNotice(mainMapList, "耗材信息新增", consMap.size() - pointConsInfo.size(), null, null); return consMap; } @@ -1028,11 +1153,16 @@ public class ShopSyncServiceImpl implements ShopSyncService { public Map syncVendor(Long sourceShopId, Long pointShopId, List> mainMapList) { Map vendorMap = new HashMap<>(); - List pointShopVendor = vendorService.queryChain().select(ShopVendor::getSyncId) + Map pointVendorMap = new HashMap<>(); + List pointShopVendor = new ArrayList<>(); + List pointShopVendorList = vendorService.queryChain() .eq(ShopVendor::getShopId, pointShopId) .isNotNull(ShopVendor::getSyncId) - .listAs(Long.class); - + .list(); + for (ShopVendor shopVendor : pointShopVendorList) { + pointShopVendor.add(shopVendor.getSyncId()); + pointVendorMap.put(shopVendor.getSyncId(), shopVendor); + } List list = vendorService.queryChain().eq(ShopVendor::getShopId, sourceShopId).list(); list.forEach(vendor -> { if (CollUtil.isEmpty(pointShopVendor) || !pointShopVendor.contains(vendor.getId())) { @@ -1042,9 +1172,23 @@ public class ShopSyncServiceImpl implements ShopSyncService { vendorNew.setShopId(pointShopId); vendorService.save(vendorNew); vendorMap.put(vendor.getId(), vendorNew.getId()); + } else { + ShopVendor vendorNew = pointVendorMap.get(vendor.getId()); + vendorNew.setSort(vendor.getSort()); + vendorNew.setName(vendor.getName()); + vendorNew.setContactName(vendor.getContactName()); + vendorNew.setTelephone(vendor.getTelephone()); + vendorNew.setAddress(vendor.getAddress()); + vendorNew.setPeriod(vendor.getPeriod()); + vendorNew.setTip(vendor.getTip()); + vendorNew.setRemark(vendor.getRemark()); + vendorNew.setIsDel(vendor.getIsDel()); + vendorService.updateById(vendorNew, false); + vendorMap.put(vendor.getId(), vendorNew.getId()); } }); - buildNotice(mainMapList, "单位同步", vendorMap.size(), null, null); + buildNotice(mainMapList, "供应商同步", pointShopVendor.size(), null, null); + buildNotice(mainMapList, "供应商新增", vendorMap.size() - pointShopVendor.size(), null, null); log.info("供应商同步,源{}个,已有{}个,同步{}个", list.size(), pointShopVendor.size(), vendorMap.size()); return vendorMap; }