ソースを参照

pms 瑞恒 设备利用率 折线图

zhangcl 1 週間 前
コミット
adb044e9c8

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrhdailyreport/vo/IotRhDailyReportPolylineVO.java

@@ -60,4 +60,7 @@ public class IotRhDailyReportPolylineVO {
     @ExcelProperty("运行时效")
     private BigDecimal transitTime = BigDecimal.ZERO;
 
+    @Schema(description = "设备利用率")
+    private BigDecimal utilizationRate;
+
 }

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

@@ -1972,6 +1972,19 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key日期yyyy-MM-dd   value对应日报部门的总产能
         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);
+                }
+            });
+        }
+
         // 以项目部为维度统计数据
         // 找到所有项目部与队伍的对应关系
         // 查询指定根部门下的所有子部门
@@ -1980,6 +1993,23 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         reqVO.setDeptIds(allRhChildDeptIds);
         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 -> {
             if ("2".equals(dept.getType())) {
@@ -1987,15 +2017,23 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 projectDeptPair.put(dept.getId(), dept);
             }
             teamProjectIdPair.put(dept.getId(), dept.getParentId());
+            // 筛选出当前选择的组织部门下包含瑞恒主设备的 队伍id 列表
+            if ("3".equals(dept.getType()) && haveDeviceDeptIds.contains(dept.getId())) {
+                currentDeviceDeptIds.add(dept.getId());
+            }
         });
 
         // 查询指定部门下相关设备的产能
         // key队伍id   value队伍下相关设备产能
         Map<Long, BigDecimal> teamCapacityPair = queryCapacities(new ArrayList<>(allRhChildDeptIds));
 
+        // key日期yyyy-MM-dd   value累计注气量
+        Map<String, Set<Long>> dateUtilizationDeptPair = new HashMap<>();
+
         // 累计计算各项指标
         if (CollUtil.isNotEmpty(dailyReports)) {
             dailyReports.forEach(report -> {
+                Long deptId = report.getDeptId();
                 // 按照日期维度统计各 工作量数据 累计用电量 累计油耗 累计注气量 累计注水量
                 LocalDateTime reportLocalDate = report.getCreateTime();
                 // 将日期格式转换成 字符串
@@ -2009,10 +2047,25 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 // 累计油耗
                 dateFuelConsumptionPair.merge(reportDateStr, report.getDailyOilUsage(), BigDecimal::add);
                 // 累计产能
-                if (teamCapacityPair.containsKey(report.getDeptId())) {
-                    BigDecimal tempCapacity = teamCapacityPair.get(report.getDeptId());
+                if (teamCapacityPair.containsKey(deptId)) {
+                    BigDecimal tempCapacity = teamCapacityPair.get(deptId);
                     dateCapacityPair.merge(reportDateStr, tempCapacity, BigDecimal::add);
                 }
+                // 统计各日期的设备利用率 注气量 或 注水量 >0 的日报数量
+                BigDecimal dailyGasInjection = report.getDailyGasInjection();
+                BigDecimal dailyWaterInjection = report.getDailyWaterInjection();
+                if (haveDeviceDeptIds.contains(deptId) && (dailyGasInjection.compareTo(BigDecimal.ZERO)>0 || dailyWaterInjection.compareTo(BigDecimal.ZERO)>0)) {
+                    if (dateUtilizationDeptPair.containsKey(reportDateStr)) {
+                        Set<Long> tempDeptIds = dateUtilizationDeptPair.get(reportDateStr);
+                        tempDeptIds.add(deptId);
+                        dateUtilizationDeptPair.put(reportDateStr, tempDeptIds);
+                    } else {
+                        Set<Long> tempDeptIds = new HashSet<>();
+                        tempDeptIds.add(deptId);
+                        dateUtilizationDeptPair.put(reportDateStr, tempDeptIds);
+                    }
+                }
+
             });
             // 根据 累计注气量 累计产能 计算指定日期范围的平均产能
             if (CollUtil.isNotEmpty(dateGasInjectionPair) && CollUtil.isNotEmpty(dateCapacityPair)) {
@@ -2054,6 +2107,19 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                 statistics.setCumulativePowerConsumption(datePowerConsumptionPair.get(date));
                 statistics.setCumulativeFuelConsumption(dateFuelConsumptionPair.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);
             });
         }