系统单位 同步问题

This commit is contained in:
2025-04-11 13:58:38 +08:00
parent 4ce545f944
commit 24a209b118

View File

@@ -431,13 +431,16 @@ public class ShopSyncServiceImpl implements ShopSyncService {
Map<Long, Long> proMap = new HashMap<>();
List<Product> products = productService.queryChain().eq(Product::getShopId, sourceShopId).list();
if (CollectionUtil.isNotEmpty(products)) {
unitService.queryChain().eq(ShopProdUnit::getIsSystem, 1).list().forEach(tbShopUnit -> {
unitMap.put(tbShopUnit.getId(), tbShopUnit.getId());
});
for (Product tbProduct : products) {
if (CollUtil.isEmpty(pointProducts) || !pointProducts.contains(tbProduct.getId())) {
Product tbProductNew = BeanUtil.copyProperties(tbProduct, Product.class);
tbProductNew.setId(null);
tbProductNew.setSyncId(tbProduct.getId());
tbProductNew.setShopId(pointShopId);
tbProductNew.setCategoryId(tbProduct.getCategoryId() != null ? cateGoryMap.get(tbProduct.getSpecId()) : null);
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.setStockNumber(0);
@@ -479,12 +482,16 @@ public class ShopSyncServiceImpl implements ShopSyncService {
}
}
Map<Long, Long> unitMap = new HashMap<>();
Set<Long> sysUnitMap = new HashSet<>();
if (mainEntity.getUnitId() != null) {
List<ShopProdUnit> 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));
}
for (ShopProdUnit shopProdUnit : unitService.queryChain().eq(ShopProdUnit::getIsSystem, 1).list()) {
sysUnitMap.add(shopProdUnit.getId());
}
}
Map<Long, Long> categoryMap = new HashMap<>();
if (mainEntity.getCategoryId() != null) {
@@ -502,7 +509,11 @@ public class ShopSyncServiceImpl implements ShopSyncService {
newEntity.setShopId(shopId);
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 (newEntity.getUnitId() != null) {
if (!sysUnitMap.contains(newEntity.getUnitId())) {
newEntity.setUnitId(unitMap.get(shopId));
}
}
if (finalMap.containsKey(shopId)) {
Product childEntity = finalMap.get(shopId);
newEntity.setId(childEntity.getId());