Commit 8dda3e04 by fudahua

批量处理关联关系

parent e10a5b4c
...@@ -113,15 +113,16 @@ public class StoreRangeServiceImpl implements StoreRangeService { ...@@ -113,15 +113,16 @@ public class StoreRangeServiceImpl implements StoreRangeService {
return true; return true;
} }
String enterpriseId = list.get(0).getEnterpriseId(); String enterpriseId = list.get(0).getEnterpriseId();
//导购绑定列表 容错处理 //更新前绑定门店列表
List<StaffClerkRelationDTO> staffClerkRelationDTOS = staffClerkRelationService.listBindStoreIdByEnterpriseId(enterpriseId); List<TabStoreRelation> storeRelations = tabHaobanStoreRelationMapper.listStoreRange(enterpriseId);
Map<String, Set<String>> oldStaffStoreIdByWxEidMap = staffClerkRelationDTOS.stream().collect(Collectors.groupingBy(StaffClerkRelationDTO::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet()))); Map<String, Set<String>> oldStoreIdByMap = storeRelations.stream().collect(Collectors.groupingBy(TabStoreRelation::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet())));
//根据wxEnterpriseId 分组 //根据wxEnterpriseId 分组
Map<String, Set<String>> newStoreIdBywxEnterpriseMap = list.stream().collect(Collectors.groupingBy(TabStoreRelation::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet()))); Map<String, Set<String>> newStoreIdBywxEnterpriseMap = list.stream().collect(Collectors.groupingBy(TabStoreRelation::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet())));
//所有就的门店old绑定列表 //所有就的门店old绑定列表
Map<String, Set<String>> oldStoreIdBywxEnterpriseMap = getOldStoreIdsByWxEnterpriseId(enterpriseId, oldStaffStoreIdByWxEidMap); Map<String, Set<String>> oldStoreIdBywxEnterpriseMap = getOldStoreIdsByWxEnterpriseId(enterpriseId, oldStoreIdByMap);
//需要解绑门店 //需要解绑门店
Set<String> needUnBindStoreIds = new HashSet<>(); Set<String> needUnBindStoreIds = new HashSet<>();
...@@ -141,7 +142,7 @@ public class StoreRangeServiceImpl implements StoreRangeService { ...@@ -141,7 +142,7 @@ public class StoreRangeServiceImpl implements StoreRangeService {
needUnBindStoreIds.addAll(mid); needUnBindStoreIds.addAll(mid);
//需要新增 //需要新增
Set<String> old = oldStaffStoreIdByWxEidMap.get(wxEid); Set<String> old = oldStoreIdByMap.get(wxEid);
if (CollectionUtils.isEmpty(old)) { if (CollectionUtils.isEmpty(old)) {
needAddStoreIds.addAll(newStoreIds); needAddStoreIds.addAll(newStoreIds);
return; return;
...@@ -176,8 +177,6 @@ public class StoreRangeServiceImpl implements StoreRangeService { ...@@ -176,8 +177,6 @@ public class StoreRangeServiceImpl implements StoreRangeService {
tabHaobanStoreRelationMapper.deleteStoreRalationByStoreIds(enterpriseId, delStoreIds); tabHaobanStoreRelationMapper.deleteStoreRalationByStoreIds(enterpriseId, delStoreIds);
} }
if (CollectionUtils.isNotEmpty(addStoreIds)) { if (CollectionUtils.isNotEmpty(addStoreIds)) {
insertStoreRelationBatch(storeRelations);
} else {
List<TabStoreRelation> adds = storeRelations.stream().filter(dto -> addStoreIds.contains(dto.getStoreId())).collect(Collectors.toList()); List<TabStoreRelation> adds = storeRelations.stream().filter(dto -> addStoreIds.contains(dto.getStoreId())).collect(Collectors.toList());
//批量插入 //批量插入
insertStoreRelationBatch(adds); insertStoreRelationBatch(adds);
...@@ -208,20 +207,20 @@ public class StoreRangeServiceImpl implements StoreRangeService { ...@@ -208,20 +207,20 @@ public class StoreRangeServiceImpl implements StoreRangeService {
* @param enterpriseId * @param enterpriseId
* @return * @return
*/ */
private Map<String, Set<String>> getOldStoreIdsByWxEnterpriseId(String enterpriseId, Map<String, Set<String>> oldStaffStoreIdByWxEidMap) { private Map<String, Set<String>> getOldStoreIdsByWxEnterpriseId(String enterpriseId, Map<String, Set<String>> oldStoreIdBywxEnterpriseMap) {
Map<String, Set<String>> ret = new HashMap<>(); Map<String, Set<String>> ret = new HashMap<>();
Set<String> wxEnterpriseIds = new HashSet<>(); Set<String> wxEnterpriseIds = new HashSet<>();
//更新前绑定门店列表 // //更新前绑定门店列表
List<TabStoreRelation> storeRelations = tabHaobanStoreRelationMapper.listStoreRange(enterpriseId); // List<TabStoreRelation> storeRelations = tabHaobanStoreRelationMapper.listStoreRange(enterpriseId);
Map<String, Set<String>> oldStoreIdBywxEnterpriseMap = storeRelations.stream().collect(Collectors.groupingBy(TabStoreRelation::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet()))); // Map<String, Set<String>> oldStoreIdBywxEnterpriseMap = storeRelations.stream().collect(Collectors.groupingBy(TabStoreRelation::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet())));
if (CollectionUtils.isNotEmpty(storeRelations)) { if (oldStoreIdBywxEnterpriseMap != null && oldStoreIdBywxEnterpriseMap.size() > 0) {
wxEnterpriseIds.addAll(oldStoreIdBywxEnterpriseMap.keySet()); wxEnterpriseIds.addAll(oldStoreIdBywxEnterpriseMap.keySet());
} }
//导购绑定列表 //导购绑定列表
// List<StaffClerkRelationDTO> staffClerkRelationDTOS = staffClerkRelationService.listBindStoreIdByEnterpriseId(enterpriseId); List<StaffClerkRelationDTO> staffClerkRelationDTOS = staffClerkRelationService.listBindStoreIdByEnterpriseId(enterpriseId);
// Map<String, Set<String>> oldStaffStoreIdByWxEidMap = staffClerkRelationDTOS.stream().collect(Collectors.groupingBy(StaffClerkRelationDTO::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet()))); Map<String, Set<String>> oldStaffStoreIdByWxEidMap = staffClerkRelationDTOS.stream().collect(Collectors.groupingBy(StaffClerkRelationDTO::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet())));
if (oldStaffStoreIdByWxEidMap != null && oldStaffStoreIdByWxEidMap.size() > 0) { if (oldStaffStoreIdByWxEidMap != null && oldStaffStoreIdByWxEidMap.size() > 0) {
wxEnterpriseIds.addAll(oldStaffStoreIdByWxEidMap.keySet()); wxEnterpriseIds.addAll(oldStaffStoreIdByWxEidMap.keySet());
} }
......
...@@ -59,18 +59,21 @@ public class ServiceTest { ...@@ -59,18 +59,21 @@ public class ServiceTest {
@Test @Test
public void test11() { public void test11() {
FlushStoreMqDTO flushStoreMqDTO = new FlushStoreMqDTO(); // FlushStoreMqDTO flushStoreMqDTO = new FlushStoreMqDTO();
flushStoreMqDTO.setEnterpriseId("testEnteroriseId"); // flushStoreMqDTO.setEnterpriseId("testEnteroriseId");
int i = 2; // int i = 2;
while (i-- > 0) { // while (i-- > 0) {
try { // try {
Thread.sleep(1000); // Thread.sleep(1000);
} catch (InterruptedException e) { // } catch (InterruptedException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
wxEnterpriseRelatedApiService.flushBindStoreByEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000", // wxEnterpriseRelatedApiService.flushBindStoreByEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000",
"-1", "-1", ChannelCodeEnum.SYNC_UNBIND.getCode()); // "-1", "-1", ChannelCodeEnum.SYNC_UNBIND.getCode());
} // }
wxEnterpriseRelatedApiService.flushBindStoreByEnterpriseId("ff808081593917d90159398ec6340012",
"ca66a01b79474c40b3e7c7f93daf1a3b", "-1", ChannelCodeEnum.SYNC_UNBIND.getCode());
// List<String> ids = new ArrayList<>(); // List<String> ids = new ArrayList<>();
// ids.add("8f5ddb9df0a54332acfa2d5804e90c64"); // ids.add("8f5ddb9df0a54332acfa2d5804e90c64");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment