Преглед изворни кода

pms 瑞恒 调整设备利用率

zhangcl пре 1 дан
родитељ
комит
949fb63b40

+ 144 - 50
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrhdailyreport/IotRhDailyReportServiceImpl.java

@@ -1268,6 +1268,9 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key项目部id     value项目部下包含设备的队伍 年度 注气时间 或 注水时间 总和
         Map<Long, BigDecimal> projectYearWorkTimePair = new HashMap<>();
 
+        // key项目部id     value项目部包含的队伍年度日报总数量
+        Map<Long, Integer> projectYearTotalReportPair = new HashMap<>();
+
         if (CollUtil.isNotEmpty(yearDailyReports)) {
             yearDailyReports.forEach(yearReport -> {
                 Long deptId = yearReport.getDeptId();
@@ -1312,13 +1315,23 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     } else {
                         projectYearWaterInjectionPair.put(projectDeptId, dailyWaterInjection);
                     }
+                    // 统计各项目部年度日报总数量
+                    if (projectYearTotalReportPair.containsKey(projectDeptId)) {
+                        Integer tempCount = projectYearTotalReportPair.get(projectDeptId);
+                        projectYearTotalReportPair.put(projectDeptId, ++tempCount);
+                    } else {
+                        projectYearTotalReportPair.put(projectDeptId, 1);
+                    }
                 }
             });
         }
 
-        // key项目部id     value项目部包含的队伍指定时间区域内日报数量
+        // key项目部id     value项目部包含的队伍指定时间区域内注气或注水>0的日报数量
         Map<Long, Integer> projectReportPair = new HashMap<>();
 
+        // key项目部id     value项目部包含的队伍指定时间区域内日报总数量
+        Map<Long, Integer> projectTotalReportPair = new HashMap<>();
+
         // 以施工区域为维度统计 队伍总数 施工队伍数 准备队伍数
         // key: 项目部ID -> key: 施工区域 -> Set<队伍ID>
         Map<Long, Map<String, Set<Long>>> projectLocationTeamSet = new HashMap<>();   // 总队伍
@@ -1512,6 +1525,13 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     } else {
                         projectWaterInjectionPair.put(projectId, dailyWaterInjection);
                     }
+                    // 统计各项目部日报总数量
+                    if (projectTotalReportPair.containsKey(projectId)) {
+                        Integer tempCount = projectTotalReportPair.get(projectId);
+                        projectTotalReportPair.put(projectId, ++tempCount);
+                    } else {
+                        projectTotalReportPair.put(projectId, 1);
+                    }
                 }
             });
             // 计算指定时间区间内包含的天数
@@ -1677,8 +1697,11 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                             rateVo.setConstructionDays(reportCount);
                             // 当前项目部 设备利用率 公式 reportCount/(currentTeamNum*daysCount)
                             // 计算设备利用率(处理除数为0的情况)
