查询条件有多个,但对应数据库就1个字段,此时,查询条件需要取交集。
Collection<String> districtCodes = queryPageDTO.getDistrictCodes();标签:cityCodes,交集,CollectionUtils,list,查询,add,isEmpty,tempList From: https://www.cnblogs.com/maohuidong/p/18320839
Set<String> levelCityCodes = handleCityLevel(queryPageDTO);
Set<String> levelRegionCityCodes = handleCityLevelRegion(queryPageDTO);
// 3个List取交集(但不包含空)
List<Collection<String>> tempList = new ArrayList<>();
if(!CollectionUtils.isEmpty(districtCodes)){
tempList.add(districtCodes);
}
if(!CollectionUtils.isEmpty(levelCityCodes)){
tempList.add(levelCityCodes);
}
if(!CollectionUtils.isEmpty(levelRegionCityCodes)){
tempList.add(levelRegionCityCodes);
}
Collection<String> cityCodes = new HashSet<>();
if(!CollectionUtils.isEmpty(tempList)){
cityCodes = tempList.get(0);
for(int i = 1;i < tempList.size();i++){
cityCodes.retainAll(tempList.get(i));
}
// 取交集为空的情况下,默认一个值,查询不到
if(CollectionUtils.isEmpty(cityCodes)){
cityCodes.add("-1");
}
}
queryPageDTO.setDistrictCodes(cityCodes);