瀏覽代碼

pms 瑞恒日报 统计 已填报 未填报 与 运行记录 数据保持一致。

zhangcl 1 天之前
父節點
當前提交
9ed0922840

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

@@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
 import cn.iocoder.yudao.module.pms.constant.PmsConstants;
 import cn.iocoder.yudao.module.pms.controller.admin.iotcarzhbd.vo.IotCarZhbdPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicecategorytemplateattrs.vo.IotDeviceProperty;
+import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotprojecttask.vo.IotProjectTaskPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.*;
@@ -1159,60 +1160,92 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         List<IotRhDailyReportStatisticsVO> results = new ArrayList<>();
         // 查询 瑞恒157l 所有存在设备的队伍
         // 查询瑞恒下所有部门
-        List<IotDeviceDO> devices = devices();
+        // List<IotDeviceDO> devices = devices();
         // 所有需要填报日报的 瑞恒 队伍集合
         Set<Long> deptIds = new HashSet<>();
-        if (CollUtil.isNotEmpty(devices)){
-            devices.forEach(device -> {
-                deptIds.add(device.getDeptId());
-            });
-            // 根据部门id集合查询所有部门信息
-            // 查询所有部门信息
-            Map<Long, DeptDO> allDepts = deptService.getDeptMap(deptIds);
-            // 过滤后的所有部门信息
-            Map<Long, DeptDO> filteredDepts = new HashMap<>();
-            // 过滤掉部门中的 ‘项目部’
-            if (CollUtil.isNotEmpty(allDepts)) {
-                allDepts.forEach((deptId, dept) -> {
-                    // 将不属于 队伍 的组织部门过滤掉
-                    if ("3".equals(dept.getType())) {
-                        filteredDepts.put(deptId, dept);
-                    }
-                });
-            }
+        /* devices.forEach(device -> {
+            deptIds.add(device.getDeptId());
+        }); */
+
+        Set<Long> ids = new HashSet<>();
+        ids = deptService.getChildDeptIdListFromCache(157l);
+        ids.add(157l);
 
-            // 比如有20个队伍 某个时间区间D内 必须有20*D份日报 时间区间最好是1天
-            // 查询出指定时间区间内 已经填写的日报数量
-            List<IotRhDailyReportDO> dailyReports = iotRhDailyReportMapper.dailyReports(reqVO);
-            // 根据指定的时间区间 计算出天数
-            LocalDateTime[] createTimes = reqVO.getCreateTime();
-            // 获取开始时间和结束时间
-            LocalDateTime startTime = createTimes[0];
-            LocalDateTime endTime = createTimes[1];
-            // 截断到日期(忽略时分秒)
-            LocalDate startDate = startTime.toLocalDate();
-            LocalDate endDate = endTime.toLocalDate();
-            // 计算天数:日期差 + 1(包含首尾两天)
-            long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
-            // 计算指定时间区间内所有日报数量总数
-            long totalRequiredReports = (long) filteredDepts.size() * days;
-            // 获取【实际已报的日报数量】
-            long totalReportedReports = CollUtil.isNotEmpty(dailyReports) ? dailyReports.size() : 0l;
-            // 计算指定时间区间内未填报的日报数量
-            long notReportedCount = totalRequiredReports - totalReportedReports;
-            IotRhDailyReportStatisticsVO allReports = new IotRhDailyReportStatisticsVO();
-            allReports.setGroupName("总数");
-            allReports.setCount(totalRequiredReports);
-            IotRhDailyReportStatisticsVO haveReported = new IotRhDailyReportStatisticsVO();
-            haveReported.setGroupName("已填报");
-            haveReported.setCount(totalReportedReports);
-            IotRhDailyReportStatisticsVO notReported = new IotRhDailyReportStatisticsVO();
-            notReported.setGroupName("未填报");
-            notReported.setCount(notReportedCount);
-            results.add(allReports);
-            results.add(haveReported);
-            results.add(notReported);
+        // 根据部门id集合查询所有部门信息
+        // 查询所有部门信息
+        // Map<Long, DeptDO> allDepts = deptService.getDeptMap(deptIds);
+        // 过滤后的所有部门信息
+        // Map<Long, DeptDO> filteredDepts = new HashMap<>();
+        // 过滤掉部门中的 ‘项目部’
+        /* if (CollUtil.isNotEmpty(allDepts)) {
+            allDepts.forEach((deptId, dept) -> {
+                // 将不属于 队伍 的组织部门过滤掉
+                if ("3".equals(dept.getType())) {
+                    filteredDepts.put(deptId, dept);
+                }
+            });
+        } */
+
+        // 瑞恒日报总数
+        Integer rhTotalCount = 0;
+        // 瑞恒已填报完成日报总数
+        AtomicReference<Integer> rhFinishedCount = new AtomicReference<>(0);
+        // 瑞恒未填报完成日报总数
+        AtomicReference<Integer> rhUnfinishedCount = new AtomicReference<>(0);
+
+        // 以运行记录表中 指定 时间范围内的 名称中包含 ‘生产日报’ 工单的部门为基数
+        // 瑞鹰钻井 rq_iot_opeation_fill rq_iot_opeation_fill_order 关联查询
+        // 瑞鹰修井 需要结合 挂靠队伍 日报
+        IotOpeationFillPageReqVO fillReqVO = new IotOpeationFillPageReqVO();
+        fillReqVO.setCreateTime(reqVO.getCreateTime());
+        fillReqVO.setDeptIds(new ArrayList<>(ids));
+        List<IotOpeationFillDO> fills = iotOpeationFillMapper.countFills(fillReqVO);
+
+        if (CollUtil.isNotEmpty(fills)) {
+            rhTotalCount = fills.size();
+            fills.forEach(fill -> {
+                // 找出所有已经填报完成的队伍
+                if (1 == fill.getIsFill()) {
+                    // 填报完成
+                    rhFinishedCount.set(rhFinishedCount.get() + 1);
+                } else {
+                    // 填报中属于未填报完成
+                    rhUnfinishedCount.set(rhUnfinishedCount.get() + 1);
+                }
+            });
         }
+
+        // 比如有20个队伍 某个时间区间D内 必须有20*D份日报 时间区间最好是1天
+        // 查询出指定时间区间内 已经填写的日报数量
+        // List<IotRhDailyReportDO> dailyReports = iotRhDailyReportMapper.dailyReports(reqVO);
+        // 根据指定的时间区间 计算出天数
+        LocalDateTime[] createTimes = reqVO.getCreateTime();
+        // 获取开始时间和结束时间
+        LocalDateTime startTime = createTimes[0];
+        LocalDateTime endTime = createTimes[1];
+        // 截断到日期(忽略时分秒)
+        LocalDate startDate = startTime.toLocalDate();
+        LocalDate endDate = endTime.toLocalDate();
+        // 计算天数:日期差 + 1(包含首尾两天)
+        long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
+        // 计算指定时间区间内所有日报数量总数
+        // long totalRequiredReports = (long) filteredDepts.size() * days;
+        // 获取【实际已报的日报数量】
+        // long totalReportedReports = CollUtil.isNotEmpty(dailyReports) ? dailyReports.size() : 0l;
+        // 计算指定时间区间内未填报的日报数量
+        // long notReportedCount = totalRequiredReports - totalReportedReports;
+        IotRhDailyReportStatisticsVO allReports = new IotRhDailyReportStatisticsVO();
+        allReports.setGroupName("总数");
+        allReports.setCount(rhTotalCount);
+        IotRhDailyReportStatisticsVO haveReported = new IotRhDailyReportStatisticsVO();
+        haveReported.setGroupName("已填报");
+        haveReported.setCount(rhFinishedCount.get());
+        IotRhDailyReportStatisticsVO notReported = new IotRhDailyReportStatisticsVO();
+        notReported.setGroupName("未填报");
+        notReported.setCount(rhUnfinishedCount.get());
+        results.add(allReports);
+        results.add(haveReported);
+        results.add(notReported);
         return results;
     }
 
