关联关系同步
This commit is contained in:
parent
d9e1cc378a
commit
e46e515666
|
|
@ -549,8 +549,13 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|||
|
||||
public Map<Long, Long> syncGroup(Long sourceShopId, Long pointShopId, Map<Long, Long> pros, List<Map<String, Object>> mainMapList) {
|
||||
Map<Long, Long> groupMap = new HashMap<>();
|
||||
List<Long> pointGroup = groupService.queryChain().select(ProdGroup::getSyncId).eq(ProdGroup::getShopId, pointShopId)
|
||||
.isNotNull(ProdGroup::getSyncId).listAs(Long.class);
|
||||
List<Long> pointGroup = new ArrayList<>();
|
||||
List<ProdGroup> pointList = groupService.queryChain().eq(ProdGroup::getShopId, pointShopId)
|
||||
.isNotNull(ProdGroup::getSyncId).list();
|
||||
for (ProdGroup prodGroup : pointList) {
|
||||
pointGroup.add(prodGroup.getSyncId());
|
||||
groupMap.put(prodGroup.getSyncId(), prodGroup.getId());
|
||||
}
|
||||
List<ProdGroup> list = groupService.queryChain().eq(ProdGroup::getShopId, sourceShopId).list();
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
log.info("分组同步,分组数据为空");
|
||||
|
|
@ -567,14 +572,33 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|||
groupMap.put(prodGroup.getId(), tbProductGroupNew.getId());
|
||||
}
|
||||
}
|
||||
List<ProdGroupRelation> groupRelations = prodGroupRelationService.queryChain().in(ProdGroupRelation::getProdGroupId, groupMap.keySet()).list();
|
||||
for (ProdGroupRelation prodGroupRelation : groupRelations) {
|
||||
prodGroupRelation.setProdGroupId(groupMap.get(prodGroupRelation.getProdGroupId()));
|
||||
prodGroupRelation.setProductId(pros.get(prodGroupRelation.getProductId()));
|
||||
if (CollUtil.isNotEmpty(groupMap)) {
|
||||
List<ProdGroupRelation> groupRelations = prodGroupRelationService.queryChain().in(ProdGroupRelation::getProdGroupId, groupMap.keySet()).list();
|
||||
List<ProdGroupRelation> upList = new ArrayList<>();
|
||||
List<ProdGroupRelation> addList = new ArrayList<>();
|
||||
for (ProdGroupRelation prodGroupRelation : groupRelations) {
|
||||
prodGroupRelation.setProdGroupId(groupMap.get(prodGroupRelation.getProdGroupId()));
|
||||
prodGroupRelation.setProductId(pros.get(prodGroupRelation.getProductId()));
|
||||
ProdGroupRelation oldRelation = prodGroupRelationService.queryChain()
|
||||
.eq(ProdGroupRelation::getProdGroupId, prodGroupRelation.getProdGroupId())
|
||||
.eq(ProdGroupRelation::getProductId, prodGroupRelation.getProductId()).one();
|
||||
if (oldRelation == null) {
|
||||
addList.add(prodGroupRelation);
|
||||
} else {
|
||||
if (oldRelation.getSort().equals(prodGroupRelation.getSort())) {
|
||||
upList.add(prodGroupRelation);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(addList)) {
|
||||
prodGroupRelationService.saveBatch(addList, 100);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(upList)) {
|
||||
prodGroupRelationService.updateBatch(addList, 100);
|
||||
}
|
||||
}
|
||||
prodGroupRelationService.saveOrUpdateBatch(groupRelations, 100);
|
||||
log.info("分组同步,源{}个,已有{}个,同步{}个", list.size(), pointGroup.size(), groupMap.size());
|
||||
buildNotice(mainMapList, "分组同步", groupMap.size(), null, null);
|
||||
log.info("分组同步,源{}个,已有{}个,同步{}个", list.size(), pointGroup.size(), groupMap.size() - pointGroup.size());
|
||||
buildNotice(mainMapList, "分组同步", groupMap.size() - pointGroup.size(), null, null);
|
||||
return groupMap;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue