同步时 历史同步数据更新

This commit is contained in:
wangw 2025-04-12 15:45:28 +08:00
parent caf42d0b0c
commit e1fab524f1
1 changed files with 33 additions and 7 deletions

View File

@ -207,7 +207,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
unitEntityMap.put(tbShopUnit.getSyncId(), tbShopUnit);
});
List<ShopProdUnit> list = unitService.queryChain().eq(ShopProdUnit::getShopId, sourceShopId).list();
list.forEach(tbShopUnit -> {
for (ShopProdUnit tbShopUnit : list) {
if (CollUtil.isEmpty(pointShopUnits) || !pointShopUnits.contains(tbShopUnit.getId())) {
ShopProdUnit unitNew = BeanUtil.copyProperties(tbShopUnit, ShopProdUnit.class);
unitNew.setId(null);
@ -217,13 +217,16 @@ public class ShopSyncServiceImpl implements ShopSyncService {
unitMap.put(tbShopUnit.getId(), unitNew.getId());
} else {
ShopProdUnit unit = unitEntityMap.get(tbShopUnit.getId());
if (unit == null) {
continue;
}
unit.setUnitType(tbShopUnit.getUnitType());
unit.setName(tbShopUnit.getName());
unit.setStatus(tbShopUnit.getStatus());
unitService.updateById(unit, false);
unitMap.put(tbShopUnit.getSyncId(), tbShopUnit.getId());
}
});
};
buildNotice(mainMapList, "单位同步", pointShopUnits.size(), null, null);
buildNotice(mainMapList, "单位新增", unitMap.size() - pointShopUnits.size(), null, null);
log.info("单位同步,源{}个,已有{}个,同步{}个", list.size(), pointShopUnits.size(), unitMap.size() - pointShopUnits.size());
@ -283,7 +286,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
specEntityMap.put(shopProdSpec.getSyncId(), shopProdSpec);
}
List<ShopProdSpec> list = specService.queryChain().eq(ShopProdSpec::getShopId, sourceShopId.toString()).list();
list.forEach(spec -> {
for (ShopProdSpec spec : list) {
if (CollUtil.isEmpty(pointShopSpecs) || !pointShopSpecs.contains(spec.getId())) {
ShopProdSpec newSpec = BeanUtil.copyProperties(spec, ShopProdSpec.class);
newSpec.setId(null);
@ -294,6 +297,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
specMap.put(spec.getId(), newSpec.getId());
} else {
ShopProdSpec newSpec = specEntityMap.get(spec.getId());
if (newSpec == null) {
continue;
}
newSpec.setName(spec.getName());
newSpec.setFullName(spec.getFullName());
newSpec.setLevel(spec.getLevel());
@ -303,7 +309,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
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()));
@ -312,7 +318,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
if ("0".equals(pid)) {
shopProdSpec.setPids("0,");
} else {
shopProdSpec.setPids(shopProdSpec.getPids() + specMap.get(Long.valueOf(pid)) + ",");
if (!"null".equals(pid) && specMap.containsKey(Long.valueOf(pid))) {
shopProdSpec.setPids(shopProdSpec.getPids() + specMap.get(Long.valueOf(pid)) + ",");
}
}
}
specService.updateById(shopProdSpec);
@ -393,6 +401,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
newPointShopCateGory.add(tbShopCategoryNew);
} else {
ShopProdCategory tbShopCategoryNew = categoryEntityMap.get(shopProdCategory.getId());
if (tbShopCategoryNew == null) {
continue;
}
tbShopCategoryNew.setName(shopProdCategory.getName());
tbShopCategoryNew.setShortName(shopProdCategory.getShortName());
tbShopCategoryNew.setPic(shopProdCategory.getPic());
@ -526,6 +537,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
proMap.put(tbProduct.getId(), tbProductNew.getId());
} else {
Product tbProductNew = pointMap.get(tbProduct.getId());
if (tbProductNew == null) {
continue;
}
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);
@ -861,6 +875,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
skuMap.put(prodSku.getId(), newSku.getId());
} else {
ProdSku newSku = pointSkuMap.get(prodSku.getId());
if (newSku == null) {
continue;
}
newSku.setSpecInfo(prodSku.getSpecInfo());
newSku.setCoverImg(prodSku.getCoverImg());
newSku.setIsDel(prodSku.getIsDel());
@ -935,6 +952,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
consGroupMap.put(consGroup.getId(), newConsGroup.getId());
} else {
ConsGroup newConsGroup = pointConsGroupMap.get(consGroup.getId());
if (newConsGroup == null) {
continue;
}
newConsGroup.setName(consGroup.getName());
newConsGroup.setStatus(consGroup.getStatus());
consGroupService.updateById(newConsGroup, false);
@ -1010,6 +1030,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
consMap.put(cons.getId(), conInfo.getId());
} else {
ConsInfo conInfo = pointConsMap.get(cons.getId());
if (conInfo == null) {
continue;
}
conInfo.setConsGroupId(consGroupMap.get(conInfo.getConsGroupId()));
conInfo.setConName(cons.getConName());
conInfo.setPrice(cons.getPrice());
@ -1172,7 +1195,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
pointVendorMap.put(shopVendor.getSyncId(), shopVendor);
}
List<ShopVendor> list = vendorService.queryChain().eq(ShopVendor::getShopId, sourceShopId).list();
list.forEach(vendor -> {
for (ShopVendor vendor : list) {
if (CollUtil.isEmpty(pointShopVendor) || !pointShopVendor.contains(vendor.getId())) {
ShopVendor vendorNew = BeanUtil.copyProperties(vendor, ShopVendor.class);
vendorNew.setId(null);
@ -1182,6 +1205,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
vendorMap.put(vendor.getId(), vendorNew.getId());
} else {
ShopVendor vendorNew = pointVendorMap.get(vendor.getId());
if (vendorNew == null) {
continue;
}
vendorNew.setSort(vendor.getSort());
vendorNew.setName(vendor.getName());
vendorNew.setContactName(vendor.getContactName());
@ -1194,7 +1220,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
vendorService.updateById(vendorNew, false);
vendorMap.put(vendor.getId(), vendorNew.getId());
}
});
}
buildNotice(mainMapList, "供应商同步", pointShopVendor.size(), null, null);
buildNotice(mainMapList, "供应商新增", vendorMap.size() - pointShopVendor.size(), null, null);
log.info("供应商同步,源{}个,已有{}个,同步{}个", list.size(), pointShopVendor.size(), vendorMap.size());