@@ -1225,117 +1258,151 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             throw exception(IOT_DAILY_REPORT_TIME_NOT_EXISTS);
         }
         List<IotRhDailyReportStatisticsVO> results = new ArrayList<>();
-        List<IotDeviceDO> devices = devices();
+        // List<IotDeviceDO> devices = devices();
         // 所有需要填报日报的 瑞恒 队伍集合
         Set<Long> deptIds = new HashSet<>();
         List<String> reportDates = new ArrayList<>();
-        if (CollUtil.isNotEmpty(devices)){
-            devices.forEach(device -> {
-                deptIds.add(device.getDeptId());
+        /* devices.forEach(device -> {
+            deptIds.add(device.getDeptId());
+        }); */
+
+        Set<Long> ids = new HashSet<>();
+        ids = deptService.getChildDeptIdListFromCache(157l);
+        ids.add(157l);
+
+        // 以运行记录表中 指定 时间范围内的 名称中包含 ‘生产日报’ 工单的部门为基数
+        // 瑞鹰钻井 rq_iot_opeation_fill rq_iot_opeation_fill_order 关联查询
+        // 瑞鹰修井 需要结合 挂靠队伍 日报
+        IotOpeationFillPageReqVO fillReqVO = new IotOpeationFillPageReqVO();
+        fillReqVO.setCreateTime(reqVO.getCreateTime());
+        fillReqVO.setDeptIds(new ArrayList<>(ids));
+        List<IotOpeationFillDO> fills = iotOpeationFillMapper.countFills(fillReqVO);
+
+        // 根据指定的时间区间 计算出天数
+        LocalDateTime[] createTimes = reqVO.getCreateTime();
+        // 获取开始时间和结束时间
+        LocalDateTime startTime = createTimes[0];
+        LocalDateTime endTime = createTimes[1];
+        // 截断到日期(忽略时分秒)
+        LocalDate startDate = startTime.toLocalDate();
+        LocalDate endDate = endTime.toLocalDate();
+        // 将时间区间拆分成具体的每天 计算每天未填报日报的队伍明细
+        Set<LocalDate> dateSet = new HashSet<>();
+        LocalDate currentDate = startDate;
+        // 循环添加从开始日期到结束日期的所有日期(包含两端)
+        while (!currentDate.isAfter(endDate)) {
+            dateSet.add(currentDate);
+            currentDate = currentDate.plusDays(1); // 日期加1天
+        }
+        // 转换为字符串格式的日期集合(如:2025-10-06)
+        reportDates = dateSet.stream()
+                .map(date -> date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
+                .collect(Collectors.toList());
+        // 比如有20个队伍 某个时间区间D内 必须有20*D份日报 时间区间最好是1天
+        // 查询出指定时间区间内 已经填写的日报数量
+        // List<IotRhDailyReportDO> dailyReports = iotRhDailyReportMapper.dailyReports(reqVO);
+        // 已经填报的队伍名称集合
+        Map<String, List<String>> reportedDeptNames = new HashMap<>();
+        // 未填报的队伍名称集合
+        Map<String, List<String>> unReportedDeptNames = new HashMap<>();
+        // 查询所有部门信息
+        Map<Long, DeptDO> allDepts = deptService.getDeptMap(ids);
+        // 过滤后的所有部门信息
+        Map<Long, DeptDO> filteredDepts = new HashMap<>();
+        // 过滤掉部门中的 ‘项目部’
+        /* if (CollUtil.isNotEmpty(allDepts)) {
+            allDepts.forEach((deptId, dept) -> {
+                if ("3".equals(dept.getType())) {
+                    filteredDepts.put(deptId, dept);
+                }
             });
-            // 根据指定的时间区间 计算出天数
-            LocalDateTime[] createTimes = reqVO.getCreateTime();
-            // 获取开始时间和结束时间
-            LocalDateTime startTime = createTimes[0];
-            LocalDateTime endTime = createTimes[1];
-            // 截断到日期(忽略时分秒)
-            LocalDate startDate = startTime.toLocalDate();
-            LocalDate endDate = endTime.toLocalDate();
-            // 将时间区间拆分成具体的每天 计算每天未填报日报的队伍明细
-            Set<LocalDate> dateSet = new HashSet<>();
-            LocalDate currentDate = startDate;
-            // 循环添加从开始日期到结束日期的所有日期(包含两端)
-            while (!currentDate.isAfter(endDate)) {
-                dateSet.add(currentDate);
-                currentDate = currentDate.plusDays(1); // 日期加1天
-            }
-            // 转换为字符串格式的日期集合(如:2025-10-06)
-            reportDates = dateSet.stream()
-                    .map(date -> date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
-                    .collect(Collectors.toList());
-            // 比如有20个队伍 某个时间区间D内 必须有20*D份日报 时间区间最好是1天
-            // 查询出指定时间区间内 已经填写的日报数量
-            List<IotRhDailyReportDO> dailyReports = iotRhDailyReportMapper.dailyReports(reqVO);
-            // 已经填报的队伍名称集合
-            Map<String, List<String>> reportedDeptNames = new HashMap<>();
-            // 未填报的队伍名称集合
-            Map<String, List<String>> unReportedDeptNames = new HashMap<>();
-            // 查询所有部门信息
-            Map<Long, DeptDO> allDepts = deptService.getDeptMap(deptIds);
-            // 过滤后的所有部门信息
-            Map<Long, DeptDO> filteredDepts = new HashMap<>();
-            // 过滤掉部门中的 ‘项目部’
-            if (CollUtil.isNotEmpty(allDepts)) {
-                allDepts.forEach((deptId, dept) -> {
-                    if ("3".equals(dept.getType())) {
-                        filteredDepts.put(deptId, dept);
-                    }
-                });
-            }
-            if (CollUtil.isNotEmpty(dailyReports)) {
-                // 组装每天填写的日报集合 从而统计出每天未填写日报的队伍
-                dailyReports.forEach(report -> {
-                    Long tempDeptId = report.getDeptId();
-                    if (filteredDepts.containsKey(tempDeptId)) {
-                        String deptName = filteredDepts.get(tempDeptId).getName();
-                        LocalDateTime createTime = report.getCreateTime();
-                        LocalDate tempDate = createTime.toLocalDate();
-                        String tempReportDate = tempDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-                        if (reportedDeptNames.containsKey(tempReportDate)) {
-                            List<String> tempDeptNames = reportedDeptNames.get(tempReportDate);
-                            tempDeptNames.add(deptName);
-                            reportedDeptNames.put(tempReportDate, tempDeptNames);
-                        } else {
-                            List<String> tempDeptNames = new ArrayList<>();
-                            tempDeptNames.add(deptName);
-                            reportedDeptNames.put(tempReportDate, tempDeptNames);
-                        }
+        } */
+        /* if (CollUtil.isNotEmpty(dailyReports)) {
+            // 组装每天填写的日报集合 从而统计出每天未填写日报的队伍
+            dailyReports.forEach(report -> {
+                Long tempDeptId = report.getDeptId();
+                if (filteredDepts.containsKey(tempDeptId)) {
+                    String deptName = filteredDepts.get(tempDeptId).getName();
+                    LocalDateTime createTime = report.getCreateTime();
+                    LocalDate tempDate = createTime.toLocalDate();
+                    String tempReportDate = tempDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+                    if (reportedDeptNames.containsKey(tempReportDate)) {
+                        List<String> tempDeptNames = reportedDeptNames.get(tempReportDate);
+                        tempDeptNames.add(deptName);
+                        reportedDeptNames.put(tempReportDate, tempDeptNames);
+                    } else {
+                        List<String> tempDeptNames = new ArrayList<>();
+                        tempDeptNames.add(deptName);
+                        reportedDeptNames.put(tempReportDate, tempDeptNames);
                     }
-                });
-            }
-            // 遍历所有时间区间的日期 组装每个日期中 未填写日报的队伍名称集合
-            if (CollUtil.isNotEmpty(reportDates)) {
-                reportDates.forEach(dateStr -> {
-                    // 对时间区间内每个日期 都经过已经填报日报的过滤
-                    if (reportedDeptNames.containsKey(dateStr)) {
-                        List<String> tempReportedDeptNames = reportedDeptNames.get(dateStr);
-                        filteredDepts.forEach((deptId, dept) -> {
-                            if (!tempReportedDeptNames.contains(dept.getName())) {
-                                if (unReportedDeptNames.containsKey(dateStr)) {
-                                    List<String> tempDeptNames = unReportedDeptNames.get(dateStr);
-                                    tempDeptNames.add(dept.getName());
-                                    unReportedDeptNames.put(dateStr, tempDeptNames);
-                                } else {
-                                    List<String> tempDeptNames = new ArrayList<>();
-                                    tempDeptNames.add(dept.getName());
-                                    unReportedDeptNames.put(dateStr, tempDeptNames);
-                                }
+                }
+            });
+        } */
+        // 遍历所有时间区间的日期 组装每个日期中 未填写日报的队伍名称集合
+        /* if (CollUtil.isNotEmpty(reportDates)) {
+            reportDates.forEach(dateStr -> {
+                // 对时间区间内每个日期 都经过已经填报日报的过滤
+                if (reportedDeptNames.containsKey(dateStr)) {
+                    List<String> tempReportedDeptNames = reportedDeptNames.get(dateStr);
+                    filteredDepts.forEach((deptId, dept) -> {
+                        if (!tempReportedDeptNames.contains(dept.getName())) {
+                            if (unReportedDeptNames.containsKey(dateStr)) {
+                                List<String> tempDeptNames = unReportedDeptNames.get(dateStr);
+                                tempDeptNames.add(dept.getName());
+                                unReportedDeptNames.put(dateStr, tempDeptNames);
+                            } else {
+                                List<String> tempDeptNames = new ArrayList<>();
+                                tempDeptNames.add(dept.getName());
+                                unReportedDeptNames.put(dateStr, tempDeptNames);
                             }
-                        });
-                    } else {
-                        // 当天没有任何队伍填写日报
-                        filteredDepts.forEach((deptId, dept) -> {
+                        }
+                    });
+                } else {
+                    // 当天没有任何队伍填写日报
+                    filteredDepts.forEach((deptId, dept) -> {
+                        List<String> tempDeptNames = new ArrayList<>();
+                        tempDeptNames.add(dept.getName());
+                        unReportedDeptNames.put(dateStr, tempDeptNames);
+                    });
+                }
+            });
+        } */
+
+        if (CollUtil.isNotEmpty(fills)) {
+            fills.forEach(fill -> {
+                if (1 != fill.getIsFill()) {
+                    // 未完成填报
+                    LocalDate tempDate = fill.getCreateTime().toLocalDate();
+                    String tempDateStr = tempDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+                    if (allDepts.containsKey(fill.getDeptId())) {
+                        DeptDO dept = allDepts.get(fill.getDeptId());
+                        if (unReportedDeptNames.containsKey(tempDateStr)) {
+                            List<String> tempDeptNames = unReportedDeptNames.get(tempDateStr);
+                            tempDeptNames.add(dept.getName());
+                            unReportedDeptNames.put(tempDateStr, tempDeptNames);
+                        } else {
                             List<String> tempDeptNames = new ArrayList<>();
                             tempDeptNames.add(dept.getName());
-                            unReportedDeptNames.put(dateStr, tempDeptNames);
-                        });
+                            unReportedDeptNames.put(tempDateStr, tempDeptNames);
+                        }
                     }
-                });
-            }
-            // 将集合中的未填报日报的队伍集合转换成 逗号 分隔的字符串
-            if (CollUtil.isNotEmpty(unReportedDeptNames)) {
-                unReportedDeptNames.forEach((reportDate, deptList) -> {
-                    IotRhDailyReportStatisticsVO dailyReportVO = new IotRhDailyReportStatisticsVO();
-                    dailyReportVO.setReportDate(reportDate);
-                    dailyReportVO.setDeptNames(deptList.stream().collect(Collectors.joining(",")));
-                    dailyReportVO.setCount(deptList.size());
-                    results.add(dailyReportVO);
-                });
-                // 使用Comparator进行排序
-                results.sort(Comparator
-                        .comparing(IotRhDailyReportStatisticsVO::getReportDate,
-                                Comparator.nullsLast(Comparator.reverseOrder())));
-            }
+                }
+            });
+        }
+
+        // 将集合中的未填报日报的队伍集合转换成 逗号 分隔的字符串
+        if (CollUtil.isNotEmpty(unReportedDeptNames)) {
+            unReportedDeptNames.forEach((reportDate, deptList) -> {
+                IotRhDailyReportStatisticsVO dailyReportVO = new IotRhDailyReportStatisticsVO();
+                dailyReportVO.setReportDate(reportDate);
+                dailyReportVO.setDeptNames(deptList.stream().collect(Collectors.joining(",")));
+                dailyReportVO.setCount(deptList.size());
+                results.add(dailyReportVO);
+            });
+            // 使用Comparator进行排序
+            results.sort(Comparator
+                    .comparing(IotRhDailyReportStatisticsVO::getReportDate,
+                            Comparator.nullsLast(Comparator.reverseOrder())));
         }
         return results;
     }

