同步问题
This commit is contained in:
@@ -118,6 +118,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void sync(Long sourceShopId, Long targetShopId, Long sysUserId) {
|
||||
log.info("同步开始,源店铺ID:{},目标店铺ID:{}", sourceShopId, targetShopId);
|
||||
try {
|
||||
Map<Long, Long> unitMap;
|
||||
Map<Long, Long> specMap;
|
||||
Map<Long, Long> categoryMap;
|
||||
@@ -152,6 +153,10 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
Map<Long, Long> consInfoMap = syncConsInfo(sourceShopId, targetShopId, conGroupMap, mainMapList);
|
||||
syncConsPro(sourceShopId, targetShopId, consInfoMap, proMap);
|
||||
syncNoticeService.addNotice(targetShopId, sysUserId, "数据同步", JSON.toJSONString(mainMapList), null);
|
||||
} catch (Exception e) {
|
||||
log.error("同步异常", e);
|
||||
throw new CzgException("同步失败");
|
||||
}
|
||||
log.info("同步结束,源店铺ID:{},目标店铺ID:{}", sourceShopId, targetShopId);
|
||||
|
||||
}
|
||||
@@ -581,7 +586,6 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
dataMap.put(newEntity.getId(), newEntity.getName());
|
||||
buildNotice(mainMapList, "分组变动", 1, "group", dataMap);
|
||||
syncNoticeService.addNotice(shopId, sysUserId, "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newEntity));
|
||||
if (CollUtil.isEmpty(groupRelationMap)) {
|
||||
List<ProdGroupRelation> oldProdGroup = prodGroupRelationService.queryChain().eq(ProdGroupRelation::getProdGroupId, newEntity.getId()).list();
|
||||
if (CollUtil.isEmpty(oldProdGroup)) {
|
||||
continue;
|
||||
@@ -596,8 +600,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
queryWrapper.eq(ProdGroupRelation::getProdGroupId, newEntity.getId());
|
||||
queryWrapper.in(ProdGroupRelation::getProductId, rmIds);
|
||||
prodGroupRelationService.remove(queryWrapper);
|
||||
} else {
|
||||
List<Product> prods = productService.queryChain().select(Product::getId).eq(Product::getShopId, shopId).in(Product::getSyncId, groupRelationMap.keySet()).list();
|
||||
|
||||
if (CollUtil.isNotEmpty(groupRelationMap)) {
|
||||
List<Product> prods = productService.queryChain().eq(Product::getShopId, shopId).in(Product::getSyncId, groupRelationMap.keySet()).list();
|
||||
for (Product prod : prods) {
|
||||
ProdGroupRelation newProdGroupRelation = new ProdGroupRelation();
|
||||
newProdGroupRelation.setProdGroupId(newEntity.getId());
|
||||
@@ -608,7 +613,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(groupRelations)) {
|
||||
prodGroupRelationService.saveOrUpdateBatch(groupRelationList, 100);
|
||||
prodGroupRelationService.saveBatch(groupRelationList, 100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,19 +890,25 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
for (Long shopId : shopIds) {
|
||||
Product product = productService.queryChain().eq(Product::getSyncId, sourceProdId).eq(Product::getShopId, shopId).one();
|
||||
if (product != null) {
|
||||
List<ConsInfo> newCons = new ArrayList<>();
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
List<Long> prods = prodConsRelationService.queryChain().select(ProdConsRelation::getProductId)
|
||||
.eq(ProdConsRelation::getShopId, shopId).eq(ProdConsRelation::getProductId, product.getId()).listAs(Long.class);
|
||||
if (CollUtil.isNotEmpty(prods)) {
|
||||
List<Long> remIds = productService.queryChain().select(Product::getId).in(Product::getId, prods).isNotNull(Product::getSyncId).listAs(Long.class);
|
||||
if (CollUtil.isNotEmpty(remIds)) {
|
||||
prodConsRelationService.remove(new QueryWrapper().eq(ProdConsRelation::getShopId, shopId).in(ProdConsRelation::getProductId, remIds));
|
||||
}
|
||||
newCons = consInfoService.queryChain()
|
||||
.isNotNull(ConsInfo::getSyncId).eq(ConsInfo::getShopId, shopId).list();
|
||||
if (CollUtil.isNotEmpty(newCons)) {
|
||||
prodConsRelationService.remove(QueryWrapper.create()
|
||||
.eq(ProdConsRelation::getShopId, shopId)
|
||||
.eq(ProdConsRelation::getProductId, product.getId())
|
||||
.in(ProdConsRelation::getConsInfoId, newCons.stream().map(ConsInfo::getId).collect(Collectors.toList())));
|
||||
}
|
||||
} else {
|
||||
Map<Long, BigDecimal> map = list.stream().collect(Collectors.toMap(ProdConsRelation::getConsInfoId, ProdConsRelation::getSurplusStock));
|
||||
List<ConsInfo> newCons = consInfoService.queryChain().select(ConsInfo::getId)
|
||||
newCons = consInfoService.queryChain()
|
||||
.in(ConsInfo::getSyncId, map.keySet()).eq(ConsInfo::getShopId, shopId).list();
|
||||
if (CollUtil.isNotEmpty(newCons)) {
|
||||
prodConsRelationService.remove(QueryWrapper.create()
|
||||
.eq(ProdConsRelation::getShopId, shopId)
|
||||
.eq(ProdConsRelation::getProductId, product.getId())
|
||||
.in(ProdConsRelation::getConsInfoId, newCons.stream().map(ConsInfo::getId).collect(Collectors.toList())));
|
||||
for (ConsInfo newCon : newCons) {
|
||||
ProdConsRelation prodConsRelation = new ProdConsRelation();
|
||||
prodConsRelation.setShopId(shopId);
|
||||
@@ -909,8 +920,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(newSaveList)) {
|
||||
prodConsRelationService.saveOrUpdateBatch(newSaveList, 100);
|
||||
prodConsRelationService.saveBatch(newSaveList, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user