Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/master'

lipenghui 3 dní pred
rodič
commit
42396b76ea

+ 49 - 5
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmaintenancebom/IotMaintenanceBomController.java

@@ -266,10 +266,54 @@ public class IotMaintenanceBomController {
                 }
             });
         }
-        // 查询正常的累计运行时长 公里数 时需要 携带 设备分类id 方便快速定位 累计属性值
 
+        // deviceRunLogPair 集合中如果存在未生成运行记录的 多累计属性 自动补全
+        Map<Long, List<IotDeviceRunLogRespVO>> copyDeviceRunLogPair = new HashMap<>(deviceRunLogPair);
+        deviceRunLogPair.forEach((deviceId, runLogs) -> {
+            List<IotDeviceRunLogRespVO> copyRunLogs = copyDeviceRunLogPair.get(deviceId);
+            List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(deviceId);
+            copyDeviceRunLogPair.get(deviceId);
+            if (deviceMultiAttrsPair.containsKey(deviceId)) {
+                List<String> multiAttrNames = deviceMultiAttrsPair.get(deviceId);
+                List<IotDeviceRunLogRespVO> unRunLogs = new ArrayList<>();
+                if (CollUtil.isNotEmpty(multiAttrNames) && (multiAttrNames.size() > copyRunLogs.size())) {
+                    multiAttrNames.forEach(attr -> {
+                        timeRunLogs.forEach(runLog -> {
+                            if (!attr.equals(runLog.getPointName())) {
+                                // 当前的多累计属性没有产生运行记录数据
+                                IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
+                                tempRunLog.setPointName(attr);
+                                tempRunLog.setType(1);
+                                tempRunLog.setDeviceId(runLog.getDeviceId());
+                                unRunLogs.add(tempRunLog);
+                            }
+                        });
+                    });
+                    timeRunLogs.addAll(unRunLogs);
+                    copyDeviceRunLogPair.put(deviceId, timeRunLogs);
+                }
+            }
+        });
+
+        // 查询正常的累计运行时长 公里数 时需要 携带 设备分类id 方便快速定位 累计属性值
+        // 相同设备如果都包含 totalRuntime totalMileage 则返回1个对象
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
                 bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+        // 没有产生运行记录的单累计属性 返回前端 0 deviceAttrsPair单属性属性集合
