Commit 8dda3e04 by fudahua

批量处理关联关系

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