Kaynağa Gözat

Merge remote-tracking branch 'origin/master'

Zimo 1 hafta önce
ebeveyn
işleme
ea7d9a0ed4

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

@@ -94,4 +94,7 @@ public class IotRdDailyReportPolylineVO {
     @ExcelProperty("压裂井数")
     private Integer ylWellCount;
 
+    @Schema(description = "设备利用率")
+    private BigDecimal utilizationRate;
+
 }

+ 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;
+
 }

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -717,6 +717,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
             // 查询 瑞都下的所有 部门
             if (deptId == 163l || deptId == 388l) {
                 Set<Long> tempChildDeptIds = deptService.getChildDeptIdListFromCache(deptId);
+                tempChildDeptIds.add(deptId);
                 childDeptIds.addAll(tempChildDeptIds);
             }
             if (childDeptIds.contains(randomDeptId)) {

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotprojectinfo/IotProjectInfoServiceImpl.java

@@ -275,6 +275,8 @@ public class IotProjectInfoServiceImpl implements IotProjectInfoService {
             ryChildDeptIds.add(158l);
             Set<Long> rdChildDeptIds = deptService.getChildDeptIdListFromCache(163l);
             rdChildDeptIds.add(163l);
+            Set<Long> fiveChildDeptIds = deptService.getChildDeptIdListFromCache(388l);
+            fiveChildDeptIds.add(388l);
             if (rhChildDeptIds.contains(deptId)) {
                 // 当前登录所属公司为 瑞恒
                 allChildDeptIds.add(157l);
@@ -287,6 +289,10 @@ public class IotProjectInfoServiceImpl implements IotProjectInfoService {
                 // 当前登录所属公司为 瑞都
                 allChildDeptIds.add(163l);
             }
+            if (fiveChildDeptIds.contains(deptId)) {
+                // 当前登录所属公司为 5#公司
+                allChildDeptIds.add(388l);
+            }
         });
 
         return allChildDeptIds;

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotprojecttask/IotProjectTaskServiceImpl.java

@@ -297,6 +297,9 @@ public class IotProjectTaskServiceImpl implements IotProjectTaskService {
                 dataPermissionTaskIds.add(task.getId());
             });
         }
+        if (CollUtil.isEmpty(dataPermissionTaskIds)) {
+            return new PageResult<>(new ArrayList<>(), 0l);
+        }
         Set<Long> departmentIds = new HashSet<>();
 
         // 客户名称模板搜索

+ 48 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrddailyreport/IotRdDailyReportServiceImpl.java

@@ -2357,6 +2357,8 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
         Map<String, BigDecimal> dateMixSandPair = new HashMap<>();
         // key日期yyyy-MM-dd  value 累计 油耗
         Map<String, BigDecimal> dateFuelsPair = new HashMap<>();
+        // key日期yyyy-MM-dd  value 累计的压裂连油主设备id列表
+        Map<String, List<Long>> dateDeviceIdsPair = new HashMap<>();
 
         // 以项目部为维度统计数据
         // 找到所有项目部与队伍的对应关系
@@ -2375,6 +2377,20 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
             teamProjectIdPair.put(dept.getId(), dept.getParentId());
         });
 
