Ver código fonte

pms 瑞都 日报 工作量汇总 折线图

zhangcl 4 dias atrás
pai
commit
1bea418234

+ 2 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrddailyreport/IotRdDailyReportController.java

@@ -2077,7 +2077,7 @@ public class IotRdDailyReportController {
     @GetMapping("/polylineStatistics")
     @Operation(summary = "瑞都日报 统计")
     @PreAuthorize("@ss.hasPermission('pms:iot-rd-daily-report:query')")
-    public CommonResult<List<IotRdDailyReportStatisticsRespVO>> polylineStatistics(@Valid IotRdDailyReportPageReqVO pageReqVO) {
+    public CommonResult<List<IotRdDailyReportPolylineVO>> polylineStatistics(@Valid IotRdDailyReportPageReqVO pageReqVO) {
         // 根据查询参数筛选出 符合条件 的记录id 再传入 分页查询
         Set<Long> projectIds = new HashSet<>();
         Set<Long> taskIds = new HashSet<>();
@@ -2103,7 +2103,7 @@ public class IotRdDailyReportController {
                 pageReqVO.setTaskIds(taskIds);
             }
         }
-        List<IotRdDailyReportStatisticsRespVO> result = iotRdDailyReportService.statistics(pageReqVO);
+        List<IotRdDailyReportPolylineVO> result = iotRdDailyReportService.polylineStatistics(pageReqVO);
         return success(result);
     }
 

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

@@ -52,4 +52,39 @@ public class IotRdDailyReportPolylineVO {
     @ExcelProperty("发生工作量所在月份")
     private String workloadMonth;
 
+    @Schema(description = "日报日期 yyyy-MM-dd", example = "1")
+    @ExcelProperty("日报日期 yyyy-MM-dd")
+    private String reportDate;
+
+    // 汇总统计 工作量
+    @Schema(description = "桥塞(个数)")
+    @ExcelProperty("桥塞(个数)")
+    private BigDecimal cumulativeBridgePlug;
+    @Schema(description = "趟数")
+    @ExcelProperty("趟数")
+    private BigDecimal cumulativeRunCount;
+    @Schema(description = "井数")
+    @ExcelProperty("井数")
+    private BigDecimal cumulativeWorkingWell;
+    @Schema(description = "小时H")
+    @ExcelProperty("小时H")
+    private BigDecimal cumulativeHourCount;
+    @Schema(description = "水方量(方)")
+    @ExcelProperty("水方量(方)")
+    private BigDecimal cumulativeWaterVolume;
+    @Schema(description = "段数  累计施工-层")
+    @ExcelProperty("段数  累计施工-层")
+    private BigDecimal cumulativeWorkingLayers;
+    @Schema(description = "台次 当日仪表/混砂")
+    @ExcelProperty("台次 当日仪表/混砂")
+    private BigDecimal cumulativeMixSand;
+    @Schema(description = "台次 当日泵车台次")
+    @ExcelProperty("台次 当日泵车台次")
+    private BigDecimal cumulativePumpTrips;
+    @Schema(description = "累计 台次")
+    @ExcelProperty("累计 台次")
+    private BigDecimal taici;
+    @Schema(description = "油耗L")
+    @ExcelProperty("油耗L")
+    private BigDecimal cumulativeFuels;
 }

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

@@ -1,6 +1,8 @@
 package cn.iocoder.yudao.module.pms.service.iotrddailyreport;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -1545,26 +1547,268 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
     @Override
     public List<IotRdDailyReportPolylineVO> polylineStatistics(IotRdDailyReportPageReqVO pageReqVO) {
         List<IotRdDailyReportPolylineVO> result = new ArrayList<>();
-        // 默认查询当年工作量
+        // 查询折线趋势图必须 传递时间参数
         if (ObjUtil.isEmpty(pageReqVO.getCreateTime())) {
             throw exception(IOT_DAILY_REPORT_TIME_NOT_EXISTS);
         }
+        Set<Long> ids = new HashSet<>();
+        if (Objects.nonNull(pageReqVO.getDeptId())) {
+            ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
+            // 找到所有子部门对象集合
+            ids.add(pageReqVO.getDeptId());
+            pageReqVO.setDeptIds(ids);
+        }
+        // 检查contractName不为空但projectIds为空的情况
+        if (StrUtil.isNotBlank(pageReqVO.getContractName()) && (CollUtil.isEmpty(pageReqVO.getProjectIds()))) {
+            return new ArrayList<>();
+        }
+        // 检查taskName不为空但taskIds为空的情况
+        if (StrUtil.isNotBlank(pageReqVO.getTaskName()) && (CollUtil.isEmpty(pageReqVO.getTaskIds()))) {
+            return new ArrayList<>();
+        }
         // 筛选审核通过的数据
-        pageReqVO.setAuditStatus(20);
+        // pageReqVO.setAuditStatus(20);
         List<IotRdDailyReportDO> dailyReports = iotRdDailyReportMapper.dailyReports(pageReqVO);
         if (CollUtil.isNotEmpty(dailyReports)) {
-            // 设置 小队 任务已经完成的工作量集合 (按照不同的单位统计任务的不同工作量)
-            // key任务井id      value队伍工作量数据
-            Map<Long, BigDecimal> bridgePlugPair = new HashMap<>();
-            Map<Long, BigDecimal> runCountPair = new HashMap<>();
-            Map<Long, BigDecimal> cumulativeWorkingWellPair = new HashMap<>();
-            Map<Long, BigDecimal> hourCountPair = new HashMap<>();
-            Map<Long, BigDecimal> waterVolumePair = new HashMap<>();
-            Map<Long, BigDecimal> pumpTripsPair = new HashMap<>();
-            Map<Long, BigDecimal> cumulativeWorkingLayersPair = new HashMap<>();
-            Map<Long, BigDecimal> mixSandPair = new HashMap<>();
+            Long rootDeptId = 163l;
+            if (ObjUtil.isEmpty(pageReqVO.getDeptId())) {
+                pageReqVO.setDeptId(rootDeptId);
+            }
+            result = polylineStatisticsByProjectDept(dailyReports, pageReqVO.getDeptId(), pageReqVO.getCreateTime());
+        }
+        return result;
+    }
+
+    /**
+     * 按项 日期 维度统计 折线 工作量 数据
+     * @param dailyReports 日报数据列表
+     * @param rootDeptId 部门ID(如163L为瑞恒根部门,或其他项目部 ID)
+     * @return
+     */
+    private List<IotRdDailyReportPolylineVO> polylineStatisticsByProjectDept(List<IotRdDailyReportDO> dailyReports,
+                                                                             Long rootDeptId, LocalDateTime[] createTimes) {
+        List<IotRdDailyReportPolylineVO> result = new ArrayList<>();
+        // 按照日期维度统计数据
+        Set<Long> projectDeptIds = new HashSet<>();
+        // key项目部id    value项目部名称
+        Map<Long, DeptDO> projectDeptPair = new HashMap<>();
+        // key部门id   value部门parentId
+        Map<Long, Long> teamProjectIdPair = new HashMap<>();
 
-            dailyReports.forEach(report -> {});
+        // 按照日期维度统计各工作量数据
+        // key日期yyyy-MM-dd   value 累计 桥塞(个数)
+        Map<String, BigDecimal> dateBridgePlugPair = new HashMap<>();
+        // key日期yyyy-MM-dd   value 累计 趟数
+        Map<String, BigDecimal> dateRunCountPair = new HashMap<>();
+        // key日期yyyy-MM-dd   value 累计 井数
+        Map<String, BigDecimal> dateWorkingWellPair = new HashMap<>();
+        // key日期yyyy-MM-dd   value 累计 小时H
+        Map<String, BigDecimal> dateHourCountPair = new HashMap<>();
+        // key日期yyyy-MM-dd   value 累计 水方量(方)
+        Map<String, BigDecimal> dateWaterVolumePair = new HashMap<>();
+        // key日期yyyy-MM-dd   value 累计 台次 泵车
+        Map<String, BigDecimal> datePumpTripsPair = new HashMap<>();
+        // key日期yyyy-MM-dd  value 累计 段数 累计施工-层
+        Map<String, BigDecimal> dateWorkingLayersPair = new HashMap<>();
+        // key日期yyyy-MM-dd  value 累计 台次 当日仪表/混砂
+        Map<String, BigDecimal> dateMixSandPair = new HashMap<>();
+        // key日期yyyy-MM-dd  value 累计 油耗
+        Map<String, BigDecimal> dateFuelsPair = new HashMap<>();
+
+        // 以项目部为维度统计数据
+        // 找到所有项目部与队伍的对应关系
+        // 查询指定根部门下的所有子部门
+        Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(rootDeptId);
+        DeptListReqVO reqVO = new DeptListReqVO();
+        reqVO.setDeptIds(allRhChildDeptIds);
+        List<DeptDO> depts = deptService.getDeptList(reqVO);
+
+        // 构建项目部映射和父子部门关系
+        depts.forEach(dept -> {
+            if ("2".equals(dept.getType())) {
+                projectDeptIds.add(dept.getId());
+                projectDeptPair.put(dept.getId(), dept);
+            }
+            teamProjectIdPair.put(dept.getId(), dept.getParentId());
+        });
+
+        // 累计计算各项指标
+        if (CollUtil.isNotEmpty(dailyReports)) {
+            dailyReports.forEach(report -> {
+                BigDecimal dailyFuel = report.getDailyFuel();
+                dailyFuel = ObjUtil.isEmpty(dailyFuel) ? BigDecimal.ZERO : dailyFuel;
+
+                // 按照日期维度统计各 工作量数据 累计用电量 累计油耗 累计注气量 累计注水量
+                LocalDateTime reportLocalDate = report.getCreateTime();
+                // 将日期格式转换成 字符串
+                String reportDateStr = LocalDateTimeUtil.format(reportLocalDate, DatePattern.NORM_DATE_PATTERN);
+                if (dateFuelsPair.containsKey(reportDateStr)) {
+                    BigDecimal existTotalFuel = dateFuelsPair.get(reportDateStr);
+                    BigDecimal tempTotalFuel = existTotalFuel.add(dailyFuel);
+                    dateFuelsPair.put(reportDateStr, tempTotalFuel);
+                } else {
+                    dateFuelsPair.put(reportDateStr, dailyFuel);
+                }
+
+                // 设置每个任务的工作量数据  单位相同的工作量值作合并处理
+                List<IotTaskAttrModelProperty> taskAttrs = report.getExtProperty();
+                // 暂存不同单位的工作量属性值
+                BigDecimal tempTotalBridgePlug = BigDecimal.ZERO;               // 桥塞(个数)
+                BigDecimal tempTotalRunCount = BigDecimal.ZERO;                 // 趟数
+                BigDecimal tempTotalCumulativeWorkingWell = BigDecimal.ZERO;    // 井数
+                BigDecimal tempTotalHourCount = BigDecimal.ZERO;                // 小时H
+                BigDecimal tempTotalWaterVolume = BigDecimal.ZERO;              // 水方量(方)
+                BigDecimal tempTotalPumpTrips = BigDecimal.ZERO;                // 泵车 台次
+                BigDecimal tempTotalCumulativeWorkingLayers = BigDecimal.ZERO;  // 段数 累计施工-层
+                BigDecimal tempTotalMixSand = BigDecimal.ZERO;                  // 台次 当日仪表/混砂
+
+                if (CollUtil.isNotEmpty(taskAttrs)) {
+                    for (IotTaskAttrModelProperty attr : taskAttrs) {
+                        String unit = attr.getUnit();   // 工作量单位
+                        String actualValueStr = attr.getActualValue();  // 工作量属性的实际值
+                        // 处理实际值:避免null或非数字字符串导致的异常
+                        BigDecimal actualValue = BigDecimal.ZERO;
+                        if (StrUtil.isNotBlank(actualValueStr)) {  // 假设使用Hutool的StrUtil,或自行判断null/空
+                            try {
+                                actualValue = new BigDecimal(actualValueStr);
+                            } catch (NumberFormatException e) {
+                                // 若字符串格式错误,默认按0处理(可根据业务调整)
+                                actualValue = BigDecimal.ZERO;
+                            }
+                        }
+                        if ("个数".equals(unit)) {
+                            // 钻可溶桥塞  钻复合桥塞
+                            tempTotalBridgePlug = tempTotalBridgePlug.add(actualValue);
+                            if (dateBridgePlugPair.containsKey(reportDateStr)) {
+                                BigDecimal tempBridgePlug = dateBridgePlugPair.get(reportDateStr);
+                                dateBridgePlugPair.put(reportDateStr, tempTotalBridgePlug.add(tempBridgePlug));
+                            } else {
+                                dateBridgePlugPair.put(reportDateStr, tempTotalBridgePlug);
+                            }
+                        }
+                        if ("趟数".equals(unit)) {
+                            tempTotalRunCount = tempTotalRunCount.add(actualValue);
+                            if (dateRunCountPair.containsKey(reportDateStr)) {
+                                BigDecimal tempRunCount = dateRunCountPair.get(reportDateStr);
+                                dateRunCountPair.put(reportDateStr, tempTotalRunCount.add(tempRunCount));
+                            } else {
+                                dateRunCountPair.put(reportDateStr, tempTotalRunCount);
+                            }
+                        }
+                        if ("小时".equals(unit)) {
+                            tempTotalHourCount = tempTotalHourCount.add(actualValue);
+                            if (dateHourCountPair.containsKey(reportDateStr)) {
+                                BigDecimal tempHourCount = dateHourCountPair.get(reportDateStr);
+                                dateHourCountPair.put(reportDateStr, tempTotalHourCount.add(tempHourCount));
+                            } else {
+                                dateHourCountPair.put(reportDateStr, tempTotalHourCount);
+                            }
+                        }
+                        if ("天数".equals(unit)) {
+                            // 将 actualValue 换算成 H
+                            BigDecimal hours = actualValue.multiply(new BigDecimal("24"));
+                            tempTotalHourCount = tempTotalHourCount.add(hours);
+                            if (dateHourCountPair.containsKey(reportDateStr)) {
+                                BigDecimal tempHourCount = dateHourCountPair.get(reportDateStr);
+                                dateHourCountPair.put(reportDateStr, tempTotalHourCount.add(tempHourCount));
+                            } else {
+                                dateHourCountPair.put(reportDateStr, tempTotalHourCount);
+                            }
+                        }
+                        if ("方".equals(unit)) {
+                            tempTotalWaterVolume = tempTotalWaterVolume.add(actualValue);
+                            if (dateWaterVolumePair.containsKey(reportDateStr)) {
+                                BigDecimal tempWaterVolume = dateWaterVolumePair.get(reportDateStr);
+                                dateWaterVolumePair.put(reportDateStr, tempTotalWaterVolume.add(tempWaterVolume));
+                            } else {
+                                dateWaterVolumePair.put(reportDateStr, tempTotalWaterVolume);
+                            }
+                        }
+                        if ("井数".equals(unit)) {
+                            tempTotalCumulativeWorkingWell = tempTotalCumulativeWorkingWell.add(actualValue);
+                            if (dateWorkingWellPair.containsKey(reportDateStr)) {
+                                BigDecimal tempWorkingWell = dateWorkingWellPair.get(reportDateStr);
+                                dateWorkingWellPair.put(reportDateStr, tempTotalCumulativeWorkingWell.add(tempWorkingWell));
+                            } else {
+                                dateWorkingWellPair.put(reportDateStr, tempTotalCumulativeWorkingWell);
+                            }
+                        }
+                        if ("段数".equals(unit)) {
+                            // 累计施工层
+                            tempTotalCumulativeWorkingLayers = tempTotalCumulativeWorkingLayers.add(actualValue);
+                            if (dateWorkingLayersPair.containsKey(reportDateStr)) {
+                                BigDecimal tempWorkingLayer = dateWorkingLayersPair.get(reportDateStr);
+                                dateWorkingLayersPair.put(reportDateStr, tempTotalCumulativeWorkingLayers.add(tempWorkingLayer));
+                            } else {
+                                dateWorkingLayersPair.put(reportDateStr, tempTotalCumulativeWorkingLayers);
+                            }
+                        }
+                        if ("台次".equals(unit) && "当日泵车台次".equals(attr.getName())) {
+                            tempTotalPumpTrips = tempTotalPumpTrips.add(actualValue);
+                            if (datePumpTripsPair.containsKey(reportDateStr)) {
+                                BigDecimal tempPumpTrips = datePumpTripsPair.get(reportDateStr);
+                                datePumpTripsPair.put(reportDateStr, tempTotalPumpTrips.add(tempPumpTrips));
+                            } else {
+                                datePumpTripsPair.put(reportDateStr, tempTotalPumpTrips);
+                            }
+                        }
+                        if ("台次".equals(unit) && ("当日仪表/混砂".equals(attr.getName())
+                                || "当日混砂".equals(attr.getName()) || "当日仪表".equals(attr.getName()))) {
+                            tempTotalMixSand = tempTotalMixSand.add(actualValue);
+                            if (dateMixSandPair.containsKey(reportDateStr)) {
+                                BigDecimal tempMixSand = dateMixSandPair.get(reportDateStr);
+                                dateMixSandPair.put(reportDateStr, tempTotalMixSand.add(tempMixSand));
+                            } else {
+                                dateMixSandPair.put(reportDateStr, tempTotalMixSand);
+                            }
+                        }
+                    }
+                }
+            });
+        }
+
+        // 新增:日期字符串集合
+        List<String> dateRangeList = new ArrayList<>();
+
+        if (createTimes.length >= 2) {
+            LocalDate startDate = createTimes[0].toLocalDate();
+            LocalDate endDate = createTimes[1].toLocalDate();
+            // 生成从起始日期到结束日期的所有日期
+            for (LocalDate date = startDate;
+                 !date.isAfter(endDate);  // 使用 isAfter 而不是 <= 判断
+                 date = date.plusDays(1)) {
+                dateRangeList.add(date.format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN)));
+            }
+        }
+
+        if (CollUtil.isNotEmpty(dateRangeList)) {
+            dateRangeList.forEach(date -> {
+                IotRdDailyReportPolylineVO statistics = new IotRdDailyReportPolylineVO();
+                statistics.setReportDate(date);
+                statistics.setCumulativeBridgePlug(dateBridgePlugPair.get(date));
+                statistics.setCumulativeRunCount(dateRunCountPair.get(date));
+                statistics.setCumulativeWorkingWell(dateWorkingWellPair.get(date));
+                statistics.setCumulativeHourCount(dateHourCountPair.get(date));
+                statistics.setCumulativeFuels(dateFuelsPair.get(date));
+                statistics.setCumulativeWaterVolume(dateWaterVolumePair.get(date));
+                statistics.setCumulativeWorkingLayers(dateWorkingLayersPair.get(date));
+                BigDecimal taici = BigDecimal.ZERO;
+                // 合并 仪表混砂 泵车 的台次
+                if (CollUtil.isNotEmpty(dateMixSandPair)) {
+                    BigDecimal mixSand = dateMixSandPair.get(date);
+                    mixSand = ObjUtil.isNotEmpty(mixSand) ? mixSand : BigDecimal.ZERO;
+                    taici = taici.add(mixSand);
+                }
+                if (CollUtil.isNotEmpty(datePumpTripsPair)) {
+                    BigDecimal pumpTrips = datePumpTripsPair.get(date);
+                    pumpTrips = ObjUtil.isNotEmpty(pumpTrips) ? pumpTrips : BigDecimal.ZERO;
+                    taici = taici.add(pumpTrips);
+                }
+                statistics.setCumulativeMixSand(dateMixSandPair.get(date));
+                statistics.setCumulativePumpTrips(datePumpTripsPair.get(date));
+                statistics.setTaici(taici);
+                result.add(statistics);
+            });
         }
         return result;
     }