shenyijian
2024-08-21 a4b8b53d4b59a5f9e5c4d19e5f4db7829b81e07d
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java
@@ -103,54 +103,72 @@
         }
         SgProjectInfoVO sgProjectInfoVO = value.get(0);
         SgProjectInfoDO sgProjectInfoDO = SgProjectInfoDO.builder().id(porId).lonLat(sgProjectInfoVO.getLonLat()).status(sgProjectInfoVO.getProjectStatus()).projectName(sgProjectInfoVO.getProjectName()).build();
         List<SgTypeVO> sgGxDOS = new ArrayList<>();
         //类型分组
         Map<String, List<SgProjectInfoVO>> GxMap = value.stream().filter(s->s.getDeviceType()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getDeviceType));
         for (Map.Entry<String, List<SgProjectInfoVO>> ty : GxMap.entrySet()) {
            String type = ty.getKey();
            List<SgProjectInfoVO> gxList = ty.getValue();
            if (CollectionUtils.isEmpty(gxList)){
         //父类型分组
         List<PtypeVO> pTypes = new ArrayList();
         Map<String, List<SgProjectInfoVO>> pTypeMap = value.stream().filter(s->s.getPtype()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getPtype));
         for (Map.Entry<String, List<SgProjectInfoVO>> pty : pTypeMap.entrySet()) {
            List<SgProjectInfoVO> ptyValue = pty.getValue();
            if (CollectionUtils.isEmpty(ptyValue)){
               continue;
            }
            SgTypeVO typeVO = SgTypeVO.builder().typeName(gxList.get(0).getTypeName()).build();
            List<SgDeviceDO> deviceDOS = new ArrayList<>();
            //设备分组
            Map<Long, List<SgProjectInfoVO>> dMap = gxList.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getDId));
            for (Map.Entry<Long, List<SgProjectInfoVO>> device : dMap.entrySet()) {
               Long dId = device.getKey();
               List<SgProjectInfoVO> deList = device.getValue();
               SgDeviceDO sgDeviceDO = new SgDeviceDO();
               sgDeviceDO.setId(dId);
               sgDeviceDO.setDeviceName(deList.get(0).getDeviceName());
               List<SgGxStepDO> stepDOS = deList.stream().filter(s->s.getReportStatus()==null || s.getReportStatus()!=4).map(s -> SgGxStepDO.builder().id(s.getStepId()).gxStepNum(s.getGxStepNum()).gxStepName(s.getGxStepName()).deviceId(s.getDId()).approvalStatus(s.getReportStatus()).build()).collect(Collectors.toList());
               List<SgGxStepDO> stepOver = stepDOS.stream().filter(s -> s.getApprovalStatus() != null && s.getApprovalStatus() == 2).collect(Collectors.toList());
               BigDecimal stepSize = BigDecimal.valueOf(stepDOS.size());
               BigDecimal stepOverSize = BigDecimal.ZERO;
               if (!stepOver.isEmpty()){
                  stepOverSize = BigDecimal.valueOf(stepOver.size());
            PtypeVO ptypeVO = PtypeVO.builder().pTypeName(ptyValue.get(0).getPtypeName()).build();
            List<SgTypeVO> sgGxDOS = new ArrayList<>();
            //类型分组
            Map<String, List<SgProjectInfoVO>> GxMap = ptyValue.stream().filter(s->s.getDeviceType()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getDeviceType));
            for (Map.Entry<String, List<SgProjectInfoVO>> ty : GxMap.entrySet()) {
               String type = ty.getKey();
               List<SgProjectInfoVO> gxList = ty.getValue();
               if (CollectionUtils.isEmpty(gxList)){
                  continue;
               }
               BigDecimal divide = stepOverSize.divide(stepSize, 2, RoundingMode.HALF_UP);
               sgDeviceDO.setStatus(divide.compareTo(new BigDecimal(1)) == 0?2:deList.get(0).getDeviceStatus());
               sgDeviceDO.setProgress(divide.toString());
               sgDeviceDO.setDeviceProgress(getBigDecimalPercent(divide));
               sgDeviceDO.setStepDOList(stepDOS);
               deviceDOS.add(sgDeviceDO);
               allDevice.add(sgDeviceDO);
               SgTypeVO typeVO = SgTypeVO.builder().typeName(gxList.get(0).getTypeName()).build();
               List<SgDeviceDO> deviceDOS = new ArrayList<>();
               //设备分组
               Map<Long, List<SgProjectInfoVO>> dMap = gxList.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getDId));
               for (Map.Entry<Long, List<SgProjectInfoVO>> device : dMap.entrySet()) {
                  Long dId = device.getKey();
                  List<SgProjectInfoVO> deList = device.getValue();
                  SgDeviceDO sgDeviceDO = new SgDeviceDO();
                  sgDeviceDO.setId(dId);
                  sgDeviceDO.setDeviceName(deList.get(0).getDeviceName());
                  List<SgGxStepDO> stepDOS = deList.stream().filter(s->s.getReportStatus()==null || s.getReportStatus()!=4).map(s -> SgGxStepDO.builder().id(s.getStepId()).gxStepNum(s.getGxStepNum()).gxStepName(s.getGxStepName()).deviceId(s.getDId()).approvalStatus(s.getReportStatus()).build()).collect(Collectors.toList());
                  List<SgGxStepDO> stepOver = stepDOS.stream().filter(s -> s.getApprovalStatus() != null && s.getApprovalStatus() == 2).collect(Collectors.toList());
                  BigDecimal stepSize = BigDecimal.valueOf(stepDOS.size());
                  BigDecimal stepOverSize = BigDecimal.ZERO;
                  if (!stepOver.isEmpty()){
                     stepOverSize = BigDecimal.valueOf(stepOver.size());
                  }
                  BigDecimal divide = stepOverSize.divide(stepSize, 2, RoundingMode.HALF_UP);
                  sgDeviceDO.setStatus(divide.compareTo(new BigDecimal(1)) == 0?2:deList.get(0).getDeviceStatus());
                  sgDeviceDO.setProgress(divide.toString());
                  sgDeviceDO.setDeviceProgress(getBigDecimalPercent(divide));
                  sgDeviceDO.setStepDOList(stepDOS);
                  deviceDOS.add(sgDeviceDO);
                  allDevice.add(sgDeviceDO);
               }
               BigDecimal deviceSize = BigDecimal.valueOf(deviceDOS.size());
               double sum = deviceDOS.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
               BigDecimal deviceOver = BigDecimal.valueOf(sum);
               BigDecimal divideDevice = deviceOver.divide(deviceSize, 2, RoundingMode.HALF_UP);
               typeVO.setDeviceDOS(deviceDOS);
               typeVO.setTypeProgress(getBigDecimalPercent(divideDevice));
               typeVO.setProgress(divideDevice.toString());
               sgGxDOS.add(typeVO);
            }
            BigDecimal deviceSize = BigDecimal.valueOf(deviceDOS.size());
            double sum = deviceDOS.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
            BigDecimal deviceOver = BigDecimal.valueOf(sum);
            BigDecimal divideDevice = deviceOver.divide(deviceSize, 2, RoundingMode.HALF_UP);
            typeVO.setDeviceDOS(deviceDOS);
            typeVO.setTypeProgress(getBigDecimalPercent(divideDevice));
            sgGxDOS.add(typeVO);
            BigDecimal sgGxSize = BigDecimal.valueOf(sgGxDOS.size());
            double sum = sgGxDOS.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
            BigDecimal sgGxOver = BigDecimal.valueOf(sum);
            BigDecimal divideSgGx = sgGxOver.divide(sgGxSize, 2, RoundingMode.HALF_UP);
            ptypeVO.setPTypeProgress(getBigDecimalPercent(divideSgGx));
            ptypeVO.setSgTypeVOS(sgGxDOS);
            pTypes.add(ptypeVO);
         }
         BigDecimal allDeviceSize = BigDecimal.valueOf(allDevice.size());
         if (!allDeviceSize.equals(BigDecimal.ZERO)){
            double sum = allDevice.stream().mapToDouble(s -> Double.parseDouble(s.getProgress())).sum();
            BigDecimal allDeviceOver = BigDecimal.valueOf(sum);
            BigDecimal allDivideDevice = allDeviceOver.divide(allDeviceSize, 2, RoundingMode.HALF_UP);
            sgProjectInfoDO.setSgGxDOS(sgGxDOS);
            sgProjectInfoDO.setPtypeVOS(pTypes);
            sgProjectInfoDO.setProjectProgress( getBigDecimalPercent(allDivideDevice));
            sgProjectInfoDO.setProjectProgressNum(allDivideDevice);
         }
@@ -314,11 +332,11 @@
         List<SgProjectInfoDO> projectProgress = getProjectProgress(list);
         projectProgress.forEach(p -> {
            List<SgTypeVO> sgGxDOS = p.getSgGxDOS();
            sgGxDOS.forEach(sgTypeVO -> {
               String typeProgress = sgTypeVO.getTypeProgress().replace("%", "");
            List<PtypeVO> ptypeVOS = p.getPtypeVOS();
            ptypeVOS.forEach(sgTypeVO -> {
               String typeProgress = sgTypeVO.getPTypeProgress().replace("%", "");
               BigDecimal percentageBigDecimal = new BigDecimal(typeProgress).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
               bigDecimals.merge(sgTypeVO.getTypeName(), percentageBigDecimal, BigDecimal::add);
               bigDecimals.merge(sgTypeVO.getPTypeName(), percentageBigDecimal, BigDecimal::add);
            });
         });