shenyijian
2024-09-10 9c00c5de75be77dfeb314a6fea96455af7cbf53e
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java
@@ -289,7 +289,7 @@
   @Override
   public IPage<SgProjectInfoVO> progressPage(IPage<SgProjectInfoVO> page, ProjectSearchDTO searchDTO) {
      List<SgProjectInfoVO> list = new ArrayList<>();
         if(!searchDTO.getAdCode().isEmpty()){
         if(StringUtils.isNotBlank(searchDTO.getAdCode())){
            list =   sgProjectInfoMapper.progressList1(page, searchDTO);
         }else {
            list = sgProjectInfoMapper.progressList(page, searchDTO);
@@ -298,7 +298,7 @@
      List<Long> ids = list.stream().map(SgProjectInfoVO::getId).collect(Collectors.toList());
      searchDTO.setProjectIds(ids);
      List<SgProjectInfoDO> projectProgress = new ArrayList<>();
      if(!searchDTO.getAdCode().isEmpty()){
      if(StringUtils.isNotBlank(searchDTO.getAdCode())){
         projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject1(searchDTO));
      }else {
         projectProgress = getProjectProgress(sgProjectInfoMapper.queryStepByProject(searchDTO));
@@ -560,7 +560,7 @@
      Map<String, Object> map  = new HashMap<>();
      List<SgProjectInfoVO> progressList = progressList(searchDTO);
      BigDecimal reduce = progressList.stream().filter(s->s.getProjectProgressNum()!=null).map(SgProjectInfoDO::getProjectProgressNum).reduce(BigDecimal.ZERO, BigDecimal::add);
      BigDecimal divide = reduce.divide(BigDecimal.valueOf(progressList.size()), 2, RoundingMode.HALF_UP);
      BigDecimal divide = reduce.divide(BigDecimal.valueOf(progressList.size()==0?1:progressList.size()), 2, RoundingMode.HALF_UP);
      List<SgProjectInfoDO> pending = progressList.stream().filter(s -> s.getStatus() == 0).collect(Collectors.toList());
      List<SgProjectInfoDO> progress = progressList.stream().filter(s -> s.getStatus() == 1).collect(Collectors.toList());
      List<SgProjectInfoDO> over = progressList.stream().filter(s -> s.getStatus() == 2).collect(Collectors.toList());
@@ -614,64 +614,85 @@
   @Override
   public List<SgProjectTreeVO> projectTree(ProjectSearchDTO dto) {
      List<String> sgCodeS = getSgCodeByUser();
      dto.setSgCodeS(sgCodeS);
      List<SgProjectTreeVO> list =    sgProjectInfoMapper.projectTree(dto);
      if (CollectionUtils.isNotEmpty(list)){
      // 按省、市、县分组
      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.setId(UUID.randomUUID().toString().replace("-",""));
         provinceNode.setRegionName(province);
         provinceNode.setChildList(new ArrayList<>());
         long provinceNum = 0;
         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.setId(UUID.randomUUID().toString().replace("-",""));
            cityNode.setRegionName(city);
            cityNode.setChildList(new ArrayList<>());
            for (Map.Entry<String, List<SgProjectTreeVO>> countyEntry : countyMap.entrySet()) {
               String county = countyEntry.getKey();
               List<SgProjectTreeVO> countyProjects = countyEntry.getValue();
               for (SgProjectTreeVO countyProject : countyProjects) {
                  countyProject.setRegionName(countyProject.getResNm());
         // 按省、片区、市、县、乡镇分组
         Map<String, Map<String, Map<String, Map<String, Map<String, List<SgProjectTreeVO>>>>>> groupedProjects = list.stream()
            .collect(
               Collectors.groupingBy(SgProjectTreeVO::getProvinceNm,
                  Collectors.groupingBy(SgProjectTreeVO::getLot,
                     Collectors.groupingBy(SgProjectTreeVO::getCityNm,
                        Collectors.groupingBy(SgProjectTreeVO::getCountyNm,
                           Collectors.groupingBy(SgProjectTreeVO::getTownNm
                           ))))));
            List<SgProjectTreeVO> tree = new ArrayList<>();
            for (Map.Entry<String, Map<String, Map<String, Map<String, Map<String, List<SgProjectTreeVO>>>>>> provinceEntry : groupedProjects.entrySet()) {
               SgProjectTreeVO provinceNode = new SgProjectTreeVO();
               provinceNode.setProvinceNm(provinceEntry.getKey());
               provinceNode.setRegionName(provinceEntry.getKey());
               provinceNode.setId(UUID.randomUUID().toString().replace("-",""));
               provinceNode.setLevel(1);
               List<SgProjectTreeVO> provinceChildren = new ArrayList<>();
               for (Map.Entry<String, Map<String, Map<String, Map<String, List<SgProjectTreeVO>>>>> lotEntry : provinceEntry.getValue().entrySet()) {
                  SgProjectTreeVO lotNode = new SgProjectTreeVO();
                  List<String> lotIds = new ArrayList<>();
                  lotNode.setLot(lotEntry.getKey());
                  lotNode.setRegionName(lotEntry.getKey());
                  lotNode.setId(UUID.randomUUID().toString().replace("-",""));
                  lotNode.setLevel(2);
                  List<SgProjectTreeVO> lotChildren = new ArrayList<>();
                  for (Map.Entry<String, Map<String, Map<String, List<SgProjectTreeVO>>>> cityEntry : lotEntry.getValue().entrySet()) {
                     SgProjectTreeVO cityNode = new SgProjectTreeVO();
                     List<String> cityIds = new ArrayList<>();
                     cityNode.setCityNm(cityEntry.getKey());
                     cityNode.setRegionName(cityEntry.getKey());
                     cityNode.setId(UUID.randomUUID().toString().replace("-",""));
                     cityNode.setLevel(3);
                     List<SgProjectTreeVO> cityChildren = new ArrayList<>();
                     for (Map.Entry<String, Map<String, List<SgProjectTreeVO>>> countyEntry : cityEntry.getValue().entrySet()) {
                        SgProjectTreeVO countyNode = new SgProjectTreeVO();
                        List<String> countyIds = new ArrayList<>();
                        countyNode.setCountyNm(countyEntry.getKey());
                        countyNode.setRegionName(countyEntry.getKey());
                        countyNode.setId(UUID.randomUUID().toString().replace("-",""));
                        countyNode.setLevel(4);
                        List<SgProjectTreeVO> countyChildren = new ArrayList<>();
                        for (Map.Entry<String, List<SgProjectTreeVO>> townEntry : countyEntry.getValue().entrySet()) {
                           SgProjectTreeVO townNode = new SgProjectTreeVO();
                           townNode.setTownNm(townEntry.getKey());
                           townNode.setRegionName(townEntry.getKey());
                           townNode.setChildList(townEntry.getValue());
                           townNode.setChildNum((long) townEntry.getValue().size());
                           townNode.setId(UUID.randomUUID().toString().replace("-",""));
                           townNode.setLevel(5);
                           townNode.setProjectIds(townEntry.getValue().stream().map(SgProjectTreeVO::getId).collect(Collectors.toList()));
                           countyIds.addAll(townNode.getProjectIds());
                           countyChildren.add(townNode);
                        }
                        countyNode.setChildNum(countyChildren.stream().mapToLong(SgProjectTreeVO::getChildNum).sum());
                        countyNode.setChildList(countyChildren);
                        countyNode.setProjectIds(countyIds);
                        cityIds.addAll(countyIds);
                        cityChildren.add(countyNode);
                     }
                     cityNode.setChildNum(cityChildren.stream().mapToLong(SgProjectTreeVO::getChildNum).sum());
                     cityNode.setChildList(cityChildren);
                     cityNode.setProjectIds(cityIds);
                     lotIds.addAll(cityIds);
                     lotChildren.add(cityNode);
                  }
                  lotNode.setChildNum(lotChildren.stream().mapToLong(SgProjectTreeVO::getChildNum).sum());
                  lotNode.setChildList(lotChildren);
                  lotNode.setProjectIds(lotIds);
                  provinceChildren.add(lotNode);
               }
               SgProjectTreeVO countyNode = new SgProjectTreeVO();
               countyNode.setCountyNm(county);
               countyNode.setRegionName(county);
               countyNode.setId(UUID.randomUUID().toString().replace("-",""));
               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);
               provinceNode.setChildNum(provinceChildren.stream().mapToLong(SgProjectTreeVO::getChildNum).sum());
               provinceNode.setChildList(provinceChildren);
               tree.add(provinceNode);
            }
            cityNode.setChildNum((long) cityIds.size());
            cityNode.setProjectIds(cityIds);
            provinceNode.getChildList().add(cityNode);
            provinceNum+= (long) cityIds.size();
         }
         provinceNode.setChildNum(provinceNum);
         result.add(provinceNode);
      }
      return result;
            return tree;
      }
      return new ArrayList<>();
   }