供应商修改 同步
This commit is contained in:
parent
69ba9ec48c
commit
ffb4a5eb46
|
|
@ -32,6 +32,7 @@ public class ShopVendor implements Serializable {
|
||||||
* 店铺Id
|
* 店铺Id
|
||||||
*/
|
*/
|
||||||
private Long shopId;
|
private Long shopId;
|
||||||
|
private Long syncId;
|
||||||
/**
|
/**
|
||||||
* 排序
|
* 排序
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,12 @@ public interface ShopSyncService {
|
||||||
* @param sourceProdId 主店商品ID
|
* @param sourceProdId 主店商品ID
|
||||||
*/
|
*/
|
||||||
void syncConsProBySourceShop(Long sourceShopId, Long sourceProdId, Long sysUserId);
|
void syncConsProBySourceShop(Long sourceShopId, Long sourceProdId, Long sysUserId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步供应商 开了同步耗材开关的子店铺
|
||||||
|
*
|
||||||
|
* @param sourceShopId 主店ID
|
||||||
|
* @param vendorId 供应商Id
|
||||||
|
*/
|
||||||
|
void syncVendorBySourceShop(Long sourceShopId, Long vendorId, Long sysUserId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||||
private ProdConsRelationService prodConsRelationService;
|
private ProdConsRelationService prodConsRelationService;
|
||||||
@Resource
|
@Resource
|
||||||
private ShopUserService shopUserService;
|
private ShopUserService shopUserService;
|
||||||
|
@Resource
|
||||||
|
private ShopVendorService vendorService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private SyncNoticeService syncNoticeService;
|
private SyncNoticeService syncNoticeService;
|
||||||
|
|
||||||
|
|
@ -154,6 +156,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||||
Map<Long, Long> conGroupMap = syncConsGroup(sourceShopId, targetShopId, mainMapList);
|
Map<Long, Long> conGroupMap = syncConsGroup(sourceShopId, targetShopId, mainMapList);
|
||||||
Map<Long, Long> consInfoMap = syncConsInfo(sourceShopId, targetShopId, conGroupMap, mainMapList);
|
Map<Long, Long> consInfoMap = syncConsInfo(sourceShopId, targetShopId, conGroupMap, mainMapList);
|
||||||
syncConsPro(sourceShopId, targetShopId, consInfoMap, proMap);
|
syncConsPro(sourceShopId, targetShopId, consInfoMap, proMap);
|
||||||
|
syncVendor(sourceShopId, targetShopId, mainMapList);
|
||||||
syncNoticeService.addNotice(targetShopId, sysUserId, "数据同步", JSON.toJSONString(mainMapList), null);
|
syncNoticeService.addNotice(targetShopId, sysUserId, "数据同步", JSON.toJSONString(mainMapList), null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("同步异常", e);
|
log.error("同步异常", e);
|
||||||
|
|
@ -1017,6 +1020,67 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<Long, Long> syncVendor(Long sourceShopId, Long pointShopId, List<Map<String, Object>> mainMapList) {
|
||||||
|
Map<Long, Long> vendorMap = new HashMap<>();
|
||||||
|
List<Long> pointShopVendor = vendorService.queryChain().select(ShopVendor::getSyncId)
|
||||||
|
.eq(ShopVendor::getShopId, pointShopId)
|
||||||
|
.isNotNull(ShopVendor::getSyncId)
|
||||||
|
.listAs(Long.class);
|
||||||
|
|
||||||
|
List<ShopVendor> list = vendorService.queryChain().eq(ShopVendor::getShopId, sourceShopId).list();
|
||||||
|
list.forEach(vendor -> {
|
||||||
|
if (CollUtil.isEmpty(pointShopVendor) || !pointShopVendor.contains(vendor.getId())) {
|
||||||
|
ShopVendor vendorNew = BeanUtil.copyProperties(vendor, ShopVendor.class);
|
||||||
|
vendorNew.setId(null);
|
||||||
|
vendorNew.setSyncId(vendor.getId());
|
||||||
|
vendorNew.setShopId(pointShopId);
|
||||||
|
vendorService.save(vendorNew);
|
||||||
|
vendorMap.put(vendor.getId(), vendorNew.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buildNotice(mainMapList, "单位同步", vendorMap.size(), null, null);
|
||||||
|
log.info("供应商同步,源{}个,已有{}个,同步{}个", list.size(), pointShopVendor.size(), vendorMap.size());
|
||||||
|
return vendorMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void syncVendorBySourceShop(Long sourceShopId, Long vendorId, Long sysUserId) {
|
||||||
|
assertAutoSync(sourceShopId);
|
||||||
|
AssertUtil.isNull(vendorId, "{}不能为空", "供应商ID");
|
||||||
|
Set<Long> shopIds = checkSourceShopInfo(sourceShopId, 2);
|
||||||
|
if (CollUtil.isEmpty(shopIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopVendor mainVendor = vendorService.getById(vendorId);
|
||||||
|
AssertUtil.isNull(mainVendor, "需要同步的{}不存在", "单位");
|
||||||
|
List<ShopVendor> list = vendorService.queryChain().eq(ShopVendor::getSyncId, vendorId).in(ShopVendor::getShopId, shopIds).list();
|
||||||
|
Map<Long, ShopVendor> map = new HashMap<>();
|
||||||
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
|
map = list.stream().collect(Collectors.toMap(ShopVendor::getShopId, t -> t));
|
||||||
|
}
|
||||||
|
Map<Long, ShopVendor> finalMap = map;
|
||||||
|
shopIds.forEach(shopId -> {
|
||||||
|
List<Map<String, Object>> mainMapList = new ArrayList<>();
|
||||||
|
Map<Long, String> vendorDataMap = new HashMap<>();
|
||||||
|
ShopVendor newVendor = BeanUtil.copyProperties(mainVendor, ShopVendor.class);
|
||||||
|
|
||||||
|
newVendor.setSyncId(mainVendor.getId());
|
||||||
|
newVendor.setShopId(shopId);
|
||||||
|
if (finalMap.containsKey(shopId)) {
|
||||||
|
ShopVendor vendor = finalMap.get(shopId);
|
||||||
|
newVendor.setId(vendor.getId());
|
||||||
|
vendorService.updateById(newVendor);
|
||||||
|
} else {
|
||||||
|
newVendor.setId(null);
|
||||||
|
vendorService.save(newVendor);
|
||||||
|
}
|
||||||
|
vendorDataMap.put(newVendor.getId(), newVendor.getName());
|
||||||
|
buildNotice(mainMapList, "供应商变动", 1, "vendor", vendorDataMap);
|
||||||
|
syncNoticeService.addNotice(shopId, sysUserId, "数据变动", JSON.toJSONString(mainMapList), JSON.toJSONString(newVendor));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 断言是否支持自动同步
|
* 断言是否支持自动同步
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `tb_shop_vendor`
|
||||||
|
ADD COLUMN `sync_id` bigint NULL DEFAULT NULL COMMENT '同步Id' AFTER `id`;
|
||||||
Loading…
Reference in New Issue