-                            if (currentTeamNum > 0 && daysCount > 0) {
-                                rate = new BigDecimal((double) reportCount / (currentTeamNum * daysCount))
+                            // 20260915 设备利用率 逻辑调整 分母修改为 日报总数量
+                            // 旧分母 currentTeamNum * daysCount
+                            if (daysCount > 0 && projectTotalReportPair.containsKey(projectDeptId)) {
+                                Integer totalReportNum = projectTotalReportPair.get(projectDeptId);
+                                rate = new BigDecimal((double) reportCount / totalReportNum)
                                         .setScale(4, RoundingMode.HALF_UP)  // 保留4位小数,四舍五入
                                         .doubleValue();
                             }
@@ -1688,12 +1711,16 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                         if (projectWorkTimePair.containsKey(projectDeptId)) {
                             BigDecimal reportWorkTime = projectWorkTimePair.getOrDefault(projectDeptId, BigDecimal.ZERO);
                             // 统计所有项目部 当日 总工作时间 以便于计算 公司整体的当日运行时效
+                            // 20260915 设备利用率 逻辑调整 分母修改为 日报总数量
+                            // 旧分母 currentTeamNum * daysCount * 24
                             if (currentTeamNum > 0 && daysCount > 0) {
                                 // 分母 = 队伍数 * 天数 * 24小时
                                 BigDecimal denominator = new BigDecimal(currentTeamNum * daysCount * 24);
                                 // 安全计算,避免除0
                                 BigDecimal utilization = BigDecimal.ZERO;
-                                if (denominator.compareTo(BigDecimal.ZERO) > 0) {
+                                if (projectTotalReportPair.containsKey(projectDeptId)) {
+                                    Integer totalReportNum = projectTotalReportPair.get(projectDeptId);
+                                    denominator = new BigDecimal(totalReportNum * 24);
                                     utilization = reportWorkTime.divide(denominator, 4, RoundingMode.HALF_UP);
                                     rateVo.setHourUtilizationRate(utilization);
                                 }
@@ -1708,8 +1735,12 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                                 // 分母 = 队伍数 * 天数 * 24小时
                                 BigDecimal denominator = new BigDecimal(currentTeamNum * tempYearTotalDay * 24);
                                 // 安全计算,避免除0
+                                // 20260915 设备利用率 逻辑调整 分母修改为 日报总数量
+                                // 旧分母 currentTeamNum * tempYearTotalDay * 24
                                 BigDecimal utilization = BigDecimal.ZERO;
-                                if (denominator.compareTo(BigDecimal.ZERO) > 0) {
+                                if (projectYearTotalReportPair.containsKey(projectDeptId)) {
+                                    Integer totalReportNum = projectYearTotalReportPair.get(projectDeptId);
+                                    denominator = new BigDecimal(totalReportNum * 24);
                                     utilization = reportWorkTime.divide(denominator, 4, RoundingMode.HALF_UP);
                                     rateVo.setYearHourUtilizationRate(utilization);
                                 }
@@ -1744,7 +1775,9 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 BigDecimal denominator = new BigDecimal(teamCount * daysCount * 24);
                 // 安全计算,避免除0
                 BigDecimal utilization = BigDecimal.ZERO;
-                if (denominator.compareTo(BigDecimal.ZERO) > 0) {
+                // 20260915 设备利用率逻辑调整 修改分母为 日报总数量
+                if (CollUtil.isNotEmpty(dailyReports)) {
+                    denominator = new BigDecimal(dailyReports.size() * 24);
                     utilization = currentTotalWorkTime.divide(denominator, 4, RoundingMode.HALF_UP);
                     rateVo.setHourUtilizationRate(utilization);
                 }
@@ -1754,7 +1787,9 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 BigDecimal yearDenominator = new BigDecimal(teamCount * tempYearTotalDay * 24);
                 // 安全计算,避免除0
                 BigDecimal yearUtilization = BigDecimal.ZERO;
-                if (yearDenominator.compareTo(BigDecimal.ZERO) > 0) {
+                // 20260915 设备利用率逻辑调整 修改分母为 日报总数量
+                if (CollUtil.isNotEmpty(yearDailyReports)) {
+                    yearDenominator = new BigDecimal( yearDailyReports.size() * 24);
                     yearUtilization = yearTotalWorkTime.divide(yearDenominator, 4, RoundingMode.HALF_UP);
                     rateVo.setYearHourUtilizationRate(yearUtilization);
                 }
@@ -2056,11 +2091,15 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     ) + 1;
                 }
             }
+
+            // 20260914 设备利用率 分母调整为 查询时间区间内总的日报数量
+
             // 所有LY状态的项目部包含的队伍数量>0 并且 指定时间区间天数大于0
             if (daysCount > 0 && teamProjectIdPair.size() > 0) {
                 // 指定部门(公司or项目部or队伍) 设备利用率 公式 reportCount/(currentTeamNum*daysCount)
                 // 计算设备利用率(处理除数为0的情况)
-                rate = new BigDecimal((double) reportCount / (teamProjectIdPair.size() * daysCount))
+                // 原分母 (teamProjectIdPair.size() * daysCount)
+                rate = new BigDecimal((double) reportCount / list.size())
                         .setScale(4, RoundingMode.HALF_UP)  // 保留4位小数,四舍五入
                         .doubleValue();
             }
@@ -2418,6 +2457,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             }
         });
 
+        // 20260914 修改设备利用率 统计逻辑 分母修改为 各项目部日报数据
+        // key项目部id     value项目部包含的队伍指定时间区域内日报数量
+        Map<Long, Integer> projectTotalReportPair = new HashMap<>();
+
         LocalDateTime[] createTime = pageReqVO.getCreateTime();
         List<Long> daysCounts = new ArrayList<>();
         // 如果 createTime 包含的时间是 1天则查询 这1天时间内的 队伍总数 施工队伍数量 施工准备队伍数量 驻地待命队伍数量
@@ -2463,39 +2506,49 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     // 待命队伍 = 队伍总数 - 施工队伍 -  准备队伍
                     if (CollUtil.isNotEmpty(dailyReports)) {
                         dailyReports.forEach(report -> {
-                            if (teamProjectIdPair.containsKey(report.getDeptId()) && deviceDeptIds.contains(report.getDeptId())) {
-                                // 找到队伍所属的上级项目部
-                                Long projectDeptId = teamProjectIdPair.get(report.getDeptId());
-                                // 动迁 准备 完工 都算作 准备
-                                // 施工sg  观察使用gcsy 待维修dwx 待保养dby
-                                // 20260624 修改为 注水 或 注气量 >0 的日报队伍数量
-                                BigDecimal tempGasInjection = report.getDailyGasInjection();
-                                BigDecimal tempWaterInjection = report.getDailyWaterInjection();
-                                if (tempGasInjection.compareTo(BigDecimal.ZERO) > 0 || tempWaterInjection.compareTo(BigDecimal.ZERO) > 0) {
-                                    if (sgTeamCountPair.containsKey(projectDeptId)) {
-                                        Integer tempCount = sgTeamCountPair.get(projectDeptId);
-                                        sgTeamCountPair.put(projectDeptId, ++tempCount);
-                                    } else {
-                                        sgTeamCountPair.put(projectDeptId, 1);
-                                    }
+                            // 找到队伍所属的上级项目部
+                            Long projectDeptId = teamProjectIdPair.get(report.getDeptId());
+                            if (teamProjectIdPair.containsKey(report.getDeptId())) {
+                                // 设置各项目部的日报总数量
+                                if (projectTotalReportPair.containsKey(projectDeptId)) {
+                                    Integer tempCount = projectTotalReportPair.get(projectDeptId);
+                                    projectTotalReportPair.put(projectDeptId, ++tempCount);
+                                } else {
+                                    projectTotalReportPair.put(projectDeptId, 1);
                                 }
-                                // 准备
-                                if ("zb".equals(report.getConstructionStatus()) || "dq".equals(report.getConstructionStatus()) || "wg".equals(report.getConstructionStatus())) {
-                                    if (zbTeamCountPair.containsKey(projectDeptId)) {
-                                        Integer tempCount = zbTeamCountPair.get(projectDeptId);
-                                        zbTeamCountPair.put(projectDeptId, ++tempCount);
-                                    } else {
-                                        zbTeamCountPair.put(projectDeptId, 1);
+
+                                if (deviceDeptIds.contains(report.getDeptId())) {
+                                    // 动迁 准备 完工 都算作 准备
+                                    // 施工sg  观察使用gcsy 待维修dwx 待保养dby
+                                    // 20260624 修改为 注水 或 注气量 >0 的日报队伍数量
+                                    BigDecimal tempGasInjection = report.getDailyGasInjection();
+                                    BigDecimal tempWaterInjection = report.getDailyWaterInjection();
+                                    if (tempGasInjection.compareTo(BigDecimal.ZERO) > 0 || tempWaterInjection.compareTo(BigDecimal.ZERO) > 0) {
+                                        if (sgTeamCountPair.containsKey(projectDeptId)) {
+                                            Integer tempCount = sgTeamCountPair.get(projectDeptId);
+                                            sgTeamCountPair.put(projectDeptId, ++tempCount);
+                                        } else {
+                                            sgTeamCountPair.put(projectDeptId, 1);
+                                        }
                                     }
-                                }
-                                // 待命 = 队伍总数 - 施工队伍 -  准备队伍
-                                if ("zddm".equals(report.getConstructionStatus()) || "xcdm".equals(report.getConstructionStatus())
-                                        || "dm".equals(report.getConstructionStatus()) || "wxz".equals(report.getConstructionStatus())  || "xz".equals(report.getConstructionStatus())) {
-                                    if (zddmTeamCountPair.containsKey(projectDeptId)) {
-                                        Integer tempCount = zddmTeamCountPair.get(projectDeptId);
-                                        zddmTeamCountPair.put(projectDeptId, ++tempCount);
-                                    } else {
-                                        zddmTeamCountPair.put(projectDeptId, 1);
+                                    // 准备
+                                    if ("zb".equals(report.getConstructionStatus()) || "dq".equals(report.getConstructionStatus()) || "wg".equals(report.getConstructionStatus())) {
+                                        if (zbTeamCountPair.containsKey(projectDeptId)) {
+                                            Integer tempCount = zbTeamCountPair.get(projectDeptId);
+                                            zbTeamCountPair.put(projectDeptId, ++tempCount);
+                                        } else {
+                                            zbTeamCountPair.put(projectDeptId, 1);
+                                        }
+                                    }
+                                    // 待命 = 队伍总数 - 施工队伍 -  准备队伍
+                                    if ("zddm".equals(report.getConstructionStatus()) || "xcdm".equals(report.getConstructionStatus())
+                                            || "dm".equals(report.getConstructionStatus()) || "wxz".equals(report.getConstructionStatus())  || "xz".equals(report.getConstructionStatus())) {
+                                        if (zddmTeamCountPair.containsKey(projectDeptId)) {
+                                            Integer tempCount = zddmTeamCountPair.get(projectDeptId);
+                                            zddmTeamCountPair.put(projectDeptId, ++tempCount);
+                                        } else {
+                                            zddmTeamCountPair.put(projectDeptId, 1);
+                                        }
                                     }
                                 }
                             }
@@ -2506,8 +2559,9 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         }
 
         // 统计各项目部的设备利用率
-        // key项目部id     value项目部包含的队伍指定时间区域内日报数量
+        // key项目部id     value项目部包含的队伍指定时间区域内注水量或注气量大于0的日报数量
         Map<Long, Integer> projectReportPair = new HashMap<>();
+
         // 查询指定部门下相关设备的产能
         // key队伍id   value队伍下相关设备产能
         Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
@@ -2628,9 +2682,11 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     Integer reportCount = projectReportPair.getOrDefault(projectDeptId, 0);
                     // 当前项目部 设备利用率 公式 reportCount/(currentTeamNum * daysCount)
                     // 计算设备利用率(处理除数为0的情况)
-                    if (currentTeamNum > 0 && CollUtil.isNotEmpty(daysCounts)) {
+                    // 20260914 修改设备利用率查询逻辑 原分母 currentTeamNum * daysCount
+                    if (currentTeamNum > 0 && CollUtil.isNotEmpty(daysCounts) && projectTotalReportPair.containsKey(projectDeptId)) {
+                        Integer totalReportNum = projectTotalReportPair.get(projectDeptId);
                         long daysCount = daysCounts.get(0);
-                        rate = new BigDecimal((double) reportCount / (currentTeamNum * daysCount))
+                        rate = new BigDecimal((double) reportCount / totalReportNum)
                                 .setScale(4, RoundingMode.HALF_UP)  // 保留4位小数,四舍五入
                                 .doubleValue();
                         deviceUtilizationPair.put(projectDeptId, BigDecimal.valueOf(rate));
@@ -2651,8 +2707,13 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                         BigDecimal denominator = new BigDecimal(currentTeamNum * daysCount * 24);
                         // 安全计算,避免除0
                         BigDecimal utilization = BigDecimal.ZERO;
-                        if (denominator.compareTo(BigDecimal.ZERO) > 0) {
+                        // 20260914 修改设备利用率 分母修改成 项目部下日报总数量
+
+                        if (projectTotalReportPair.containsKey(projectDeptId)) {
+                            Integer totalReportNum = projectTotalReportPair.get(projectDeptId);
+                            denominator = new BigDecimal(totalReportNum * 24);
                             utilization = reportWorkTime.divide(denominator, 4, RoundingMode.HALF_UP);
+
                         }
                         hourDeviceUtilizationPair.put(projectDeptId, utilization);
                     }
@@ -3173,6 +3234,9 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
 
         // 当前已经选择的部门下 包含瑞恒主设备的 队伍id 集合
         Set<Long> currentDeviceDeptIds = new HashSet<>();
+
+        // 20260915 修改设备利用率计算逻辑 修改分母为 日报总数
+
         // 构建项目部映射和父子部门关系
         depts.forEach(dept -> {
             if ("2".equals(dept.getType())) {
@@ -3193,6 +3257,9 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key日期yyyy-MM-dd   value累计注气量
         Map<String, Set<Long>> dateUtilizationDeptPair = new HashMap<>();
 
+        // key日期yyyy-MM-dd   value日期对应的日报总数量
+        Map<String, Integer> dateTotalReportPair = new HashMap<>();
+
         // 累计计算各项指标
         if (CollUtil.isNotEmpty(dailyReports)) {
             dailyReports.forEach(report -> {
@@ -3228,7 +3295,13 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                         dateUtilizationDeptPair.put(reportDateStr, tempDeptIds);
                     }
                 }
-
+                // 统计当前日期下所有日报总数量
+                if (dateTotalReportPair.containsKey(reportDateStr)) {
+                    Integer tempCount = dateTotalReportPair.get(reportDateStr);
+                    dateTotalReportPair.put(reportDateStr, ++tempCount);
+                } else {
+                    dateTotalReportPair.put(reportDateStr, 1);
+                }
             });
             // 根据 累计注气量 累计产能 计算指定日期范围的平均产能
             if (CollUtil.isNotEmpty(dateGasInjectionPair) && CollUtil.isNotEmpty(dateCapacityPair)) {
@@ -3275,9 +3348,11 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     Set<Long> dateDeptIds = dateUtilizationDeptPair.get(date);
                     Integer dateDeptIdCount = dateDeptIds.size();
                     Integer mainDeviceIdCount = currentDeviceDeptIds.size();
+                    // 20260915 修改设备利用率 计算逻辑 分母修改为日报总数量
                     BigDecimal rate = BigDecimal.ZERO;
-                    if (mainDeviceIdCount > 0) {
-                        BigDecimal total = new BigDecimal(mainDeviceIdCount);
+                    if (dateTotalReportPair.containsKey(date)) {
+                        Integer totalReportNum = dateTotalReportPair.get(date);
+                        BigDecimal total = new BigDecimal(totalReportNum);
                         BigDecimal current = new BigDecimal(dateDeptIdCount);
                         rate = current.divide(total, 4, RoundingMode.HALF_UP);
                     }
@@ -3405,8 +3480,12 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key队伍id   value队伍下相关设备产能
         Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
         // 统计各队伍的设备利用率
-        // key队伍id     value队伍指定时间区域内日报数量
+        // key队伍id     value队伍指定时间区域内注气或注水大于0的日报数量
         Map<Long, Integer> teamReportPair = new HashMap<>();
+
+        // key队伍id     value队伍指定时间区域内总日报数量
+        Map<Long, Integer> teamTotalReportPair = new HashMap<>();
+
         // key队伍id     value包含设备的队伍注气时间或注水时间总和
         Map<Long, BigDecimal> teamWorkTimePair = new HashMap<>();
 
@@ -3415,6 +3494,14 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             dailyReports.forEach(report -> {
                 Long deptId = report.getDeptId();
                 if (ObjUtil.isNotEmpty(deptId)) {
+                    // 20260915 修改设备利用率统计逻辑 分母修改为 总日报数量
+                    if (teamTotalReportPair.containsKey(deptId)) {
+                        Integer tempCount = teamTotalReportPair.get(deptId);
+                        teamTotalReportPair.put(deptId, ++tempCount);
+                    } else {
+                        teamTotalReportPair.put(deptId, 1);
+                    }
+
                     if (haveDeviceDeptIds.contains(deptId)) {
                         // 统计各个队伍的日报数量 筛选 注气量 或 注水量 >0 的日报
                         if (report.getDailyGasInjection().compareTo(BigDecimal.ZERO)>0 || report.getDailyWaterInjection().compareTo(BigDecimal.ZERO)>0) {
@@ -3518,9 +3605,12 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     Integer currentTeamNum = 1;
                         // 当前项目部 设备利用率 公式 reportCount/(currentTeamNum * daysCount)
                         // 计算设备利用率(处理除数为0的情况)
-                        if (currentTeamNum > 0 && CollUtil.isNotEmpty(daysCounts)) {
+                        // 20260915 修改设备利用率统计逻辑 分母修改为 日报总数量
+                        // 原分母  currentTeamNum * daysCount
+                        if (currentTeamNum > 0 && CollUtil.isNotEmpty(daysCounts) && teamTotalReportPair.containsKey(teamDeptId)) {
+                            Integer totalReportNum = teamTotalReportPair.get(teamDeptId);
                             long daysCount = daysCounts.get(0);
-                            rate = new BigDecimal((double) reportCount / (currentTeamNum * daysCount))
+                            rate = new BigDecimal((double) reportCount / totalReportNum)
                                     .setScale(4, RoundingMode.HALF_UP)  // 保留4位小数,四舍五入
                                     .doubleValue();
                             deviceUtilizationPair.put(teamDeptId, BigDecimal.valueOf(rate));
@@ -3535,13 +3625,17 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     Integer currentTeamNum = 1;
                     // 当前项目部 设备利用率 公式 reportCount/(currentTeamNum * daysCount)
                     // 计算设备利用率(处理除数为0的情况)
+                    // 20260915 修改设备利用率统计逻辑 分母修改为 日报总数量
+                    // 原分母  currentTeamNum * daysCount * 24
                     if (currentTeamNum > 0 && CollUtil.isNotEmpty(daysCounts)) {
                         long daysCount = daysCounts.get(0);
                         // 分母 = 队伍数 * 天数 * 24小时
                         BigDecimal denominator = new BigDecimal(currentTeamNum * daysCount * 24);
                         // 安全计算,避免除0
                         BigDecimal utilization = BigDecimal.ZERO;
-                        if (denominator.compareTo(BigDecimal.ZERO) > 0) {
+                        if (teamTotalReportPair.containsKey(teamDeptId)) {
+                            Integer totalReportNum = teamTotalReportPair.get(teamDeptId);
+                            denominator = new BigDecimal(totalReportNum * 24);
                             utilization = reportWorkTime.divide(denominator, 4, RoundingMode.HALF_UP);
                         }
                         hourDeviceUtilizationPair.put(teamDeptId, utilization);