|
|
@@ -31,6 +31,7 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService |
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
@Override |
|
|
@Override |
|
|
public ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, TenantEntity tenantEntity) { |
|
|
public ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, TenantEntity tenantEntity) { |
|
|
|
|
|
tenantEntity.setTenantId("789"); |
|
|
if (regionId == null) { |
|
|
if (regionId == null) { |
|
|
return new ResultData(Result.ERROR, "区域商户id不能为空"); |
|
|
return new ResultData(Result.ERROR, "区域商户id不能为空"); |
|
|
} |
|
|
} |
|
|
@@ -38,34 +39,47 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService |
|
|
//如果没选择普通商户,删除所有关系 |
|
|
//如果没选择普通商户,删除所有关系 |
|
|
if (CollectionUtils.isEmpty(ids)) { |
|
|
if (CollectionUtils.isEmpty(ids)) { |
|
|
wxMerchantRelationMapper.updateByReginId(regionId); |
|
|
wxMerchantRelationMapper.updateByReginId(regionId); |
|
|
return new ResultData(Result.SUCCESS, "编辑成功", null); |
|
|
|
|
|
|
|
|
return new ResultData(Result.SUCCESS, "成功", null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 |
|
|
//先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 |
|
|
List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByIds(ids); |
|
|
|
|
|
|
|
|
List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByRegionId(regionId); |
|
|
List<Long> updateList = new ArrayList<>(); |
|
|
List<Long> updateList = new ArrayList<>(); |
|
|
|
|
|
List<Long> deleteList = new ArrayList<>(); |
|
|
|
|
|
List<Long> insertList = new ArrayList<>(); |
|
|
if (!CollectionUtils.isEmpty(infByIds)) { |
|
|
if (!CollectionUtils.isEmpty(infByIds)) { |
|
|
List<Long> alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0 && !ids.contains(x.getMerchantId())).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
|
|
//如果已经存在就返回 |
|
|
|
|
|
if (!CollectionUtils.isEmpty(alreadyList)){ |
|
|
|
|
|
return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); |
|
|
|
|
|
|
|
|
List<Long> alreadyList = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
|
|
List<Long> list = ids.parallelStream().filter(x -> !alreadyList.contains(x)).collect(Collectors.toList()); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(list)){ |
|
|
|
|
|
insertList = list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//如果存在且是同一个区域商户下就 修改 是否删除字段 |
|
|
//如果存在且是同一个区域商户下就 修改 是否删除字段 |
|
|
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> update = infByIds.parallelStream().filter(x -> x.getIsDel() == 1 && x.getRegionMerchantId().equals(regionId) && ids.contains(x.getMerchantId())).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(update)) { |
|
|
|
|
|
updateList = update; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//删除商户 |
|
|
|
|
|
List<Long> del = infByIds.parallelStream().filter(x -> x.getIsDel() == 0 && !ids.contains(x.getMerchantId()) && x.getRegionMerchantId().equals(regionId)).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(del)) { |
|
|
|
|
|
deleteList = del; |
|
|
} |
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
insertList = ids; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
List<Long> finalList = updateList; |
|
|
|
|
|
List<Long> alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); |
|
|
|
|
|
List<Long> insertList = ids.parallelStream().filter(x -> !finalList.contains(x) && !alreadyList.contains(x)).collect(Collectors.toList()); |
|
|
|
|
|
if (!CollectionUtils.isEmpty(updateList)) { |
|
|
if (!CollectionUtils.isEmpty(updateList)) { |
|
|
wxMerchantRelationMapper.updateByMerchantIds(updateList,regionId); |
|
|
|
|
|
|
|
|
wxMerchantRelationMapper.updateByMerchantIds(updateList, regionId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(deleteList)) { |
|
|
|
|
|
wxMerchantRelationMapper.deleteByMerchantIds(deleteList, regionId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(insertList)) { |
|
|
if (!CollectionUtils.isEmpty(insertList)) { |
|
|
List<WxMerchantRelation> list = new ArrayList<>(); |
|
|
List<WxMerchantRelation> list = new ArrayList<>(); |
|
|
for (Long id : ids) { |
|
|
|
|
|
|
|
|
for (Long id : insertList) { |
|
|
WxMerchantRelation relation = new WxMerchantRelation(); |
|
|
WxMerchantRelation relation = new WxMerchantRelation(); |
|
|
relation.setId(IdWorker.get().nextId()); |
|
|
relation.setId(IdWorker.get().nextId()); |
|
|
relation.setMerchantId(id); |
|
|
relation.setMerchantId(id); |
|
|
|