+        if (CollUtil.isNotEmpty(deviceAttrsPair)) {
+            deviceAttrsPair.forEach((deviceId, attrs) -> {
+                if (!deviceRunLogMap.containsKey(deviceId)) {
+                    // 当前设备没有产生运行记录数据
+                    attrs.forEach(attr -> {
+                        IotDeviceRunLogRespVO runLog = new IotDeviceRunLogRespVO();
+                        runLog.setTotalRunTime(BigDecimal.ZERO);
+                        runLog.setTotalMileage(BigDecimal.ZERO);
+                        runLog.setPointName(attr.getName());
+                        deviceRunLogMap.put(deviceId, runLog);
+                    });
+                }
+            });
+        }
         // 2. 转换成 VO
         return BeanUtils.toBean(BOMs, IotMaintenanceBomRespVO.class, bomVO -> {
             // 设置设备相关信息
@@ -302,12 +346,12 @@ public class IotMaintenanceBomController {
                     bomVO.setTempTotalMileage(tempTotalRunDataPair.get(uniqueKey));
                 }
             }
-            // 如果多累计时长 公里数属性 没有运行记录填报数据,只返回 属性名称集合
-            if (deviceRunLogPair.containsKey(bomVO.getDeviceId())) {
+            // 如果多累计时长 公里数属性 没有运行记录填报数据,且运行记录模板中 属性标识符没有配置 累计时长 累计公里数 只返回 属性名称集合
+            if (copyDeviceRunLogPair.containsKey(bomVO.getDeviceId())) {
                 // 设置每个保养项对应的 多个累计类型属性集合 包含属性的运行记录值
                 // 区分开 时间 里程 的累计属性列表 便于前端选择
                 List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
-                List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(bomVO.getDeviceId());
+                List<IotDeviceRunLogRespVO> timeRunLogs = copyDeviceRunLogPair.get(bomVO.getDeviceId());
                 timeRunLogs.forEach(log -> {
                     log.setType(1);
                     IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
@@ -321,7 +365,7 @@ public class IotMaintenanceBomController {
                 // 如果多累计属性没有运行记录填报值 则直接返回 名称 可以设置 累计运行时长 或 公里数 为 0
                 List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
                 List<IotDeviceRunLogRespVO> timeRunLogs = new ArrayList<>();
-                if (deviceMultiAttrsPair.containsKey(bomVO.getDeviceId())) {
+                if (deviceMultiAttrsPair.containsKey(bomVO.getDeviceId()) && !deviceAttrsPair.containsKey(bomVO.getDeviceId())) {
                     List<String> attrNames = deviceMultiAttrsPair.get(bomVO.getDeviceId());
                     attrNames.forEach(attrName -> {
                         IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();

+ 99 - 48
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -679,15 +679,17 @@ public class IotDeviceServiceImpl implements IotDeviceService {
         Map<Long, Long> deviceCategoryPair = new HashMap<>();
         // k设备id   v设备分类包含的模板中与累计运行时长、累计运行公里数相关的属性集合
         Map<Long, List<IotModelTemplateAttrsDO>> deviceAttrsPair = new HashMap<>();
+        // k设备id   v设备分类包含的模板中与累计运行时长、累计运行公里数相关的属性(多种累计属性)集合
+        Map<Long, List<IotModelTemplateAttrsDO>> deviceMultiAttrsPair = new HashMap<>();
         // 查询所有 设备boms节点的所有上级节点名称 拼接出 全路径 的bom节点
         List<Long> bomNodeIds = new ArrayList<>();
         // key设备id  value设备对应的运行记录模板中涉及多个累计时长累计公里数的属性集合
         Map<Long, List<IotDeviceRunLogRespVO>> deviceRunLogPair = new HashMap<>();
         // 设备所属部门id集合
         Set<Long> deptIds = new HashSet<>();
+        // 设备运行模板中正常的 累计时长 累计里程 集合
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = new HashMap<>();
         if (CollUtil.isNotEmpty(devices)) {
-            // 设备运行模板中正常的 累计时长 累计里程 集合
-            Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = new HashMap<>();
             devices.forEach(device -> {
                 deviceIds.add(device.getId());
                 bomNodeIds.add(Long.valueOf(device.getBomNodeId()));
@@ -701,12 +703,14 @@ public class IotDeviceServiceImpl implements IotDeviceService {
 
             if (CollUtil.isNotEmpty(deviceCategoryIds)) {
                 // 查询设备分类id集合对应的运行记录模板中涉及 累计运行时长、累计运行公里数 的属性
-                IotModelTemplateAttrsPageReqVO reqVO = new IotModelTemplateAttrsPageReqVO();
-                reqVO.setMultipleFlag("Y");
-                reqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
-                reqVO.setIsSum(1);  // 累计属性标识
-                List<IotModelTemplateAttrsDO> accumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(reqVO);
-                // k设备分类id   v设备分类包含的模板中 多个 累计运行时长 累计运行公里数相关的属性集合
+                IotModelTemplateAttrsPageReqVO singleAttrreqVO = new IotModelTemplateAttrsPageReqVO();
+                List<String> codes = new ArrayList<>(Arrays.asList("sc", "gls"));
+                singleAttrreqVO.setCodes(codes);
+                singleAttrreqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
+                singleAttrreqVO.setIsSum(1);  // 累计属性标识
+                // 查询标识的累计类型属性 累计运行时长 累计运行公里数 正常的累计属性
+                List<IotModelTemplateAttrsDO> accumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(singleAttrreqVO);
+                // k设备分类id   v设备分类包含的模板中与累计运行时长 累计运行公里数相关的属性集合
                 Map<Long, List<IotModelTemplateAttrsDO>> accumulatedAttrPair = new HashMap<>();
                 if (CollUtil.isNotEmpty(accumulatedAttrs)) {
                     accumulatedAttrs.forEach(attr -> {
@@ -719,17 +723,50 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                             tempAttrs.add(attr);
                             accumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
                         }
-                        multipleAttrNames.add(attr.getName());
                     });
                 }
                 if (CollUtil.isNotEmpty(accumulatedAttrPair)) {
                     accumulatedAttrPair.forEach((k,v) -> {
+                        // k设备分类id   v设备分类包含的模板中与累计运行时长 累计运行公里数相关的属性集合
+                        deviceCategoryPair.forEach((ik, iv) -> {
+                            // ik设备id   iv设备分类id
+                            if (iv.equals(k)) {
+                                deviceAttrsPair.put(ik, v);
+                            }
+                        });
+                    });
+                }
+
+                // 查询设备分类id集合对应的运行记录模板中涉及 累计运行时长、累计运行公里数 的属性
+                IotModelTemplateAttrsPageReqVO reqVO = new IotModelTemplateAttrsPageReqVO();
+                reqVO.setMultipleFlag("Y");
+                reqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
+                reqVO.setIsSum(1);  // 累计属性标识
+                List<IotModelTemplateAttrsDO> multiAccumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(reqVO);
+                // k设备分类id   v设备分类包含的模板中 多个 累计运行时长 累计运行公里数相关的属性集合
+                Map<Long, List<IotModelTemplateAttrsDO>> multiAccumulatedAttrPair = new HashMap<>();
+                if (CollUtil.isNotEmpty(multiAccumulatedAttrs)) {
+                    multiAccumulatedAttrs.forEach(attr -> {
+                        if (multiAccumulatedAttrPair.containsKey(attr.getDeviceCategoryId())) {
+                            List<IotModelTemplateAttrsDO> tempAttrs = multiAccumulatedAttrPair.get(attr.getDeviceCategoryId());
+                            tempAttrs.add(attr);
+                            multiAccumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
+                        } else {
+                            List<IotModelTemplateAttrsDO> tempAttrs = new ArrayList<>();
+                            tempAttrs.add(attr);
+                            multiAccumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
+                        }
+                        multipleAttrNames.add(attr.getName());
+                    });
+                }
+                if (CollUtil.isNotEmpty(multiAccumulatedAttrPair)) {
+                    multiAccumulatedAttrPair.forEach((k,v) -> {
                         // k设备分类id   v设备分类包含的模板中 多个累计运行时长 累计运行公里数 相关的属性集合
                         deviceCategoryPair.forEach((ik, iv) -> {
                             // ik设备id   iv设备分类id
                             if (iv.equals(k)) {
                                 // key设备id  value设备分类包含的模板中 多个累计运行时长 累计运行公里数 相关的属性集合
-                                deviceAttrsPair.put(ik, v);
+                                deviceMultiAttrsPair.put(ik, v);
                                 multipleAttrDeviceIds.add(ik);
                             }
                         });
@@ -737,6 +774,22 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                 }
                 // 根据设备id集合查询正常的 累计时长 累计公里数
                 deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(new ArrayList<>(deviceIds), new ArrayList<>(deviceCategoryIds), deviceCategoryPair);
+                // 没有产生运行记录的单累计属性 返回前端 0 deviceAttrsPair单属性属性集合
+                Map<Long, IotDeviceRunLogRespVO> finalDeviceRunLogMap = deviceRunLogMap;
+                if (CollUtil.isNotEmpty(deviceAttrsPair)) {
+                    deviceAttrsPair.forEach((deviceId, attrs) -> {
+                        if (!finalDeviceRunLogMap.containsKey(deviceId)) {
+                            // 当前设备没有产生运行记录数据
+                            attrs.forEach(attr -> {
+                                IotDeviceRunLogRespVO runLog = new IotDeviceRunLogRespVO();
+                                runLog.setTotalRunTime(BigDecimal.ZERO);
+                                runLog.setTotalMileage(BigDecimal.ZERO);
+                                runLog.setPointName(attr.getName());
+                                finalDeviceRunLogMap.put(deviceId, runLog);
+                            });
+                        }
+                    });
+                }
 
                 // 根据设备id 运行记录模板属性名称 查询对应的 累计运行时长 累计运行公里数
                 if (CollUtil.isNotEmpty(multipleAttrDeviceIds) && CollUtil.isNotEmpty(multipleAttrNames)) {
@@ -769,7 +822,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                         });
                     }
                     // todo 如果还没有记录运行记录数据 也要显示出来
-                    deviceAttrsPair.forEach((deviceId, templateAttrs) -> {
+                    deviceMultiAttrsPair.forEach((deviceId, templateAttrs) -> {
                         // 循环每个设备对应的多累计属性集合 找到没有生成运行记录的属性 使用空对象补全
                         List<String> loggedAttrNames;
                         if (loggedAttrNamePair.containsKey(deviceId)) {
@@ -797,47 +850,45 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                                 loggedRunLogs.add(tempRunLog);
                             }
                         });
+                        deviceRunLogPair.put(deviceId, loggedRunLogs);
                     });
 
                 }
-            }
-
-            // 查询 bomNodeIds 集合中每个bom节点的所有上级节点
-            Map<Long, String> bomFullPaths = iotDeviceBomService.buildBomFullPaths(bomNodeIds);
-            Map<Long, IotDeviceRunLogRespVO> finalDeviceRunLogMap = deviceRunLogMap;
-            devices.forEach(device -> {
-                String uniqueKey = StrUtil.join("-", device.getId(), device.getBomNodeId());
-                if (bomMaterialsPair.containsKey(uniqueKey)) {
-                    device.setDeviceBomMaterials(bomMaterialsPair.get(uniqueKey));
-                }
-                // 保养项全路径名
-                if (bomFullPaths.containsKey(Long.valueOf(device.getBomNodeId()))) {
-                    if (StrUtil.isNotBlank(bomFullPaths.get(Long.valueOf(device.getBomNodeId())))) {
-                        device.setName(bomFullPaths.get(Long.valueOf(device.getBomNodeId())));
+                // 查询 bomNodeIds 集合中每个bom节点的所有上级节点
+                Map<Long, String> bomFullPaths = iotDeviceBomService.buildBomFullPaths(bomNodeIds);
+                devices.forEach(device -> {
+                    String uniqueKey = StrUtil.join("-", device.getId(), device.getBomNodeId());
+                    if (bomMaterialsPair.containsKey(uniqueKey)) {
+                        device.setDeviceBomMaterials(bomMaterialsPair.get(uniqueKey));
                     }
-                }
-                if (deviceRunLogPair.containsKey(device.getId())) {
-                    // 区分开 时间 里程 的累计属性列表 便于前端选择
-                    List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
-                    List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(device.getId());
-                    timeRunLogs.forEach(log -> {
-                        log.setType(1);
-                        IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
-                        BeanUtils.copyProperties(log, tempRunLog);
-                        tempRunLog.setType(2);
-                        mileageRunLogs.add(tempRunLog);
-                    });
-                    device.setTimeAccumulatedAttrs(timeRunLogs);
-                    device.setMileageAccumulatedAttrs(mileageRunLogs);
-                }
-                // 这里只赋值正常的 累计时长 累计公里数 多个累计属性的需要在保养配置中选择
-                if (CollUtil.isNotEmpty(finalDeviceRunLogMap) && finalDeviceRunLogMap.containsKey(device.getId())) {
-                    IotDeviceRunLogRespVO tempRunLog = finalDeviceRunLogMap.get(device.getId());
-                    device.setTotalRunTime(tempRunLog.getTotalRunTime());
-                    device.setTotalMileage(tempRunLog.getTotalMileage());
-                }
-            });
-
+                    // 保养项全路径名
+                    if (bomFullPaths.containsKey(Long.valueOf(device.getBomNodeId()))) {
+                        if (StrUtil.isNotBlank(bomFullPaths.get(Long.valueOf(device.getBomNodeId())))) {
+                            device.setName(bomFullPaths.get(Long.valueOf(device.getBomNodeId())));
+                        }
+                    }
+                    if (deviceRunLogPair.containsKey(device.getId())) {
+                        // 区分开 时间 里程 的累计属性列表 便于前端选择
+                        List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
+                        List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(device.getId());
+                        timeRunLogs.forEach(log -> {
+                            log.setType(1);
+                            IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
+                            BeanUtils.copyProperties(log, tempRunLog);
+                            tempRunLog.setType(2);
+                            mileageRunLogs.add(tempRunLog);
+                        });
+                        device.setTimeAccumulatedAttrs(timeRunLogs);
+                        device.setMileageAccumulatedAttrs(mileageRunLogs);
+                    }
+                    // 这里只赋值正常的 累计时长 累计公里数 多个累计属性的需要在保养配置中选择
+                    if (CollUtil.isNotEmpty(finalDeviceRunLogMap) && finalDeviceRunLogMap.containsKey(device.getId())) {
+                        IotDeviceRunLogRespVO tempRunLog = finalDeviceRunLogMap.get(device.getId());
+                        device.setTotalRunTime(tempRunLog.getTotalRunTime());
+                        device.setTotalMileage(tempRunLog.getTotalMileage());
+                    }
+                });
+            }
         }
         return devices;
     }

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

@@ -382,6 +382,21 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             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 (!dept.getName().contains("项目部") && !dept.getName().contains("瑞恒兴域")
+                            && !dept.getName().contains("基地") && !dept.getName().contains("服务部")) {
+                        filteredDepts.put(deptId, dept);
+                    }
+                });
+            }
+
             // 比如有20个队伍 某个时间区间D内 必须有20*D份日报 时间区间最好是1天
             // 查询出指定时间区间内 已经填写的日报数量
             List<IotRhDailyReportDO> dailyReports = iotRhDailyReportMapper.dailyReports(reqVO);
@@ -396,7 +411,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             // 计算天数:日期差 + 1(包含首尾两天)
             long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
             // 计算指定时间区间内所有日报数量总数
-            long totalRequiredReports = (long) deptIds.size() * days;
+            long totalRequiredReports = (long) filteredDepts.size() * days;
             // 获取【实际已报的日报数量】
             long totalReportedReports = CollUtil.isNotEmpty(dailyReports) ? dailyReports.size() : 0l;
             // 计算指定时间区间内未填报的日报数量
@@ -530,6 +545,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     IotRhDailyReportStatisticsVO dailyReportVO = new IotRhDailyReportStatisticsVO();
                     dailyReportVO.setReportDate(reportDate);
                     dailyReportVO.setDeptNames(deptList.stream().collect(Collectors.joining(",")));
+                    dailyReportVO.setCount(deptList.size());
                     results.add(dailyReportVO);
                 });
                 // 使用Comparator进行排序