同步时 历史同步数据更新

This commit is contained in:
wangw 2025-04-12 15:09:06 +08:00
parent fe45484955
commit 86370e9781
1 changed files with 166 additions and 22 deletions

View File

@ -196,14 +196,15 @@ public class ShopSyncServiceImpl implements ShopSyncService {
public Map<Long, Long> syncUnit(Long sourceShopId, Long pointShopId, List<Map<String, Object>> mainMapList) {
Map<Long, Long> unitMap = new HashMap<>();
Map<Long, ShopProdUnit> unitEntityMap = new HashMap<>();
List<Long> pointShopUnits = new ArrayList<>();
List<ShopProdUnit> pointUnits = unitService.queryChain()
List<ShopProdUnit> 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<ShopProdUnit> 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<Long, Long> syncSpec(Long sourceShopId, Long pointShopId, List<Map<String, Object>> mainMapList) {
Map<Long, Long> specMap = new HashMap<>();
Map<Long, ShopProdSpec> specEntityMap = new HashMap<>();
List<Long> pointShopSpecs = new ArrayList<>();
List<ShopProdSpec> newPointList = new ArrayList<>();
List<ShopProdSpec> 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<ShopProdSpec> 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<Long, Long> syncCategory(Long sourceShopId, Long pointShopId, List<Map<String, Object>> mainMapList) {
Map<Long, Long> categoryMap = new HashMap<>();
Map<Long, ShopProdCategory> categoryEntityMap = new HashMap<>();
List<Long> pointShopCateGory = new ArrayList<>();
List<ShopProdCategory> newPointShopCateGory = new ArrayList<>();
List<ShopProdCategory> 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<ShopProdCategory> 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<ShopProdCategory> 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<Long, Long> syncProduct(Long sourceShopId, Long pointShopId, Map<Long, Long> unitMap,
Map<Long, Long> specMap, Map<Long, Long> cateGoryMap, List<Map<String, Object>> mainMapList) {
Map<Long, Long> proMap = new HashMap<>();
Map<Long, Product> pointMap = new HashMap<>();
List<Long> pointProducts = new ArrayList<>();
List<Product> 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<Product> 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<Long, Long> syncSku(Long sourceShopId, Long pointShopId, Map<Long, Long> prods) {
Map<Long, Long> skuMap = new HashMap<>();
List<Long> pointSkus = skuService.queryChain().select(ProdSku::getSyncId)
Map<Long, ProdSku> pointSkuMap = new HashMap<>();
List<Long> pointSkus = new ArrayList<>();
List<ProdSku> 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<ProdSku> 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<Long, Long> syncConsGroup(Long sourceShopId, Long pointShopId, List<Map<String, Object>> mainMapList) {
Map<Long, Long> consGroupMap = new HashMap<>();
Map<Long, ConsGroup> pointConsGroupMap = new HashMap<>();
List<Long> pointConsGroup = new ArrayList<>();
List<ConsGroup> 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<ConsGroup> 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<Long, Long> syncConsInfo(Long sourceShopId, Long pointShopId, Map<Long, Long> consGroupMap, List<Map<String, Object>> mainMapList) {
Map<Long, Long> consMap = new HashMap<>();
Map<Long, ConsInfo> pointConsMap = new HashMap<>();
List<Long> pointConsInfo = new ArrayList<>();
List<ConsInfo> 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<ConsInfo> 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<Long, Long> syncVendor(Long sourceShopId, Long pointShopId, List<Map<String, Object>> mainMapList) {
Map<Long, Long> vendorMap = new HashMap<>();
List<Long> pointShopVendor = vendorService.queryChain().select(ShopVendor::getSyncId)
Map<Long, ShopVendor> pointVendorMap = new HashMap<>();
List<Long> pointShopVendor = new ArrayList<>();
List<ShopVendor> 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<ShopVendor> 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;
}