|
|
|
|
@@ -18,6 +18,7 @@ import com.czg.exception.CzgException;
|
|
|
|
|
import com.czg.product.entity.*;
|
|
|
|
|
import com.czg.product.service.*;
|
|
|
|
|
import com.czg.product.vo.ProductGroupVo;
|
|
|
|
|
import com.czg.sa.StpKit;
|
|
|
|
|
import com.czg.utils.AssertUtil;
|
|
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
@@ -125,6 +126,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
Map<Long, Long> proMap = new HashMap<>();
|
|
|
|
|
Map<Long, Long> skuMap = new HashMap<>();
|
|
|
|
|
checkShopInfo(sourceShopId, targetShopId);
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
//商品
|
|
|
|
|
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
|
|
|
|
|
CompletableFuture<Map<Long, Long>> futureUnit = CompletableFuture.supplyAsync(() -> syncUnit(sourceShopId, targetShopId), executor);
|
|
|
|
|
@@ -135,22 +137,55 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
allFutures.join();
|
|
|
|
|
|
|
|
|
|
unitMap = futureUnit.join();
|
|
|
|
|
buildNotice(mainMapList, "单位同步", unitMap.size(), null);
|
|
|
|
|
specMap = futureSpec.join();
|
|
|
|
|
buildNotice(mainMapList, "规格同步", specMap.size(), null);
|
|
|
|
|
categoryMap = futureCategory.join();
|
|
|
|
|
buildNotice(mainMapList, "分类同步", categoryMap.size(), null);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("同步异常", e);
|
|
|
|
|
throw new CzgException("同步失败");
|
|
|
|
|
}
|
|
|
|
|
proMap = syncProduct(sourceShopId, targetShopId, unitMap, specMap, categoryMap);
|
|
|
|
|
buildNotice(mainMapList, "商品同步", proMap.size(), null);
|
|
|
|
|
skuMap = syncSku(sourceShopId, targetShopId, proMap);
|
|
|
|
|
syncGroup(sourceShopId, targetShopId, proMap);
|
|
|
|
|
Map<Long, Long> groupMap = syncGroup(sourceShopId, targetShopId, proMap);
|
|
|
|
|
buildNotice(mainMapList, "分组同步", groupMap.size(), null);
|
|
|
|
|
syncProductPackage(targetShopId, proMap, skuMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//耗材
|
|
|
|
|
Map<Long, Long> conGroupMap = syncConsGroup(sourceShopId, targetShopId);
|
|
|
|
|
buildNotice(mainMapList, "耗材分组同步", conGroupMap.size(), null);
|
|
|
|
|
Map<Long, Long> consInfoMap = syncConsInfo(sourceShopId, targetShopId, conGroupMap);
|
|
|
|
|
buildNotice(mainMapList, "耗材信息同步", consInfoMap.size(), null);
|
|
|
|
|
syncConsPro(sourceShopId, targetShopId, consInfoMap, proMap);
|
|
|
|
|
syncNoticeService.addNotice(targetShopId, StpKit.USER.getLoginIdAsLong(), "数据同步", JSON.toJSONString(mainMapList), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构建消息
|
|
|
|
|
*
|
|
|
|
|
* @param mainMapList 主消息集合
|
|
|
|
|
* @param title 内容title "XX同步/变动",//商品 单位 规格 分组 耗材 耗材分组
|
|
|
|
|
* @param size 变动数量
|
|
|
|
|
* @param dataMap 变动数据集合<Id,名称>
|
|
|
|
|
*/
|
|
|
|
|
private void buildNotice(List<Map<String, Object>> mainMapList, String title, int size, Map<Long, String> dataMap) {
|
|
|
|
|
Map<String, Object> mainJsonMap = new HashMap<>();
|
|
|
|
|
mainJsonMap.put("title", title);
|
|
|
|
|
mainJsonMap.put("number", size + "个");
|
|
|
|
|
if (CollUtil.isNotEmpty(dataMap)) {
|
|
|
|
|
List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
|
|
dataMap.forEach((k, v) -> {
|
|
|
|
|
Map<String, Object> innerMap = new HashMap<>();
|
|
|
|
|
innerMap.put("id", k);
|
|
|
|
|
innerMap.put("name", v);
|
|
|
|
|
mapList.add(innerMap);
|
|
|
|
|
});
|
|
|
|
|
mainJsonMap.put("map", mapList);
|
|
|
|
|
}
|
|
|
|
|
mainMapList.add(mainJsonMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<Long, Long> syncUnit(Long sourceShopId, Long pointShopId) {
|
|
|
|
|
@@ -191,6 +226,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ShopProdUnit> finalMap = map;
|
|
|
|
|
shopIds.forEach(shopId -> {
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
Map<Long, String> unitDataMap = new HashMap<>();
|
|
|
|
|
ShopProdUnit newUnit = BeanUtil.copyProperties(mainUnit, ShopProdUnit.class);
|
|
|
|
|
|
|
|
|
|
newUnit.setSyncId(mainUnit.getId());
|
|
|
|
|
@@ -203,6 +240,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
newUnit.setId(null);
|
|
|
|
|
unitService.save(newUnit);
|
|
|
|
|
}
|
|
|
|
|
unitDataMap.put(newUnit.getId(), newUnit.getName());
|
|
|
|
|
buildNotice(mainMapList, "单位变动", 1, unitDataMap);
|
|
|
|
|
syncNoticeService.addNotice(shopId, StpKit.USER.getLoginIdAsLong(), "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newUnit));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -246,6 +286,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ShopProdSpec> finalMap = map;
|
|
|
|
|
shopIds.forEach(shopId -> {
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
Map<Long, String> dataMap = new HashMap<>();
|
|
|
|
|
ShopProdSpec newEntity = BeanUtil.copyProperties(mainEntity, ShopProdSpec.class);
|
|
|
|
|
newEntity.setSyncId(mainEntity.getId());
|
|
|
|
|
newEntity.setShopId(shopId);
|
|
|
|
|
@@ -257,6 +299,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
newEntity.setId(null);
|
|
|
|
|
specService.save(newEntity);
|
|
|
|
|
}
|
|
|
|
|
dataMap.put(newEntity.getId(), newEntity.getName());
|
|
|
|
|
buildNotice(mainMapList, "规格变动", 1, dataMap);
|
|
|
|
|
syncNoticeService.addNotice(shopId, StpKit.USER.getLoginIdAsLong(), "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newEntity));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -332,6 +377,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ShopProdCategory> finalMap = map;
|
|
|
|
|
for (Long shopId : shopIds) {
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
Map<Long, String> dataMap = new HashMap<>();
|
|
|
|
|
ShopProdCategory newEntity = BeanUtil.copyProperties(mainEntity, ShopProdCategory.class);
|
|
|
|
|
newEntity.setSyncId(mainEntity.getId());
|
|
|
|
|
newEntity.setShopId(shopId);
|
|
|
|
|
@@ -344,6 +391,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
newEntity.setId(null);
|
|
|
|
|
categoryService.save(newEntity);
|
|
|
|
|
}
|
|
|
|
|
dataMap.put(newEntity.getId(), newEntity.getName());
|
|
|
|
|
buildNotice(mainMapList, "分类变动", 1, dataMap);
|
|
|
|
|
syncNoticeService.addNotice(shopId, StpKit.USER.getLoginIdAsLong(), "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newEntity));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -410,6 +460,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
}
|
|
|
|
|
Map<Long, Product> finalMap = map;
|
|
|
|
|
for (Long shopId : shopIds) {
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
Map<Long, String> dataMap = new HashMap<>();
|
|
|
|
|
Product newEntity = BeanUtil.copyProperties(mainEntity, Product.class);
|
|
|
|
|
newEntity.setSyncId(mainEntity.getSyncId());
|
|
|
|
|
newEntity.setShopId(shopId);
|
|
|
|
|
@@ -430,6 +482,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
if ("package".equals(newEntity.getType()) || "coupon".equals(newEntity.getType())) {
|
|
|
|
|
syncProductPackageBySourceShop(newEntity, shopId);
|
|
|
|
|
}
|
|
|
|
|
dataMap.put(newEntity.getId(), newEntity.getName());
|
|
|
|
|
buildNotice(mainMapList, "商品变动", 1, dataMap);
|
|
|
|
|
syncNoticeService.addNotice(shopId, StpKit.USER.getLoginIdAsLong(), "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newEntity));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -485,6 +540,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
}
|
|
|
|
|
List<ProdGroupRelation> groupRelationList = new ArrayList<>();
|
|
|
|
|
for (Long shopId : shopIds) {
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
Map<Long, String> dataMap = new HashMap<>();
|
|
|
|
|
ProdGroup newEntity = BeanUtil.copyProperties(mainEntity, ProdGroup.class);
|
|
|
|
|
newEntity.setSyncId(mainEntity.getId());
|
|
|
|
|
newEntity.setShopId(shopId);
|
|
|
|
|
@@ -496,15 +553,18 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
newEntity.setId(null);
|
|
|
|
|
groupService.save(newEntity);
|
|
|
|
|
}
|
|
|
|
|
dataMap.put(newEntity.getId(), newEntity.getName());
|
|
|
|
|
buildNotice(mainMapList, "分组变动", 1, dataMap);
|
|
|
|
|
syncNoticeService.addNotice(shopId, StpKit.USER.getLoginIdAsLong(), "数据变动", 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)){
|
|
|
|
|
if (CollUtil.isEmpty(oldProdGroup)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Set<Long> oldProds = oldProdGroup.stream().map(ProdGroupRelation::getProductId).collect(Collectors.toSet());
|
|
|
|
|
List<Long> rmIds = productService.queryChain().select(Product::getId).eq(Product::getShopId, shopId)
|
|
|
|
|
.in(Product::getId, oldProds).isNotNull(Product::getSyncId).listAs(Long.class);
|
|
|
|
|
if(CollUtil.isEmpty(rmIds)){
|
|
|
|
|
if (CollUtil.isEmpty(rmIds)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
|
|
@@ -682,6 +742,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ConsGroup> finalMap = map;
|
|
|
|
|
shopIds.forEach(shopId -> {
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
Map<Long, String> dataMap = new HashMap<>();
|
|
|
|
|
ConsGroup newEntity = BeanUtil.copyProperties(mainEntity, ConsGroup.class);
|
|
|
|
|
newEntity.setSyncId(mainEntity.getId());
|
|
|
|
|
newEntity.setShopId(shopId);
|
|
|
|
|
@@ -693,6 +755,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
newEntity.setId(null);
|
|
|
|
|
consGroupService.save(newEntity);
|
|
|
|
|
}
|
|
|
|
|
dataMap.put(newEntity.getId(), newEntity.getName());
|
|
|
|
|
buildNotice(mainMapList, "耗材分组变动", 1, dataMap);
|
|
|
|
|
syncNoticeService.addNotice(shopId, StpKit.USER.getLoginIdAsLong(), "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newEntity));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -737,6 +802,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
}
|
|
|
|
|
Map<Long, ConsInfo> finalMap = map;
|
|
|
|
|
for (Long shopId : shopIds) {
|
|
|
|
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
|
|
|
|
Map<Long, String> dataMap = new HashMap<>();
|
|
|
|
|
ConsInfo newEntity = BeanUtil.copyProperties(mainEntity, ConsInfo.class);
|
|
|
|
|
newEntity.setSyncId(mainEntity.getId());
|
|
|
|
|
newEntity.setShopId(shopId);
|
|
|
|
|
@@ -754,6 +821,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|
|
|
|
newEntity.setStockNumber(BigDecimal.ZERO);
|
|
|
|
|
consInfoService.save(newEntity);
|
|
|
|
|
}
|
|
|
|
|
dataMap.put(newEntity.getId(), newEntity.getConName());
|
|
|
|
|
buildNotice(mainMapList, "耗材信息变动", 1, dataMap);
|
|
|
|
|
syncNoticeService.addNotice(shopId, StpKit.USER.getLoginIdAsLong(), "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newEntity));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|