|
|
@ -290,4 +290,256 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<AreaCodeDictResultDTO> areaCodeDictTreePlus(AreaCodeDictFormDTO formDTO){ |
|
|
|
List<AreaCodeDictResultDTO> tree = new ArrayList<>(); |
|
|
|
String s = areaCodeRedis.get(AreaCodeConstant.THREE_SCREEN_TREE); |
|
|
|
if (StringUtils.isNotBlank(s)){ |
|
|
|
tree = JSON.parseArray(s,AreaCodeDictResultDTO.class); |
|
|
|
}else { |
|
|
|
List<AreaCodeDictResultDTO> threeTree = beforeThreeTree(); |
|
|
|
areaCodeRedis.set(AreaCodeConstant.THREE_SCREEN_TREE,threeTree); |
|
|
|
tree = threeTree; |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(formDTO.getRootAreaCode())){ |
|
|
|
return tree; |
|
|
|
} |
|
|
|
// 传参为街道-社区级
|
|
|
|
if (formDTO.getRootAreaLevel().equals(AreaCodeConstant.STREET) || formDTO.getRootAreaLevel().equals(AreaCodeConstant.COMMUNITY)){ |
|
|
|
tree = disposeAfterTwoLevel(formDTO); |
|
|
|
}else if (formDTO.getRootAreaLevel().equals(AreaCodeConstant.PROVINCE) || formDTO.getRootAreaLevel().equals(AreaCodeConstant.CITY) || formDTO.getRootAreaLevel().equals(AreaCodeConstant.DISTRICT)){ |
|
|
|
tree = disposeBeforeThreeLevelFinal(formDTO,tree); |
|
|
|
} |
|
|
|
return tree; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 省市区三级联动查询 |
|
|
|
* @Param |
|
|
|
* @author zxc |
|
|
|
* @date 2021/1/11 上午9:35 |
|
|
|
*/ |
|
|
|
public List<AreaCodeDictResultDTO> beforeThreeTree(){ |
|
|
|
// 查询所有省市区
|
|
|
|
List<AreaCodeDTO> areaCodeDTOS = baseDao.selectAllArea(); |
|
|
|
Map<String, List<AreaCodeDTO>> groupByCity = areaCodeDTOS.stream().collect(Collectors.groupingBy(AreaCodeDTO::getCityCode)); |
|
|
|
Map<String, List<AreaCodeDTO>> groupByProvince = areaCodeDTOS.stream().collect(Collectors.groupingBy(AreaCodeDTO::getProvinceCode)); |
|
|
|
List<AreaCodeDictResultDTO> result = new ArrayList<>(); |
|
|
|
List<AreaCodeDictResultDTO> cityResult = new ArrayList<>(); |
|
|
|
groupByCity.forEach((c, v) -> { |
|
|
|
AreaCodeDictResultDTO cityDto = new AreaCodeDictResultDTO(); |
|
|
|
cityDto.setName(v.get(NumConstant.ZERO).getCityName()); |
|
|
|
cityDto.setCode(v.get(NumConstant.ZERO).getCityCode()); |
|
|
|
cityDto.setParentCode(v.get(NumConstant.ZERO).getProvinceCode()); |
|
|
|
List<AreaCodeDictResultDTO> threeResult = new ArrayList<>(); |
|
|
|
v.forEach(three -> { |
|
|
|
AreaCodeDictResultDTO dto = new AreaCodeDictResultDTO(); |
|
|
|
dto.setCode(three.getCountyCode()); |
|
|
|
dto.setName(three.getCountyName()); |
|
|
|
threeResult.add(dto); |
|
|
|
}); |
|
|
|
List<AreaCodeDictResultDTO> threeSort = threeResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList()); |
|
|
|
cityDto.setChildren(threeSort); |
|
|
|
cityResult.add(cityDto); |
|
|
|
}); |
|
|
|
groupByProvince.forEach((p,v) -> { |
|
|
|
AreaCodeDictResultDTO dto = new AreaCodeDictResultDTO(); |
|
|
|
dto.setCode(p); |
|
|
|
dto.setName(v.get(NumConstant.ZERO).getProvinceName()); |
|
|
|
List<AreaCodeDictResultDTO> cityOnceResult = new ArrayList<>(); |
|
|
|
cityResult.forEach(c -> { |
|
|
|
if (dto.getCode().equals(c.getParentCode())){ |
|
|
|
cityOnceResult.add(c); |
|
|
|
} |
|
|
|
}); |
|
|
|
List<AreaCodeDictResultDTO> citySort = cityOnceResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList()); |
|
|
|
dto.setChildren(citySort); |
|
|
|
result.add(dto); |
|
|
|
}); |
|
|
|
List<AreaCodeDictResultDTO> collect = result.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList()); |
|
|
|
return collect; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 街道-社区组织树查询 |
|
|
|
* @Param |
|
|
|
* @author zxc |
|
|
|
* @date 2021/1/11 上午9:48 |
|
|
|
*/ |
|
|
|
public List<AreaCodeDictResultDTO> afterTwoTree(){ |
|
|
|
// 查询所有街道、社区
|
|
|
|
List<AreaCodeChildDTO> areaCodeChildDTOS = childDao.selectAllChild(); |
|
|
|
List<AreaCodeDictResultDTO> fourResult = new ArrayList<>(); |
|
|
|
// 街道-社区
|
|
|
|
Map<Integer, List<AreaCodeChildDTO>> groupByLevel = areaCodeChildDTOS.stream().collect(Collectors.groupingBy(AreaCodeChildDTO::getLevel)); |
|
|
|
List<AreaCodeChildDTO> levelFive = groupByLevel.get(NumConstant.FIVE); |
|
|
|
Map<String, List<AreaCodeChildDTO>> groupByPCode = levelFive.stream().collect(Collectors.groupingBy(AreaCodeChildDTO::getPCode)); |
|
|
|
List<AreaCodeChildDTO> levelFour = groupByLevel.get(NumConstant.FOUR); |
|
|
|
levelFour.forEach(four -> { |
|
|
|
AreaCodeDictResultDTO dto = new AreaCodeDictResultDTO(); |
|
|
|
dto.setCode(four.getCode()); |
|
|
|
dto.setName(four.getName()); |
|
|
|
dto.setParentCode(four.getPCode()); |
|
|
|
groupByPCode.forEach((pCode,v) -> { |
|
|
|
if (dto.getCode().equals(pCode)){ |
|
|
|
List<AreaCodeDictResultDTO> fiveResult = new ArrayList<>(); |
|
|
|
v.forEach(five -> { |
|
|
|
AreaCodeDictResultDTO fiveDto = new AreaCodeDictResultDTO(); |
|
|
|
fiveDto.setCode(five.getCode()); |
|
|
|
fiveDto.setName(five.getName()); |
|
|
|
fiveResult.add(fiveDto); |
|
|
|
}); |
|
|
|
List<AreaCodeDictResultDTO> fiveSort = fiveResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList()); |
|
|
|
dto.setChildren(fiveSort); |
|
|
|
} |
|
|
|
}); |
|
|
|
fourResult.add(dto); |
|
|
|
}); |
|
|
|
List<AreaCodeDictResultDTO> collect = fourResult.stream().sorted(Comparator.comparing(AreaCodeDictResultDTO::getCode)).collect(Collectors.toList()); |
|
|
|
return collect; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 街道-社区组织树处理 |
|
|
|
* @Param form |
|
|
|
* @author zxc |
|
|
|
* @date 2021/1/11 上午9:58 |
|
|
|
*/ |
|
|
|
public List<AreaCodeDictResultDTO> disposeAfterTwoLevel(AreaCodeDictFormDTO form){ |
|
|
|
List<AreaCodeDictResultDTO> result = new ArrayList<>(); |
|
|
|
List<AreaCodeDictResultDTO> areaCodeDictResultDTOS = afterTwoTree(); |
|
|
|
if (CollectionUtils.isEmpty(areaCodeDictResultDTOS)){ |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
if (form.getRootAreaLevel().equals(AreaCodeConstant.STREET)){ |
|
|
|
for (AreaCodeDictResultDTO dto : areaCodeDictResultDTOS) { |
|
|
|
if (dto.getCode().equals(form.getRootAreaCode())){ |
|
|
|
result.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
for (AreaCodeDictResultDTO dto : areaCodeDictResultDTOS) { |
|
|
|
if (!CollectionUtils.isEmpty(dto.getChildren())){ |
|
|
|
for (AreaCodeDictResultDTO child : dto.getChildren()) { |
|
|
|
if (child.getCode().equals(form.getRootAreaCode())){ |
|
|
|
result.add(child); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 省市区获取 |
|
|
|
* @Param form |
|
|
|
* @Param tree |
|
|
|
* @author zxc |
|
|
|
* @date 2021/1/12 上午9:22 |
|
|
|
*/ |
|
|
|
public List<AreaCodeDictResultDTO> disposeBeforeThreeLevel(AreaCodeDictFormDTO form,List<AreaCodeDictResultDTO> tree){ |
|
|
|
List<AreaCodeDictResultDTO> result = new ArrayList<>(); |
|
|
|
if (CollectionUtils.isEmpty(tree)){ |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
if (form.getRootAreaLevel().equals(AreaCodeConstant.PROVINCE)){ |
|
|
|
for (AreaCodeDictResultDTO dto : tree) { |
|
|
|
if (dto.getCode().equals(form.getRootAreaCode())){ |
|
|
|
result.add(dto); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
}else if (form.getRootAreaLevel().equals(AreaCodeConstant.CITY)){ |
|
|
|
for (AreaCodeDictResultDTO dto : tree) { |
|
|
|
if (!CollectionUtils.isEmpty(dto.getChildren())){ |
|
|
|
for (AreaCodeDictResultDTO city : dto.getChildren()) { |
|
|
|
if (city.getCode().equals(form.getRootAreaCode())){ |
|
|
|
result.add(city); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else if (form.getRootAreaLevel().equals(AreaCodeConstant.DISTRICT)){ |
|
|
|
for (AreaCodeDictResultDTO dto : tree) { |
|
|
|
if (!CollectionUtils.isEmpty(dto.getChildren())){ |
|
|
|
for (AreaCodeDictResultDTO city : dto.getChildren()) { |
|
|
|
if (!CollectionUtils.isEmpty(city.getChildren())){ |
|
|
|
for (AreaCodeDictResultDTO child : city.getChildren()) { |
|
|
|
if (child.getCode().equals(form.getRootAreaCode())){ |
|
|
|
result.add(child); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 拼接 街道-社区 |
|
|
|
* @Param form |
|
|
|
* @Param tree |
|
|
|
* @author zxc |
|
|
|
* @date 2021/1/12 上午9:21 |
|
|
|
*/ |
|
|
|
public List<AreaCodeDictResultDTO> disposeBeforeThreeLevelFinal(AreaCodeDictFormDTO form,List<AreaCodeDictResultDTO> tree){ |
|
|
|
List<AreaCodeDictResultDTO> threeDto = disposeBeforeThreeLevel(form, tree); |
|
|
|
List<AreaCodeDictResultDTO> twoDto = afterTwoTree(); |
|
|
|
if (CollectionUtils.isEmpty(threeDto)){ |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(twoDto)){ |
|
|
|
if (form.getRootAreaLevel().equals(AreaCodeConstant.PROVINCE)){ |
|
|
|
for (AreaCodeDictResultDTO dto : tree) { |
|
|
|
if (dto.getCode().equals(form.getRootAreaCode())){ |
|
|
|
if (!CollectionUtils.isEmpty(dto.getChildren())){ |
|
|
|
for (AreaCodeDictResultDTO city : dto.getChildren()) { |
|
|
|
if (!CollectionUtils.isEmpty(city.getChildren())){ |
|
|
|
for (AreaCodeDictResultDTO child : city.getChildren()) { |
|
|
|
List<AreaCodeDictResultDTO> areaList = new ArrayList<>(); |
|
|
|
for (AreaCodeDictResultDTO area : twoDto) { |
|
|
|
if (child.getCode().equals(area.getParentCode())){ |
|
|
|
areaList.add(area); |
|
|
|
} |
|
|
|
} |
|
|
|
child.setChildren(areaList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else if (form.getRootAreaLevel().equals(AreaCodeConstant.CITY)){ |
|
|
|
for (AreaCodeDictResultDTO dto : threeDto) { |
|
|
|
if (!CollectionUtils.isEmpty(dto.getChildren())){ |
|
|
|
for (AreaCodeDictResultDTO child : dto.getChildren()) { |
|
|
|
List<AreaCodeDictResultDTO> areaList = new ArrayList<>(); |
|
|
|
for (AreaCodeDictResultDTO area : twoDto) { |
|
|
|
if (child.getCode().equals(area.getParentCode())){ |
|
|
|
areaList.add(area); |
|
|
|
} |
|
|
|
} |
|
|
|
child.setChildren(areaList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
for (AreaCodeDictResultDTO dto : threeDto) { |
|
|
|
List<AreaCodeDictResultDTO> areaList = new ArrayList<>(); |
|
|
|
for (AreaCodeDictResultDTO area : twoDto) { |
|
|
|
if (dto.getCode().equals(area.getParentCode())){ |
|
|
|
areaList.add(area); |
|
|
|
} |
|
|
|
} |
|
|
|
dto.setChildren(areaList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return threeDto; |
|
|
|
} |
|
|
|
} |