+        Set<Long> mainDeviceIds = new HashSet<>();
+        // 瑞都 压裂 连油 主设备
+        IotDeviceAssociatePageReqVO deviceAssocReqVO = new IotDeviceAssociatePageReqVO();
+        deviceAssocReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        deviceAssocReqVO.setDeptIds(allRhChildDeptIds);
+        PageResult<IotDeviceAssociateDO> pageResult = iotDeviceAssociateMapper.selectPage(deviceAssocReqVO);
+        if (ObjUtil.isNotEmpty(pageResult)) {
+            List<IotDeviceAssociateDO> deviceAssociates = pageResult.getList();
+            // 查询出选择部门内 瑞都压裂 连油主设备
+            deviceAssociates.forEach(assoc -> {
+                mainDeviceIds.add(assoc.getDeviceId());
+            });
+        }
+
         // 累计计算各项指标
         if (CollUtil.isNotEmpty(dailyReports)) {
             dailyReports.forEach(report -> {
@@ -2393,6 +2409,24 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
                     dateFuelsPair.put(reportDateStr, dailyFuel);
                 }
 
+                // 计算查询时间区间内每天的设备利用率 组装每天内所有队伍使用到的 压裂 连油 主设备列表
+                Set<Long> currentReportDeviceIds = report.getDeviceIds();
+                if (CollUtil.isNotEmpty(currentReportDeviceIds)) {
+                    // 1. 求交集:实际使用的A B类设备
+                    Set<Long> utilizedDeviceIds = currentReportDeviceIds.stream()
+                            .filter(mainDeviceIds::contains)
+                            .collect(Collectors.toSet());
+                    if (dateDeviceIdsPair.containsKey(reportDateStr)) {
+                        List<Long> tempDeviceIds = dateDeviceIdsPair.get(reportDateStr);
+                        tempDeviceIds.addAll(new ArrayList<>(utilizedDeviceIds));
+                        dateDeviceIdsPair.put(reportDateStr, tempDeviceIds);
+                    } else {
+                        List<Long> tempDeviceIds = new ArrayList<>();
+                        tempDeviceIds.addAll(new ArrayList<>(utilizedDeviceIds));
+                        dateDeviceIdsPair.put(reportDateStr, tempDeviceIds);
+                    }
+                }
+
                 // 设置每个任务的工作量数据  单位相同的工作量值作合并处理
                 List<IotTaskAttrModelProperty> taskAttrs = report.getExtProperty();
                 // 暂存不同单位的工作量属性值
@@ -2550,6 +2584,20 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
                 statistics.setCumulativeMixSand(dateMixSandPair.get(date));
                 statistics.setCumulativePumpTrips(datePumpTripsPair.get(date));
                 statistics.setTaici(taici);
+                // 计算查询周期内每天的设备利用率
+                if (dateDeviceIdsPair.containsKey(date)) {
+                    List<Long> dateDeviceIds = dateDeviceIdsPair.get(date);
+                    Integer dateDeviceIdCount = dateDeviceIds.size();
+                    Integer mainDeviceIdCount = mainDeviceIds.size();
+                    BigDecimal rate = BigDecimal.ZERO;
+                    if (mainDeviceIdCount > 0) {
+                        BigDecimal total = new BigDecimal(mainDeviceIdCount);
+                        BigDecimal current = new BigDecimal(dateDeviceIdCount);
+                        rate = current.divide(total, 4, RoundingMode.HALF_UP);
+                    }
+                    statistics.setUtilizationRate(rate);
+                }
+
                 result.add(statistics);
             });
         }

+ 135 - 4
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);
             });
         }
@@ -2726,6 +2792,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);
+                }
+            });
+        }
+
         // 以 队伍 为维度统计数据
         // 找到所有项目部与队伍的对应关系
         // 查询指定根部门下的所有子部门
@@ -2735,11 +2814,32 @@ 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 ("3".equals(dept.getType())) {
                 projectDeptIds.add(dept.getId());
                 teamDeptPair.put(dept.getId(), dept);
+                // 筛选出当前选择的组织部门下包含瑞恒主设备的 队伍id 列表
+                if (haveDeviceDeptIds.contains(dept.getId())) {
+                    currentDeviceDeptIds.add(dept.getId());
+                }
             }
             teamProjectIdPair.put(dept.getId(), dept.getParentId());
         });
@@ -2748,9 +2848,13 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // key队伍id   value队伍下相关设备产能
         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)) {
             dailyReports.forEach(report -> {
+                Long currentDeptId = report.getDeptId();
                 // 按照日期维度统计各 工作量数据 累计用电量 累计油耗 累计注气量 累计注水量
                 LocalDateTime reportLocalDate = report.getCreateTime();
                 // 将日期格式转换成 字符串
@@ -2764,10 +2868,24 @@ 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(currentDeptId)) {
+                    BigDecimal tempCapacity = teamCapacityPair.get(currentDeptId);
                     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)) {
@@ -2806,6 +2924,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);
             });
         }