+ 4 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportServiceImpl.java

@@ -562,7 +562,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
 
             // 比如有20个队伍 某个时间区间D内 必须有20*D份日报 时间区间最好是1天
             // 查询出指定时间区间内 已经填写的日报数量
-            List<IotRyDailyReportDO> dailyReports = iotRyDailyReportMapper.dailyReports(pageReqVO);
+            // List<IotRyDailyReportDO> dailyReports = iotRyDailyReportMapper.dailyReports(pageReqVO);
             // 根据指定的时间区间 计算出天数
             LocalDateTime[] createTimes = pageReqVO.getCreateTime();
             // 获取开始时间和结束时间
@@ -576,9 +576,9 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             // 计算指定时间区间内所有日报数量总数
             long totalRequiredReports = (long) filteredDepts.size() * days;
             // 获取【实际已报的日报数量】
-            long totalReportedReports = CollUtil.isNotEmpty(dailyReports) ? dailyReports.size() : 0l;
+            // long totalReportedReports = CollUtil.isNotEmpty(dailyReports) ? dailyReports.size() : 0l;
             // 计算指定时间区间内未填报的日报数量
-            long notReportedCount = totalRequiredReports - totalReportedReports;
+            // long notReportedCount = totalRequiredReports - totalReportedReports;
             IotRyDailyReportStatisticsVO allReports = new IotRyDailyReportStatisticsVO();
             allReports.setGroupName("总数");
             allReports.setCount(zxjTotalCount);
@@ -729,7 +729,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
 
         if (CollUtil.isNotEmpty(fills)) {
             fills.forEach(fill -> {
-                if (0 == fill.getIsFill()) {
+                if (1 != fill.getIsFill()) {
                     // 未完成填报
                     LocalDate tempDate = fill.getCreateTime().toLocalDate();
                     String tempDateStr = tempDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));