| | |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<SgProjectTreeVO> projectTree() { |
| | | List<SgProjectTreeVO> list = sgProjectInfoMapper.projectTree(); |
| | | // 按省、市、县分组 |
| | | Map<String, Map<String, Map<String, List<SgProjectTreeVO>>>> groupedProjects = list.stream() |
| | | .collect(Collectors.groupingBy(SgProjectTreeVO::getProvinceNm, |
| | | Collectors.groupingBy(SgProjectTreeVO::getCityNm, |
| | | Collectors.groupingBy(SgProjectTreeVO::getCountyNm)))); |
| | | |
| | | // 构建树结构 |
| | | List<SgProjectTreeVO> result = new ArrayList<>(); |
| | | for (Map.Entry<String, Map<String, Map<String, List<SgProjectTreeVO>>>> provinceEntry : groupedProjects.entrySet()) { |
| | | String province = provinceEntry.getKey(); |
| | | Map<String, Map<String, List<SgProjectTreeVO>>> cityMap = provinceEntry.getValue(); |
| | | |
| | | SgProjectTreeVO provinceNode = new SgProjectTreeVO(); |
| | | provinceNode.setProvinceNm(province); |
| | | provinceNode.setChildList(new ArrayList<>()); |
| | | |
| | | for (Map.Entry<String, Map<String, List<SgProjectTreeVO>>> cityEntry : cityMap.entrySet()) { |
| | | String city = cityEntry.getKey(); |
| | | Map<String, List<SgProjectTreeVO>> countyMap = cityEntry.getValue(); |
| | | |
| | | SgProjectTreeVO cityNode = new SgProjectTreeVO(); |
| | | List<String> cityIds = new ArrayList<>(); |
| | | cityNode.setCityNm(city); |
| | | cityNode.setChildList(new ArrayList<>()); |
| | | |
| | | for (Map.Entry<String, List<SgProjectTreeVO>> countyEntry : countyMap.entrySet()) { |
| | | String county = countyEntry.getKey(); |
| | | List<SgProjectTreeVO> countyProjects = countyEntry.getValue(); |
| | | |
| | | SgProjectTreeVO countyNode = new SgProjectTreeVO(); |
| | | countyNode.setCountyNm(county); |
| | | countyNode.setChildList(new ArrayList<>(countyProjects)); |
| | | countyNode.setChildNum((long) countyProjects.size()); |
| | | countyNode.setProjectIds(countyProjects.stream().map(SgProjectTreeVO::getId).collect(Collectors.toList())); |
| | | cityIds.addAll(countyNode.getProjectIds()); |
| | | cityNode.getChildList().add(countyNode); |
| | | } |
| | | |
| | | cityNode.setChildNum((long) cityNode.getChildList().size()); |
| | | cityNode.setProjectIds(cityIds); |
| | | provinceNode.getChildList().add(cityNode); |
| | | } |
| | | |
| | | provinceNode.setChildNum((long) provinceNode.getChildList().size()); |
| | | result.add(provinceNode); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | } |