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

pms 瑞都 非生产时效分析 以队伍为维度统计

zhangcl пре 18 часа
родитељ
комит
ab6f4572eb

+ 361 - 6
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrddailyreport/IotRdDailyReportServiceImpl.java

@@ -3390,23 +3390,25 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
         // 点击项目部 显示 下属队伍的数据
         // 首先判断点击的部门是属于 公司 还是 队伍 如果没有点击任何部门 默认查询所有项目部数据
         if (ObjUtil.isEmpty(pageReqVO.getDeptId())) {
-            result = nptStatisticsByProjectDept(dailyReports, 163L, pageReqVO);
+            // result = nptStatisticsByProjectDept(dailyReports, 163L, pageReqVO);
+            result = nptStatisticsByProjectDepartment(dailyReports, 163L, pageReqVO);
         } else {
             // 判断点击的组织树中的部门类型 类型(公司级1 项目部2 队伍3)
             DeptDO selectedDept = deptService.getDept(pageReqVO.getDeptId());
             if ("1".equals(selectedDept.getType())) {
                 // 以项目部为维度汇总数据
-                result = nptStatisticsByProjectDept(dailyReports, pageReqVO.getDeptId(), pageReqVO);
+                // result = nptStatisticsByProjectDept(dailyReports, pageReqVO.getDeptId(), pageReqVO);
+                result = nptStatisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId(), pageReqVO);
             } else if ("2".equals(selectedDept.getType())) {
                 // 以队伍为维度汇总数据
-                // result = nptStatisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId());
+                result = nptStatisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId(), pageReqVO);
             } else if ("3".equals(selectedDept.getType())) {
                 // 显示单个队伍的汇总数据
-                // result = nptStatisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId());
+                result = nptStatisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId(), pageReqVO);
             } else {
-                // 点击的部门没有类型 判断部门下的是否包含 项目部类型部门 新疆分公司
-                // 以项目部为维度汇总数据
+                // 点击的部门没有类型 判断部门下的是否包含 项目部类型部门 新疆分公司 以项目部为维度汇总数据
                 // result = nptStatisticsByProjectDept(dailyReports, pageReqVO.getDeptId(), pageReqVO);
+                result = nptStatisticsByProjectDepartment(dailyReports, pageReqVO.getDeptId(), pageReqVO);
             }
         }
         // 根据 result 集合内对象的 sort 属性正序排列 sort 类型为 integer 类型
@@ -3429,6 +3431,8 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
                                                                            Long rootDeptId, IotRdDailyReportPageReqVO pageReqVO) {
         List<IotRdDailyReportNptStatisticsRespVO> result = new ArrayList<>();
 
+        // 点击公司级别的部门 查询公司下所有施工队伍的数据
+
         Set<Long> projectDeptIds = new HashSet<>();
         // key项目部id    value项目部名称
         Map<Long, DeptDO> projectDeptPair = new HashMap<>();
@@ -3776,6 +3780,357 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
         return result;
     }
 
+    /**
+     * 按 队伍 维度统计 非生产时效
+     * @param dailyReports 瑞都日报数据列表
+     * @param deptId 项目部ID 或 队伍id
+     * @return 队伍 维度统计 非生产时效数据
+     */
+    private List<IotRdDailyReportNptStatisticsRespVO> nptStatisticsByProjectDepartment(List<IotRdDailyReportDO> dailyReports, Long deptId, IotRdDailyReportPageReqVO pageReqVO) {
+        List<IotRdDailyReportNptStatisticsRespVO> result = new ArrayList<>();
+
+        Set<Long> teamDeptIds = new HashSet<>();
+        // key项目部id    value项目部名称
+        Map<Long, DeptDO> projectDeptPair = new HashMap<>();
+        // key队伍id    value队伍名称
+        Map<Long, DeptDO> teamDeptPair = new HashMap<>();
+        // key部门id   value部门parentId
+        Map<Long, Long> teamProjectIdPair = new HashMap<>();
+
+        // key队伍id/项目部id   value设备利用率
+        Map<Long, BigDecimal> utilizationRatePair = new HashMap<>();
+
+        // key队伍id/项目部id   value累计 工程质量npt
+        Map<Long, BigDecimal> subtotalAccidentTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 设备故障npt
+        Map<Long, BigDecimal> subtotalRepairTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 设备保养npt
+        Map<Long, BigDecimal> subtotalSelfStopTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 技术受限npt
+        Map<Long, BigDecimal> subtotalComplexityTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 生产配合npt
+        Map<Long, BigDecimal> subtotalRelocationTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 生产组织npt
+        Map<Long, BigDecimal> subtotalRectificationTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 不可抗力npt
+        Map<Long, BigDecimal> subtotalWaitingStopTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 待命npt
+        Map<Long, BigDecimal> subtotalWinterBreakTimePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 甲方设计npt
+        Map<Long, BigDecimal> subtotalPartyaDesignPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 甲方准备npt
+        Map<Long, BigDecimal> subtotalPartyaPreparePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 甲方资源npt
+        Map<Long, BigDecimal> subtotalPartyaResourcePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 其它非生产时间npt
+        Map<Long, BigDecimal> subtotalOtherNptTimePair = new HashMap<>();
+
+        // key队伍id   value npt小计
+        Map<Long, BigDecimal> subtotalNptTimePair = new HashMap<>();
+        // key队伍id   value npt时效%
+        Map<Long, BigDecimal> subtotalNptRatePair = new HashMap<>();
+
+        // 以 队伍 为维度统计数据 找到所有项目部与队伍的对应关系
+        // 查询指定根部门下的所有子部门
+        Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(deptId);
+        DeptListReqVO reqVO = new DeptListReqVO();
+        // 查询某支队伍 或 所属项目部的信息
+        allRhChildDeptIds.add(deptId);
+        reqVO.setDeptIds(allRhChildDeptIds);
+        List<DeptDO> depts = deptService.getDeptList(reqVO);
+
+        // 构建项目部映射和父子部门关系
+        depts.forEach(dept -> {
+            if ("3".equals(dept.getType())) {
+                // 队伍
+                teamDeptIds.add(dept.getId());
+                teamDeptPair.put(dept.getId(), dept);
+            }
+            if ("2".equals(dept.getType())) {
+                // 项目部
+                projectDeptPair.put(dept.getId(), dept);
+            }
+            teamProjectIdPair.put(dept.getId(), dept.getParentId());
+        });
+
+        // 计算日期查询区间有多少小时
+        LocalDateTime[] createTimes = pageReqVO.getCreateTime();
+        List<Long> totalHours = new ArrayList<>();
+        if (ObjUtil.isNotEmpty(createTimes) && createTimes.length >= 2) {
+            LocalDate startDate = createTimes[0].toLocalDate();
+            LocalDate endDate = createTimes[1].toLocalDate();
+            // 核心:包含起止两天 → 天数差 +1 再 ×24
+            long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
+            Long tempTotalHours = days * 24L;
+            totalHours.add(tempTotalHours);
+        }
+
+        // 累计计算 工作量
+        if (CollUtil.isNotEmpty(dailyReports)) {
+            dailyReports.forEach(report -> {
+                // 统计日报 每个队伍的非生产时间集合
+                Long reportDeptId = report.getDeptId();
+                if (ObjUtil.isNotEmpty(reportDeptId) && teamDeptIds.contains(reportDeptId)) {
+                    // 工程质量 npt
+                    BigDecimal accidentTime = report.getAccidentTime();
+                    if (ObjUtil.isNotEmpty(accidentTime)) {
+                        if (subtotalAccidentTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existAccidentTime = subtotalAccidentTimePair.get(reportDeptId);
+                            BigDecimal tempAccidentTime = existAccidentTime.add(accidentTime);
+                            subtotalAccidentTimePair.put(reportDeptId, tempAccidentTime);
+                        } else {
+                            subtotalAccidentTimePair.put(reportDeptId, accidentTime);
+                        }
+                    }
+
+                    // 设备故障 npt
+                    BigDecimal repairTime = report.getRepairTime();
+                    if (ObjUtil.isNotEmpty(repairTime)) {
+                        if (subtotalRepairTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existRepairTime = subtotalRepairTimePair.get(reportDeptId);
+                            BigDecimal tempRepairTime = existRepairTime.add(repairTime);
+                            subtotalRepairTimePair.put(reportDeptId, tempRepairTime);
+                        } else {
+                            subtotalRepairTimePair.put(reportDeptId, repairTime);
+                        }
+                    }
+                    // 设备保养 npt
+                    BigDecimal selfStopTime = report.getSelfStopTime();
+                    if (ObjUtil.isNotEmpty(selfStopTime)) {
+                        if (subtotalSelfStopTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existSelfStopTime = subtotalSelfStopTimePair.get(reportDeptId);
+                            BigDecimal tempSelfStopTime = existSelfStopTime.add(selfStopTime);
+                            subtotalSelfStopTimePair.put(reportDeptId, tempSelfStopTime);
+                        } else {
+                            subtotalSelfStopTimePair.put(reportDeptId, selfStopTime);
+                        }
+                    }
+                    // 技术受限 npt
+                    BigDecimal complexityTime = report.getComplexityTime();
+                    if (ObjUtil.isNotEmpty(complexityTime)) {
+                        if (subtotalComplexityTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existComplexityTime = subtotalComplexityTimePair.get(reportDeptId);
+                            BigDecimal tempComplexityTime = existComplexityTime.add(complexityTime);
+                            subtotalComplexityTimePair.put(reportDeptId, tempComplexityTime);
+                        } else {
+                            subtotalComplexityTimePair.put(reportDeptId, complexityTime);
+                        }
+                    }
+                    // 生产配合 npt
+                    BigDecimal relocationTime = report.getRelocationTime();
+                    if (ObjUtil.isNotEmpty(relocationTime)) {
+                        if (subtotalRelocationTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existRelocationTime = subtotalRelocationTimePair.get(reportDeptId);
+                            BigDecimal tempRelocationTime = existRelocationTime.add(relocationTime);
+                            subtotalRelocationTimePair.put(reportDeptId, tempRelocationTime);
+                        } else {
+                            subtotalRelocationTimePair.put(reportDeptId, relocationTime);
+                        }
+                    }
+                    // 生产组织 npt
+                    BigDecimal rectificationTime = report.getRectificationTime();
+                    if (ObjUtil.isNotEmpty(rectificationTime)) {
+                        if (subtotalRectificationTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existRectificationTime = subtotalRectificationTimePair.get(reportDeptId);
+                            BigDecimal tempRectificationTime = existRectificationTime.add(rectificationTime);
+                            subtotalRectificationTimePair.put(reportDeptId, tempRectificationTime);
+                        } else {
+                            subtotalRectificationTimePair.put(reportDeptId, rectificationTime);
+                        }
+                    }
+                    // 不可抗力 npt
+                    BigDecimal waitingStopTime = report.getWaitingStopTime();
+                    if (ObjUtil.isNotEmpty(waitingStopTime)) {
+                        if (subtotalWaitingStopTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existWaitingStopTime = subtotalWaitingStopTimePair.get(reportDeptId);
+                            BigDecimal tempWaitingStopTime = existWaitingStopTime.add(waitingStopTime);
+                            subtotalWaitingStopTimePair.put(reportDeptId, tempWaitingStopTime);
+                        } else {
+                            subtotalWaitingStopTimePair.put(reportDeptId, waitingStopTime);
+                        }
+                    }
+                    // 待命 npt
+                    BigDecimal winterBreakTime = report.getWinterBreakTime();
+                    if (ObjUtil.isNotEmpty(winterBreakTime)) {
+                        if (subtotalWinterBreakTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existWinterBreakTime = subtotalWinterBreakTimePair.get(reportDeptId);
+                            BigDecimal tempWinterBreakTime = existWinterBreakTime.add(winterBreakTime);
+                            subtotalWinterBreakTimePair.put(reportDeptId, tempWinterBreakTime);
+                        } else {
+                            subtotalWinterBreakTimePair.put(reportDeptId, winterBreakTime);
+                        }
+                    }
+                    // 甲方设计 npt
+                    BigDecimal partyaDesign = report.getPartyaDesign();
+                    if (ObjUtil.isNotEmpty(partyaDesign)) {
+                        if (subtotalPartyaDesignPair.containsKey(reportDeptId)) {
+                            BigDecimal existPartyaDesign = subtotalPartyaDesignPair.get(reportDeptId);
+                            BigDecimal tempPartyaDesign = existPartyaDesign.add(partyaDesign);
+                            subtotalPartyaDesignPair.put(reportDeptId, tempPartyaDesign);
+                        } else {
+                            subtotalPartyaDesignPair.put(reportDeptId, partyaDesign);
+                        }
+                    }
+                    // 甲方准备 npt
+                    BigDecimal partyaPrepare = report.getPartyaPrepare();
+                    if (ObjUtil.isNotEmpty(partyaPrepare)) {
+                        if (subtotalPartyaPreparePair.containsKey(reportDeptId)) {
+                            BigDecimal existPartyaPrepare = subtotalPartyaPreparePair.get(reportDeptId);
+                            BigDecimal tempPartyaPrepare = existPartyaPrepare.add(partyaPrepare);
+                            subtotalPartyaPreparePair.put(reportDeptId, tempPartyaPrepare);
+                        } else {
+                            subtotalPartyaPreparePair.put(reportDeptId, partyaPrepare);
+                        }
+                    }
+                    // 甲方资源 npt
+                    BigDecimal partyaResource = report.getPartyaResource();
+                    if (ObjUtil.isNotEmpty(partyaResource)) {
+                        if (subtotalPartyaResourcePair.containsKey(reportDeptId)) {
+                            BigDecimal existPartyaResource = subtotalPartyaResourcePair.get(reportDeptId);
+                            BigDecimal tempPartyaResource = existPartyaResource.add(partyaResource);
+                            subtotalPartyaResourcePair.put(reportDeptId, tempPartyaResource);
+                        } else {
+                            subtotalPartyaResourcePair.put(reportDeptId, partyaResource);
+                        }
+                    }
+                    // 其它非生产时间 npt
+                    BigDecimal otherNptTime = report.getOtherNptTime();
+                    if (ObjUtil.isNotEmpty(otherNptTime)) {
+                        if (subtotalOtherNptTimePair.containsKey(reportDeptId)) {
+                            BigDecimal existOtherNptTime = subtotalOtherNptTimePair.get(reportDeptId);
+                            BigDecimal tempOtherNptTime = existOtherNptTime.add(otherNptTime);
+                            subtotalOtherNptTimePair.put(reportDeptId, tempOtherNptTime);
+                        } else {
+                            subtotalOtherNptTimePair.put(reportDeptId, otherNptTime);
+                        }
+                    }
+                }
+            });
+
+            // 计算每个 施工队伍 的 npt小计 npt时效
+            if (CollUtil.isNotEmpty(teamDeptPair)) {
+                teamDeptPair.forEach((teamDeptId, dept) -> {
+                    // 统计当前 施工队伍 所有 npt总和 npt时效
+                    BigDecimal tempSubtotalNpt = BigDecimal.ZERO;
+                    // 计入 npt时效 的非生产时间小计
+                    BigDecimal tempNptSum = BigDecimal.ZERO;
+                    if (subtotalAccidentTimePair.containsKey(teamDeptId)) {
+                        BigDecimal accidentTime = subtotalAccidentTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(accidentTime);
+                        tempNptSum = tempNptSum.add(accidentTime);
+                    }
+                    if (subtotalRepairTimePair.containsKey(teamDeptId)) {
+                        BigDecimal repairTime = subtotalRepairTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(repairTime);
+                        tempNptSum = tempNptSum.add(repairTime);
+                    }
+                    // 设备保养 不计入 非生产时效
+                    if (subtotalSelfStopTimePair.containsKey(teamDeptId)) {
+                        BigDecimal selfStopTime = subtotalSelfStopTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(selfStopTime);
+                    }
+                    if (subtotalComplexityTimePair.containsKey(teamDeptId)) {
+                        BigDecimal complexityTime = subtotalComplexityTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(complexityTime);
+                        tempNptSum = tempNptSum.add(complexityTime);
+                    }
+                    // 生产配合 不计入 非生产时效
+                    if (subtotalRelocationTimePair.containsKey(teamDeptId)) {
+                        BigDecimal relocationTime = subtotalRelocationTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(relocationTime);
+                    }
+                    if (subtotalRectificationTimePair.containsKey(teamDeptId)) {
+                        BigDecimal rectificationTime = subtotalRectificationTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(rectificationTime);
+                        tempNptSum = tempNptSum.add(rectificationTime);
+                    }
+                    if (subtotalWaitingStopTimePair.containsKey(teamDeptId)) {
+                        BigDecimal waitingStopTime = subtotalWaitingStopTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(waitingStopTime);
+                        tempNptSum = tempNptSum.add(waitingStopTime);
+                    }
+                    // 待命 不计入 非生产时效
+                    if (subtotalWinterBreakTimePair.containsKey(teamDeptId)) {
+                        BigDecimal winterBreakTime = subtotalWinterBreakTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(winterBreakTime);
+                    }
+                    if (subtotalPartyaDesignPair.containsKey(teamDeptId)) {
+                        BigDecimal partyaDesign = subtotalPartyaDesignPair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(partyaDesign);
+                        tempNptSum = tempNptSum.add(partyaDesign);
+                    }
+                    if (subtotalPartyaPreparePair.containsKey(teamDeptId)) {
+                        BigDecimal partyaPrepare = subtotalPartyaPreparePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(partyaPrepare);
+                        tempNptSum = tempNptSum.add(partyaPrepare);
+                    }
+                    if (subtotalPartyaResourcePair.containsKey(teamDeptId)) {
+                        BigDecimal partyaResource = subtotalPartyaResourcePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(partyaResource);
+                        tempNptSum = tempNptSum.add(partyaResource);
+                    }
+                    if (subtotalOtherNptTimePair.containsKey(teamDeptId)) {
+                        BigDecimal otherNptTime = subtotalOtherNptTimePair.get(teamDeptId);
+                        tempSubtotalNpt = tempSubtotalNpt.add(otherNptTime);
+                        tempNptSum = tempNptSum.add(otherNptTime);
+                    }
+                    // 施工队伍 npt 小计
+                    subtotalNptTimePair.put(teamDeptId, tempNptSum);
+                    // 施工队伍 npt 时效 以下非生产时间计入非生产时效
+                    // 设备故障repair_time
+                    // 工程质量accident_time
+                    // 技术受限complexity_time
+                    // 生产组织rectification_time
+                    // 不可抗力waiting_stop_time
+                    // 甲方设计partya_design
+                    // 甲方准备partya_prepare
+                    // 甲方资源partya_resource
+                    // 其他非生产时间other_npt_time
+                    if (CollUtil.isNotEmpty(totalHours)) {
+                        Long totalHour = totalHours.get(0);
+                        if (ObjUtil.isNotEmpty(totalHour) && totalHour > 0) {
+                            BigDecimal nptRate = tempNptSum.divide(new BigDecimal(totalHour), 4, RoundingMode.HALF_UP);
+                            subtotalNptRatePair.put(teamDeptId, nptRate);
+                        }
+                    }
+                });
+            }
+
+        }
+
+        // 队伍数据  生成返回的数据列表集合
+        teamDeptPair.forEach((teamDeptId, dept) -> {
+            IotRdDailyReportNptStatisticsRespVO statistics = new IotRdDailyReportNptStatisticsRespVO();
+            statistics.setTeamId(teamDeptId);
+            statistics.setTeamName(dept.getName());
+            statistics.setSort(dept.getSort());
+            if (teamDeptIds.contains(teamDeptId)) {
+                statistics.setType("3");
+            }
+            statistics.setAccidentTime(subtotalAccidentTimePair.get(teamDeptId));
+            statistics.setRepairTime(subtotalRepairTimePair.get(teamDeptId));
+            statistics.setSelfStopTime(subtotalSelfStopTimePair.get(teamDeptId));
+            statistics.setComplexityTime(subtotalComplexityTimePair.get(teamDeptId));
+            statistics.setRelocationTime(subtotalRelocationTimePair.get(teamDeptId));
+            statistics.setRectificationTime(subtotalRectificationTimePair.get(teamDeptId));
+            statistics.setWaitingStopTime(subtotalWaitingStopTimePair.get(teamDeptId));
+            statistics.setWinterBreakTime(subtotalWinterBreakTimePair.get(teamDeptId));
+            statistics.setPartyaDesign(subtotalPartyaDesignPair.get(teamDeptId));
+            statistics.setPartyaPrepare(subtotalPartyaPreparePair.get(teamDeptId));
+            statistics.setPartyaResource(subtotalPartyaResourcePair.get(teamDeptId));
+            statistics.setOtherNptTime(subtotalOtherNptTimePair.get(teamDeptId));
+            statistics.setNptTotal(subtotalNptTimePair.get(teamDeptId));
+            statistics.setNptRate(subtotalNptRatePair.get(teamDeptId));
+            if (CollUtil.isNotEmpty(totalHours)) {
+                Long totalHour = totalHours.get(0);
+                statistics.setCalendarTime(new BigDecimal(totalHour));
+            }
+            result.add(statistics);
+        });
+
+        return result;
+    }
+
     /**
      * 计算两个LocalTime之间的间隔小时数(处理空值、跨天情况)
      * @param startTime 开始时间