商品与耗材 同步关系

This commit is contained in:
2025-04-11 14:18:27 +08:00
parent 24a209b118
commit b9f535977c

View File

@@ -901,12 +901,34 @@ public class ShopSyncServiceImpl implements ShopSyncService {
public void syncConsPro(Long sourceShopId, Long pointShopId, Map<Long, Long> consMap, Map<Long, Long> proMap) {
List<ProdConsRelation> list = prodConsRelationService.queryChain().eq(ProdConsRelation::getShopId, sourceShopId).list();
List<ProdConsRelation> upList = new ArrayList<>();
List<ProdConsRelation> addList = new ArrayList<>();
for (ProdConsRelation prodConsRelation : list) {
prodConsRelation.setShopId(pointShopId);
prodConsRelation.setProductId(proMap.get(prodConsRelation.getProductId()));
prodConsRelation.setConsInfoId(consMap.get(prodConsRelation.getConsInfoId()));
if (prodConsRelation.getProductId() == null || prodConsRelation.getConsInfoId() == null) {
log.info("关联关系同步失败 商品ID:{}或耗材ID:{}不存在", prodConsRelation.getProductId(), prodConsRelation.getConsInfoId());
continue;
}
ProdConsRelation oldRelation = prodConsRelationService.queryChain()
.eq(ProdConsRelation::getShopId, pointShopId)
.eq(ProdConsRelation::getProductId, prodConsRelation.getProductId())
.eq(ProdConsRelation::getConsInfoId, prodConsRelation.getConsInfoId()).one();
if (oldRelation == null) {
addList.add(prodConsRelation);
} else {
if (oldRelation.getSurplusStock().compareTo(prodConsRelation.getSurplusStock()) != 0) {
upList.add(prodConsRelation);
}
}
}
if (CollUtil.isNotEmpty(addList)) {
prodConsRelationService.saveBatch(addList, 100);
}
if (CollUtil.isNotEmpty(upList)) {
prodConsRelationService.updateBatch(addList, 100);
}
prodConsRelationService.saveOrUpdateBatch(list, 100);
log.info("耗材与商品关联关系,同步{}个", list.size());
}