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

pms 瑞恒看板 其它项目部的生产动态概述 以队伍为维度展示

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

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

@@ -1101,7 +1101,11 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         if (reqVO.getCreateTime().length < 2) {
             throw exception(IOT_DAILY_REPORT_TIME_NOT_EXISTS);
         }
+        // 所有的项目部id集合
         List<Long> sortedProjectIds = new ArrayList<>();
+        // 需要特殊处理的项目部id集合
+        List<Long> specialProjectIds = new ArrayList<>();
+
         sortedProjectIds.add(157l);
         sortedProjectIds.add(164l); // 塔河项目部
         sortedProjectIds.add(165l); // 塔里木项目部
@@ -1113,6 +1117,14 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         sortedProjectIds.add(273l); // 南美项目部
         sortedProjectIds.add(275l); // 中东项目部
         sortedProjectIds.add(282l); // 中亚项目部
+
+        // 查询 以上每个需要特殊处理的项目部下的队伍部门id
+        specialProjectIds.add(256l); // 川庆项目部
+        specialProjectIds.add(269l); // 非洲项目部
+        specialProjectIds.add(273l); // 南美项目部
+        specialProjectIds.add(275l); // 中东项目部
+        specialProjectIds.add(282l); // 中亚项目部
+
         // 各项目部的设备利用率集合
         List<ProjectUtilizationRateVo> rates = new ArrayList<>();
         // 查询瑞恒 157l 所有项目部
@@ -1122,10 +1134,18 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         Set<Long> projectDeptIds = new HashSet<>();
         // key项目部id   value项目部名称
         Map<Long, String> projectPair = new HashMap<>();
+
+        // key队伍id   value队伍名称
+        Map<Long, String> teamPair = new HashMap<>();
+
         // key项目部id   value项目部包含的队伍id集合
         Map<Long, Set<Long>> projectTeamPair = new HashMap<>();
+        // key项目部id   value项目部包含的队伍集合
+        Map<Long, Set<DeptDO>> projectDepartmentPair = new HashMap<>();
         // 队伍id 集合
         Set<Long> teamDepartmentIds = new HashSet<>();
+        // key项目部id   value项目部包含的排序后的队伍id集合
+        Map<Long, List<Long>> projectSortedTeamIdPair = new HashMap<>();
 
         // key施工队伍id   value状态为LY的项目部id
         Map<Long, Long> teamProjectIdPair = new HashMap<>();
@@ -1174,15 +1194,17 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         }
         if (CollUtil.isNotEmpty(allDeptPair)) {
             allDeptPair.forEach((deptId, dept) -> {
+                String deptName = dept.getName();
                 // 项目部
                 if ("2".equals(dept.getType())) {
                     projectDeptIds.add(deptId);
-                    projectDeptNames.add(dept.getName());
+                    projectDeptNames.add(deptName);
                     projectPair.put(deptId, dept.getName());
                 }
                 // 队伍
                 if ("3".equals(dept.getType())) {
-                    teamDepartmentIds.add(dept.getId());
+                    teamDepartmentIds.add(deptId);
+                    teamPair.put(deptId, deptName);
                 }
             });
             // 遍历所有部门 只筛选出有设备的队伍
@@ -1192,6 +1214,11 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     // 获得当前部门的上级项目部
                     projectPair.forEach((projectDeptId, projectDeptName) -> {
                         if (projectDeptId.equals(dept.getParentId()) && haveDeviceDeptIds.contains(deptId) && teamDepartmentIds.contains(deptId)) {
+                            // 项目部下各队伍id列表初始化
+                            projectSortedTeamIdPair
+                                    .computeIfAbsent(dept.getParentId(), k -> new ArrayList<>())
+                                    .add(deptId);
+
                             if (projectTeamPair.containsKey(projectDeptId)) {
                                 Set<Long> teamIds = projectTeamPair.get(projectDeptId);
                                 teamIds.add(deptId);
@@ -1201,6 +1228,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                                 teamIds.add(deptId);
                                 projectTeamPair.put(projectDeptId, teamIds);
                             }
+
                             // 设置队伍与上级项目部的关联关系集合
                             teamProjectIdPair.put(dept.getId(), dept.getParentId());
                         }
@@ -1210,6 +1238,14 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     });
                 }
             });
+
+            // 对每个项目部下的队伍ID列表,根据队伍的 sort 字段正序排序
+            projectSortedTeamIdPair.forEach((projectId, teamIds) -> {
+                teamIds.sort(Comparator.comparing(
+                        id -> allDeptPair.get(id).getSort(),
+                        Comparator.nullsLast(Integer::compareTo)
+                ));
+            });
         }
         // 查询出指定时间区间内 已经填写的日报数量 存在注气时间是0 但是 注气量 不为0的情况
         // reqVO.setStatisticFlag("Y");
@@ -1222,7 +1258,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             LocalDateTime originalStart = timeRange[0];
             LocalDateTime originalEnd = timeRange[1];
             int statYear = originalStart.getYear();
-            // 取当年1月1日零点 从去12月26日开始统计 工作量
+            // 取当年1月1日零点 从去12月26日开始统计 工作量
             // LocalDateTime yearBegin = LocalDateTime.of(originalStart.getYear(), 1, 1, 0, 0);
             LocalDateTime yearBegin = LocalDateTime.of(statYear - 1, 12, 26, 0, 0);
             yearReqVO.setCreateTime(new LocalDateTime[]{yearBegin, originalEnd});
@@ -1237,9 +1273,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 Long deptId = yearReport.getDeptId();
                 BigDecimal dailyGasInjection = yearReport.getDailyGasInjection();
                 BigDecimal dailyWaterInjection = yearReport.getDailyWaterInjection();
-
                 if (CollUtil.isNotEmpty(projectTeamPair)) {
-
                     // 设置各项目部 按照时间统计的 设备利用率
                     // 各项目部年度 运行时效(按小时统计的设备利用率)
                     // 按小时数 统计设备利用率
@@ -1306,6 +1340,12 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key项目部id     value项目部下包含设备的队伍注气时间或注水时间总和
         Map<Long, BigDecimal> projectWorkTimePair = new HashMap<>();
 
+        // 查询需要特殊处理队伍的 工作量日报数据
+        Map<Long, String> specialTeamWellPair = new HashMap<>();
+        Map<Long, String> specialTeamLocationPair = new HashMap<>();
+        Map<Long, BigDecimal> specialTeamWorkTimePair = new HashMap<>();
+        Map<Long, String> specialTeamProductionPair = new HashMap<>();
+
         if (CollUtil.isNotEmpty(dailyReports)) {
             IotProjectTaskPageReqVO taskReqVO = new IotProjectTaskPageReqVO();
             taskReqVO.setTaskIds(convertList(dailyReports, IotRhDailyReportDO::getTaskId));
@@ -1320,11 +1360,39 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             // 整理出每个项目部下的队伍填报的日报数量
             dailyReports.forEach(report -> {
                 Long deptId = report.getDeptId();
+                // 日注气量
                 BigDecimal dailyGasInjection = report.getDailyGasInjection();
+                // 日注水量
                 BigDecimal dailyWaterInjection = report.getDailyWaterInjection();
+                // 生产动态
+                String dynamic = report.getProductionStatus();
+
+                // 按小时数 统计设备利用率
+                BigDecimal gasInjectionTime = ObjUtil.defaultIfNull(report.getDailyInjectGasTime(), BigDecimal.ZERO);
+                BigDecimal waterInjectionTime = ObjUtil.defaultIfNull(report.getDailyInjectWaterTime(), BigDecimal.ZERO);
+                // 取 注气时间 注水时间 的较大者
+                BigDecimal workTime = gasInjectionTime.compareTo(BigDecimal.ZERO) > 0
+                        ? gasInjectionTime
+                        : waterInjectionTime.compareTo(BigDecimal.ZERO) > 0
+                        ? waterInjectionTime
+                        : BigDecimal.ZERO;
+
+                specialTeamWorkTimePair.put(deptId, workTime);
+
+                // 日报关联的任务井号
+                Long reportTaskId = report.getTaskId();
+                String wellName = StrUtil.EMPTY;
+                String location = StrUtil.EMPTY;
+                if (ObjUtil.isNotEmpty(reportTaskId)) {
+                    wellName = taskWellNamePair.get(reportTaskId);
+                    location = taskLocationPair.get(reportTaskId);
+                }
 
                 if (CollUtil.isNotEmpty(projectTeamPair)) {
-                    projectTeamPair.forEach((projectDeptId, teamDeptIds) -> {
+                    for (Map.Entry<Long, Set<Long>> longSetEntry : projectTeamPair.entrySet()) {
+                        Long projectDeptId = longSetEntry.getKey();
+                        Set<Long> teamDeptIds = longSetEntry.getValue();
+
                         if (teamDeptIds.contains(deptId)) {
                             // 以施工区域为维度统计 队伍总数 施工队伍数 准备队伍数 待命队伍数量
                             Long taskId = report.getTaskId();
@@ -1379,9 +1447,6 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                                 }
                             }
 
-                            // 日报关联的任务井号
-                            Long reportTaskId = report.getTaskId();
-
                             // 提取 所有日报非生产时间和 = 24H 的队伍
                             List<BigDecimal> nptTimeList = Arrays.asList(
                                     report.getAccidentTime(),
@@ -1403,32 +1468,30 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                             BigDecimal twentyFour = new BigDecimal("24");
                             if (totalNptTime.compareTo(twentyFour) == 0) {
                                 // 所有非生产时间和=24H 的队伍 提取生产动态
-                                if (ObjUtil.isNotEmpty(reportTaskId)) {
-                                    String wellName = taskWellNamePair.get(reportTaskId);
-                                    String location = taskLocationPair.get(reportTaskId);
-                                    if (StrUtil.isNotBlank(wellName) && StrUtil.isNotBlank(location)) {
-                                        String dynamic = report.getProductionStatus();
-                                        productionMap.computeIfAbsent(projectDeptId, k -> new HashMap<>())
-                                                .computeIfAbsent(location, k -> new HashMap<>())
-                                                .computeIfAbsent(wellName, k -> new ArrayList<>())
-                                                .add(dynamic);
-                                    }
+                                if (StrUtil.isNotBlank(wellName) && StrUtil.isNotBlank(location)) {
+                                    productionMap.computeIfAbsent(projectDeptId, k -> new HashMap<>())
+                                            .computeIfAbsent(location, k -> new HashMap<>())
+                                            .computeIfAbsent(wellName, k -> new ArrayList<>())
+                                            .add(dynamic);
                                 }
                             }
-                            // 按小时数 统计设备利用率
-                            BigDecimal gasInjectionTime = ObjUtil.defaultIfNull(report.getDailyInjectGasTime(), BigDecimal.ZERO);
-                            BigDecimal waterInjectionTime = ObjUtil.defaultIfNull(report.getDailyInjectWaterTime(), BigDecimal.ZERO);
-                            // 取 注气时间 注水时间 的较大者
-                            BigDecimal workTime = gasInjectionTime.compareTo(BigDecimal.ZERO) > 0
-                                    ? gasInjectionTime
-                                    : waterInjectionTime.compareTo(BigDecimal.ZERO) > 0
-                                    ? waterInjectionTime
-                                    : BigDecimal.ZERO;
+                            // 汇总每个项目部的 工作时间
                             if (workTime.compareTo(BigDecimal.ZERO) > 0) {
                                 projectWorkTimePair.merge(projectDeptId, workTime, BigDecimal::add);
                             }
+
+                            // 需要特殊处理的项目部 单独存储每个队伍的工作量数据 不汇总 项目部数据
+                            if (specialProjectIds.contains(projectDeptId)) {
+                                specialTeamWorkTimePair.put(deptId, workTime);
+                                specialTeamProductionPair.put(deptId, dynamic);
+                                // 查询当前队伍关联的 任务 井号 施工区域
+                                specialTeamWellPair.put(deptId, wellName);
+                                specialTeamLocationPair.put(deptId, location);
+
+                            }
                         }
-                    });
+                    }
+
                 }
                 // 统计所有队伍的注气量 注水量 不区分是否包含主设备
                 if (teamIdProjectIdPair.containsKey(deptId)) {
@@ -1485,6 +1548,62 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 yearTotalDays.add(yearTotalDay);
             }
 
+            // 组合每个 需要特殊处理的 项目部下的队伍的工作量 队伍名称 施工区域 井号 施工时间 施工动态
+            Map<Long, String> projectProductionPair = new HashMap<>();
+            if (CollUtil.isNotEmpty(projectSortedTeamIdPair)) {
+                projectSortedTeamIdPair.forEach((projectDeptId, sortedTeamIds) -> {
+                    if (specialProjectIds.contains(projectDeptId)) {
+                        String content = sortedTeamIds.stream()
+                                .filter(teamId -> specialTeamLocationPair.containsKey(teamId)
+                                        && teamPair.containsKey(teamId)
+                                        && specialTeamWellPair.containsKey(teamId)
+                                        && specialTeamWorkTimePair.containsKey(teamId))
+                                .map(teamId -> {
+                                    BigDecimal workTime = specialTeamWorkTimePair.get(teamId);
+                                    String location = specialTeamLocationPair.get(teamId);
+                                    String teamName = teamPair.get(teamId);
+                                    String well     = specialTeamWellPair.get(teamId);
+                                    String production = specialTeamProductionPair.get(teamId);
+
+                                    // 施工时间为 0
+                                    boolean isZero = ObjUtil.isNotEmpty(workTime)
+                                            && BigDecimal.ZERO.compareTo(workTime) == 0;
+
+                                    StringBuilder sb = new StringBuilder();
+
+                                    // 1. 施工区域 + 队伍名称(施工区域为空时,不显示“:”)
+                                    if (StrUtil.isNotBlank(location)) {
+                                        sb.append(location).append(":");
+                                    }
+                                    if (StrUtil.isNotBlank(teamName)) {
+                                        sb.append(teamName);
+                                    }
+
+                                    // 2. 井号(为空则不显示前面的“,”)
+                                    if (StrUtil.isNotBlank(well)) {
+                                        sb.append(",").append(well);
+                                    }
+
+                                    // 3. 施工时间(为 0 或为空 时,整段“、施工‘xx’小时”不显示)
+                                    if (ObjUtil.isNotEmpty(workTime) && !isZero) {
+                                        sb.append("、施工").append(workTime.toPlainString()).append("小时");
+                                    }
+
+                                    // 4. 施工动态(仅当施工时间为 0 且动态非空时显示;为空则不显示前面的“,”)
+                                    if (isZero && StrUtil.isNotBlank(production)) {
+                                        sb.append(",").append(production);
+                                    }
+
+                                    sb.append("。");
+                                    return sb.toString();
+                                })
+                                .collect(Collectors.joining("\n"));
+
+                        projectProductionPair.put(projectDeptId, content);
+                    }
+                });
+            }
+
             // 计算每个项目部的设备利用率
             if (CollUtil.isNotEmpty(projectTeamPair)) {
                 projectTeamPair.forEach((projectDeptId, teamIds) -> {
@@ -1592,6 +1711,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                                 }
                             }
                         }
+                        // 需要特殊处理的 项目部 施工动态
+                        if (projectProductionPair.containsKey(projectDeptId)) {
+                            rateVo.setProductionSummary(projectProductionPair.get(projectDeptId));
+                        }
                         rates.add(rateVo);
                     }
                 });
@@ -1717,7 +1840,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
 
             Map<String, Map<String, List<String>>> locationMap = productionMap.get(rate.getProjectDeptId());
             // 组装各项目部 按照施工区域维度统计 的 队伍数量 生产动态明细
-            if (locationMap != null && !locationMap.isEmpty()) {
+            if (locationMap != null && !locationMap.isEmpty() && !specialProjectIds.contains(rate.getProjectDeptId())) {
                 Map<String, Set<Long>> teamMap = projectLocationTeamSet.getOrDefault(rate.getProjectDeptId(), Collections.emptyMap());
                 Map<String, Set<Long>> sgTeamMap = projectLocationSgTeamSet.getOrDefault(rate.getProjectDeptId(), Collections.emptyMap());