Przeglądaj źródła

pms 瑞恒 设备利用率 按照队伍维度查询 折线图

zhangcl 1 tydzień temu
rodzic
commit
de35548df3

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

@@ -2792,6 +2792,19 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key日期yyyy-MM-dd   value对应日报部门的总产能
         // key日期yyyy-MM-dd   value对应日报部门的总产能
         Map<String, BigDecimal> dateCapacityPair = new HashMap<>();
         Map<String, BigDecimal> dateCapacityPair = new HashMap<>();
 
 
+        // 筛选瑞恒 主设备 rq_iot_rh_main_device_category
+        Set<Long> mainDeviceCategoryIds = new HashSet<>();
+        List<DictDataDO> constructionStatusDictData = dictDataService.getDictDataListByDictType("rq_iot_rh_main_device_category");
+        if (CollUtil.isNotEmpty(constructionStatusDictData)) {
+            constructionStatusDictData.forEach(data -> {
+                String value = data.getValue();
+                if (NumberUtil.isNumber(value)) {
+                    Long longValue = Long.valueOf(value);
+                    mainDeviceCategoryIds.add(longValue);
+                }
+            });
+        }
+
         // 以 队伍 为维度统计数据
         // 以 队伍 为维度统计数据
         // 找到所有项目部与队伍的对应关系
         // 找到所有项目部与队伍的对应关系
         // 查询指定根部门下的所有子部门
         // 查询指定根部门下的所有子部门
@@ -2801,11 +2814,32 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         reqVO.setDeptIds(allRhChildDeptIds);
         reqVO.setDeptIds(allRhChildDeptIds);
         List<DeptDO> depts = deptService.getDeptList(reqVO);
         List<DeptDO> depts = deptService.getDeptList(reqVO);
 
 
+        // 包含瑞恒主设备的 部门id 集合
+        Set<Long> haveDeviceDeptIds = new HashSet<>();
+        IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
+        deviceReqVO.setDeptIds(new ArrayList<>(allRhChildDeptIds));
+        List<IotDeviceDO> devices = iotDeviceMapper.selectListAlone(deviceReqVO);
+        if (CollUtil.isNotEmpty(devices)) {
+            // 筛选出包含设备的队伍部门集合
+            devices.forEach(device -> {
+                // 20260605 筛选包含主设备的队伍
+                if (mainDeviceCategoryIds.contains(device.getAssetClass())) {
+                    haveDeviceDeptIds.add(device.getDeptId());
+                }
+            });
+        }
+
         // 构建项目部映射和父子部门关系
         // 构建项目部映射和父子部门关系
+        // 当前已经选择的部门下 包含瑞恒主设备的 队伍id 集合
+        Set<Long> currentDeviceDeptIds = new HashSet<>();
         depts.forEach(dept -> {
         depts.forEach(dept -> {
             if ("3".equals(dept.getType())) {
             if ("3".equals(dept.getType())) {
                 projectDeptIds.add(dept.getId());
                 projectDeptIds.add(dept.getId());
                 teamDeptPair.put(dept.getId(), dept);
                 teamDeptPair.put(dept.getId(), dept);
+                // 筛选出当前选择的组织部门下包含瑞恒主设备的 队伍id 列表
+                if (haveDeviceDeptIds.contains(dept.getId())) {
+                    currentDeviceDeptIds.add(dept.getId());
+                }
             }
             }
             teamProjectIdPair.put(dept.getId(), dept.getParentId());
             teamProjectIdPair.put(dept.getId(), dept.getParentId());
         });
         });
@@ -2814,9 +2848,13 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key队伍id   value队伍下相关设备产能
         // key队伍id   value队伍下相关设备产能
         Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
         Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
 
 
