|
|
|
@@ -43,31 +43,29 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService |
|
|
|
|
|
|
|
//先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 |
|
|
|
List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByIds(ids); |
|
|
|
List<Long> list = new ArrayList<>(); |
|
|
|
List<Long> updateList = new ArrayList<>(); |
|
|
|
if (!CollectionUtils.isEmpty(infByIds)) { |
|
|
|
list = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
//判断子商户是否已经被选了 |
|
|
|
Integer integer = wxMerchantRelationMapper.selectByIds(list); |
|
|
|
if (integer > 0) { |
|
|
|
List<Long> alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
//如果已经存在就返回 |
|
|
|
if (!CollectionUtils.isEmpty(alreadyList)){ |
|
|
|
return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); |
|
|
|
} |
|
|
|
//如果存在且是同一个区域商户下就 修改 是否删除字段 |
|
|
|
List<Long> delList = infByIds.parallelStream().filter(x -> x.getIsDel() == 1 && x.getRegionMerchantId().equals(regionId)).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
if (!CollectionUtils.isEmpty(delList)){ |
|
|
|
updateList = delList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<Long> finalList = list; |
|
|
|
List<Long> collected = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); |
|
|
|
//1-新增 2-修改 |
|
|
|
if (type == 1) { |
|
|
|
//选择就插入 |
|
|
|
insertInfo(regionId, ids, tenantId); |
|
|
|
return new ResultData(Result.SUCCESS, "新增成功", null); |
|
|
|
} else if (type == 2) { |
|
|
|
wxMerchantRelationMapper.updateByMerchantIds(list); |
|
|
|
if (!CollectionUtils.isEmpty(collected)){ |
|
|
|
insertInfo(regionId, collected, tenantId); |
|
|
|
} |
|
|
|
return new ResultData(Result.SUCCESS, "编辑成功", null); |
|
|
|
List<Long> finalList = updateList; |
|
|
|
List<Long> insertList = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); |
|
|
|
if (!CollectionUtils.isEmpty(updateList)) { |
|
|
|
wxMerchantRelationMapper.updateByMerchantIds(updateList,regionId); |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(insertList)) { |
|
|
|
insertInfo(regionId, insertList, tenantId); |
|
|
|
} |
|
|
|
return null; |
|
|
|
return new ResultData(Result.SUCCESS, "编辑成功", null); |
|
|
|
} |
|
|
|
|
|
|
|
public void insertInfo(Long regionId, List<Long> ids, String tenantId) { |
|
|
|
@@ -77,7 +75,6 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService |
|
|
|
relation.setId(IdWorker.get().nextId()); |
|
|
|
relation.setMerchantId(id); |
|
|
|
relation.setRegionMerchantId(regionId); |
|
|
|
relation.setIsDel(0); |
|
|
|
relation.setTenantId(tenantId); |
|
|
|
list.add(relation); |
|
|
|
} |
|
|
|
|