商品同步问题

This commit is contained in:
2025-04-10 17:52:06 +08:00
parent 81e36b992e
commit e935d5932c

View File

@@ -459,20 +459,28 @@ public class ShopSyncServiceImpl implements ShopSyncService {
if (CollUtil.isNotEmpty(list)) {
map = list.stream().collect(Collectors.toMap(Product::getShopId, t -> t));
}
List<ShopProdSpec> specList = specService.queryChain().eq(ShopProdSpec::getSyncId, productId).in(ShopProdSpec::getShopId, shopIds).list();
Map<Long, Long> specMap = new HashMap<>();
if (CollUtil.isNotEmpty(specList)) {
specMap = specList.stream().collect(Collectors.toMap(ShopProdSpec::getShopId, ShopProdSpec::getId));
if (mainEntity.getSpecId() != null) {
List<ShopProdSpec> 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<ShopProdUnit> unitList = unitService.queryChain().eq(ShopProdUnit::getSyncId, productId).in(ShopProdUnit::getShopId, shopIds).list();
Map<Long, Long> unitMap = new HashMap<>();
if (CollUtil.isNotEmpty(unitList)) {
unitMap = unitList.stream().collect(Collectors.toMap(ShopProdUnit::getShopId, ShopProdUnit::getId));
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));
}
}
List<ShopProdCategory> categoryList = categoryService.queryChain().eq(ShopProdCategory::getSyncId, productId).in(ShopProdCategory::getShopId, shopIds).list();
Map<Long, Long> categoryMap = new HashMap<>();
if (CollUtil.isNotEmpty(categoryList)) {
categoryMap = categoryList.stream().collect(Collectors.toMap(ShopProdCategory::getShopId, ShopProdCategory::getId));
if (mainEntity.getCategoryId() != null) {
List<ShopProdCategory> 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<Long, Product> 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());