+        // key日期yyyy-MM-dd   value指定日期内包含主设备队伍id集合
+        Map<String, Set<Long>> dateUtilizationDeptPair = new HashMap<>();
+
         // 累计计算各项指标
         // 累计计算各项指标
         if (CollUtil.isNotEmpty(dailyReports)) {
         if (CollUtil.isNotEmpty(dailyReports)) {
             dailyReports.forEach(report -> {
             dailyReports.forEach(report -> {
+                Long currentDeptId = report.getDeptId();
                 // 按照日期维度统计各 工作量数据 累计用电量 累计油耗 累计注气量 累计注水量
                 // 按照日期维度统计各 工作量数据 累计用电量 累计油耗 累计注气量 累计注水量
                 LocalDateTime reportLocalDate = report.getCreateTime();
                 LocalDateTime reportLocalDate = report.getCreateTime();
                 // 将日期格式转换成 字符串
                 // 将日期格式转换成 字符串
@@ -2830,10 +2868,24 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 // 累计油耗
                 // 累计油耗
                 dateFuelConsumptionPair.merge(reportDateStr, report.getDailyOilUsage(), BigDecimal::add);
                 dateFuelConsumptionPair.merge(reportDateStr, report.getDailyOilUsage(), BigDecimal::add);
                 // 累计产能
                 // 累计产能
-                if (teamCapacityPair.containsKey(report.getDeptId())) {
-                    BigDecimal tempCapacity = teamCapacityPair.get(report.getDeptId());
+                if (teamCapacityPair.containsKey(currentDeptId)) {
+                    BigDecimal tempCapacity = teamCapacityPair.get(currentDeptId);
                     dateCapacityPair.merge(reportDateStr, tempCapacity, BigDecimal::add);
                     dateCapacityPair.merge(reportDateStr, tempCapacity, BigDecimal::add);
                 }
                 }
+                // 统计各日期的设备利用率 注气量 或 注水量 >0 的日报数量
+                BigDecimal dailyGasInjection = report.getDailyGasInjection();
+                BigDecimal dailyWaterInjection = report.getDailyWaterInjection();
+                if (haveDeviceDeptIds.contains(currentDeptId) && (dailyGasInjection.compareTo(BigDecimal.ZERO)>0 || dailyWaterInjection.compareTo(BigDecimal.ZERO)>0)) {
+                    if (dateUtilizationDeptPair.containsKey(reportDateStr)) {
+                        Set<Long> tempDeptIds = dateUtilizationDeptPair.get(reportDateStr);
+                        tempDeptIds.add(currentDeptId);
+                        dateUtilizationDeptPair.put(reportDateStr, tempDeptIds);
+                    } else {
+                        Set<Long> tempDeptIds = new HashSet<>();
+                        tempDeptIds.add(currentDeptId);
+                        dateUtilizationDeptPair.put(reportDateStr, tempDeptIds);
+                    }
+                }
             });
             });
             // 根据 累计注气量 累计产能 计算指定队伍下的平均产能
             // 根据 累计注气量 累计产能 计算指定队伍下的平均产能
             if (CollUtil.isNotEmpty(dateGasInjectionPair) && CollUtil.isNotEmpty(dateCapacityPair)) {
             if (CollUtil.isNotEmpty(dateGasInjectionPair) && CollUtil.isNotEmpty(dateCapacityPair)) {
@@ -2872,6 +2924,19 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 statistics.setCumulativePowerConsumption(datePowerConsumptionPair.get(date));
                 statistics.setCumulativePowerConsumption(datePowerConsumptionPair.get(date));
                 statistics.setCumulativeFuelConsumption(dateFuelConsumptionPair.get(date));
                 statistics.setCumulativeFuelConsumption(dateFuelConsumptionPair.get(date));
                 statistics.setTransitTime(dateTransitTimePair.get(date));
                 statistics.setTransitTime(dateTransitTimePair.get(date));
+                // 设置每个日期的设备利用率
+                if (dateUtilizationDeptPair.containsKey(date)) {
+                    Set<Long> dateDeptIds = dateUtilizationDeptPair.get(date);
+                    Integer dateDeptIdCount = dateDeptIds.size();
+                    Integer mainDeviceIdCount = currentDeviceDeptIds.size();
+                    BigDecimal rate = BigDecimal.ZERO;
+                    if (mainDeviceIdCount > 0) {
+                        BigDecimal total = new BigDecimal(mainDeviceIdCount);
+                        BigDecimal current = new BigDecimal(dateDeptIdCount);
+                        rate = current.divide(total, 4, RoundingMode.HALF_UP);
+                    }
+                    statistics.setUtilizationRate(rate);
+                }
                 result.add(statistics);
                 result.add(statistics);
             });
             });
         }
         }