소스 검색

pms 5#国日报汇总 项目部 队伍

zhangcl 2 주 전
부모
커밋
de96577a24
10개의 변경된 파일528개의 추가작업 그리고 16개의 파일을 삭제
  1. 38 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotfivedailyreport/IotFiveDailyReportController.java
  2. 4 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockRespVO.java
  3. 3 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockSaveReqVO.java
  4. 6 6
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java
  5. 4 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotsapstock/IotSapStockDO.java
  6. 7 1
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/sap/SapController.java
  7. 16 2
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/sap/service/IotSapServiceImpl.java
  8. 8 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotfivedailyreport/IotFiveDailyReportService.java
  9. 435 0
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotfivedailyreport/IotFiveDailyReportServiceImpl.java
  10. 7 7
      yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrddailyreport/IotRdDailyReportServiceImpl.java

+ 38 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotfivedailyreport/IotFiveDailyReportController.java

@@ -313,6 +313,44 @@ public class IotFiveDailyReportController {
         return success(statistics);
     }
 
+    @GetMapping("/summaryStatistics")
+    @Operation(summary = "5#国日报 汇总 统计")
+    @PreAuthorize("@ss.hasPermission('pms:iot-five-daily-report:query')")
+    public CommonResult<Map<String, Object>> summaryStatistics(@Valid IotFiveDailyReportPageReqVO pageReqVO) {
+        List<IotFiveDailyReportStatisticsRespVO> result = new ArrayList<>();
+        Map<String, Object> resultMap = new HashMap<>();
+        // 根据查询参数筛选出 符合条件 的记录id 再传入 分页查询
+        Set<Long> projectIds = new HashSet<>();
+        Set<Long> taskIds = new HashSet<>();
+        if (StrUtil.isNotBlank(pageReqVO.getProjectName())) {
+            IotProjectInfoPageReqVO reqVO = new IotProjectInfoPageReqVO();
+            reqVO.setContractName(pageReqVO.getProjectName());
+            List<IotProjectInfoDO> projects = iotProjectInfoService.getIotProjectInfos(reqVO);
+            if (CollUtil.isNotEmpty(projects)) {
+                projects.forEach(project -> {
+                    projectIds.add(project.getId());
+                });
+                pageReqVO.setProjectIds(projectIds);
+            }
+        }
+        if (StrUtil.isNotBlank(pageReqVO.getWellName())) {
+            IotProjectTaskPageReqVO reqVO = new IotProjectTaskPageReqVO();
+            reqVO.setSearchKey(pageReqVO.getWellName());
+            List<IotProjectTaskDO> tasks = iotProjectTaskService.projectTasks(reqVO);
+            if (CollUtil.isNotEmpty(tasks)) {
+                tasks.forEach(task -> {
+                    taskIds.add(task.getId());
+                });
+                pageReqVO.setTaskIds(taskIds);
+            }
+        }
+        List<IotFiveDailyReportStatisticsRespVO> statistics = iotFiveDailyReportService.summaryStatistics(pageReqVO);
+        result.addAll(statistics);
+        resultMap.put("list", result);
+        resultMap.put("total", result.size());
+        return success(resultMap);
+    }
+
     @GetMapping("/export-excel")
     @Operation(summary = "导出5#国日报 Excel")
     @PreAuthorize("@ss.hasPermission('pms:iot-five-daily-report:export')")

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotsapstock/vo/IotSapStockRespVO.java

@@ -61,6 +61,10 @@ public class IotSapStockRespVO {
     @ExcelProperty("单价(元)")
     private BigDecimal unitPrice;
 
+    @Schema(description = "总价", example = "14017")
+    @ExcelProperty("总价(元)")
+    private BigDecimal totalPrice;
+
     @Schema(description = "单位")
     @ExcelProperty("单位")
     private String unit;

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

@@ -52,6 +52,9 @@ public class IotSapStockSaveReqVO {
     @Schema(description = "单价", example = "14017")
     private BigDecimal unitPrice;
 
+    @Schema(description = "总价", example = "14017")
+    private BigDecimal totalPrice;
+
     @Schema(description = "单位")
     private String unit;
 

+ 6 - 6
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java

@@ -1545,11 +1545,11 @@ public class IotStaticController {
         // 筛选出 封存 的主设备
         if (CollUtil.isNotEmpty(mainDevices)) {
             mainDevices.forEach(device -> {
-                if ("fc".equals(device.getDeviceStatus())) {
+                /* if ("fc".equals(device.getDeviceStatus())) {
                     fcMainDeviceIds.add(device.getId());
-                } else {
+                } else { */
                     abDeviceIds.add(device.getId());
-                }
+                // }
             });
         }
 
@@ -4495,11 +4495,11 @@ public class IotStaticController {
             // 过滤掉 封存 的 压裂 连油 主设备
             if (CollUtil.isNotEmpty(utilizeDevices)) {
                 utilizeDevices.forEach(device -> {
-                    if ("fc".equals(device.getDeviceStatus())) {
+                    /* if ("fc".equals(device.getDeviceStatus())) {
                         fcMainDeviceIds.add(device.getId());
-                    } else {
+                    } else { */
                         abDeviceIds.add(device.getId());
-                    }
+                    // }
                 });
             }
         }

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/iotsapstock/IotSapStockDO.java

@@ -81,6 +81,10 @@ public class IotSapStockDO extends BaseDO {
      * 单价
      */
     private BigDecimal unitPrice;
+    /**
+     * 总价
+     */
+    private BigDecimal totalPrice;
     /**
      * 单位
      */

+ 7 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/sap/SapController.java

@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -41,7 +42,7 @@ public class SapController {
 
             // 设置输入参数
             JCoParameterList input = function.getImportParameterList();
-            input.setValue("IV_WERKS", "5021");
+            input.setValue("IV_WERKS", "6000");
 
             // 执行 RFC 调用
             function.execute(destination);
@@ -55,7 +56,9 @@ public class SapController {
                     System.out.println(material.getName());
                 });
             }
+
             if (etStockTable != null && etStockTable.getNumRows() > 0) {
+                BigDecimal jiage = BigDecimal.ZERO;
                 for (int i = 0; i < etStockTable.getNumRows(); i++) {
                     etStockTable.setRow(i);
                     System.out.println(String.format("行号 %d: 工厂=%s, 物料编码=%s, 物料描述=%s, 库存数量 非限制=%s, 库存地点编码=%s, 批次=%s \n" +
@@ -75,7 +78,10 @@ public class SapController {
                             etStockTable.getString("SPEME"),    // 已冻结
                             etStockTable.getBigDecimal("JIAGE")     // 库存价格
                     ));
+                    BigDecimal tempJiage = etStockTable.getBigDecimal("JIAGE");
+                    jiage = jiage.add(tempJiage);
                 }
+                System.out.println("总价格:" + jiage.toString());
             }
             return "Material Info: " + output.getString("ET_STOCK");
         } catch (JCoException e) {

+ 16 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/sap/service/IotSapServiceImpl.java

@@ -1183,8 +1183,22 @@ public class IotSapServiceImpl implements IotSapService {
                 // 设置物料信息
                 sapStock.setMaterialCode(stock.getMATNR().replaceFirst("^0+", ""));
                 sapStock.setMaterialName(stock.getMAKTX());
-                sapStock.setQuantity(stock.getLABST());
-                sapStock.setUnitPrice(stock.getJIAGE());
+                // 数量
+                BigDecimal quantity = stock.getLABST();
+                sapStock.setQuantity(quantity);
+                // 总价
+                BigDecimal totalPrice = stock.getJIAGE();
+                // 单价 总价/数量
+                quantity = ObjUtil.isEmpty(quantity) ? BigDecimal.ZERO : quantity;
+                totalPrice = ObjUtil.isEmpty(totalPrice) ? BigDecimal.ZERO : totalPrice;
+                if (quantity.compareTo(BigDecimal.ZERO) > 0) {
+                    BigDecimal unitPrice = totalPrice.divide(quantity, 2, RoundingMode.HALF_UP);
+                    sapStock.setUnitPrice(unitPrice);
+                } else {
+                    sapStock.setUnitPrice(stock.getJIAGE());
+                }
+                // 总价
+                sapStock.setTotalPrice(totalPrice);
                 sapStock.setUnit(stock.getMEINS());
                 sapStock.setSyncTime(LocalDateTime.now());
 

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotfivedailyreport/IotFiveDailyReportService.java

@@ -68,4 +68,12 @@ public interface IotFiveDailyReportService {
      * @return 5#国日报汇总统计
      */
     IotFiveDailyReportStatisticsRespVO totalWorkload(IotFiveDailyReportPageReqVO pageReqVO);
+
+    /**
+     * 5#国 日报 汇总统计
+     *
+     * @param pageReqVO 列表查询
+     * @return 5#国日报汇总统计
+     */
+    List<IotFiveDailyReportStatisticsRespVO> summaryStatistics(IotFiveDailyReportPageReqVO pageReqVO);
 }

+ 435 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotfivedailyreport/IotFiveDailyReportServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.pms.service.iotfivedailyreport;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -10,6 +11,8 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotfivedailyreport.vo.IotFiv
 import cn.iocoder.yudao.module.pms.controller.admin.iotfivedailyreport.vo.IotFiveDailyReportStatisticsRespVO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotfivedailyreport.IotFiveDailyReportDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotfivedailyreport.IotFiveDailyReportMapper;
+import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
@@ -17,6 +20,8 @@ import org.springframework.validation.annotation.Validated;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -181,4 +186,434 @@ public class IotFiveDailyReportServiceImpl implements IotFiveDailyReportService
         return result;
     }
 
+    @Override
+    public List<IotFiveDailyReportStatisticsRespVO> summaryStatistics(IotFiveDailyReportPageReqVO pageReqVO) {
+        List<IotFiveDailyReportStatisticsRespVO> result = new ArrayList<>();
+        // 不分页统计所有数据
+        Set<Long> ids = new HashSet<>();
+        if (ObjUtil.isEmpty(pageReqVO.getDeptId())) {
+            pageReqVO.setDeptId(388l);
+        }
+        ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
+        // 找到所有子部门对象集合
+        ids.add(pageReqVO.getDeptId());
+        pageReqVO.setDeptIds(ids);
+        // 检查contractName不为空但projectIds为空的情况
+        if (StrUtil.isNotBlank(pageReqVO.getProjectName()) && (CollUtil.isEmpty(pageReqVO.getProjectIds()))) {
+            return new ArrayList<>();
+        }
+        // 检查taskName不为空但taskIds为空的情况
+        if (StrUtil.isNotBlank(pageReqVO.getWellName()) && (CollUtil.isEmpty(pageReqVO.getTaskIds()))) {
+            return new ArrayList<>();
+        }
+        PageResult<IotFiveDailyReportDO> pageReports = iotFiveDailyReportMapper.selectPage(pageReqVO);
+        List<IotFiveDailyReportDO> dailyReports = pageReports.getList();
+
+        // 默认显示所有项目部的汇总数据(新疆分公司也展示 下属各项目部的数据)
+        // 点击项目部 显示 下属队伍的数据
+        // 首先判断点击的部门是属于 公司 还是 队伍 如果没有点击任何部门 默认查询所有项目部数据
+        if (ObjUtil.isEmpty(pageReqVO.getDeptId())) {
+            result = statisticsByProjectDept(dailyReports, 388L, pageReqVO);
+        } else {
+            // 判断点击的组织树中的部门类型 类型(公司级1 项目部2 队伍3)
+            DeptDO selectedDept = deptService.getDept(pageReqVO.getDeptId());
+            if ("1".equals(selectedDept.getType())) {
+                // 以项目部为维度汇总数据
+                result = statisticsByProjectDept(dailyReports, pageReqVO.getDeptId(), pageReqVO);
+            } else if ("2".equals(selectedDept.getType())) {
+                // 以队伍为维度汇总数据
+                result = statisticsByProjectDepartment(dailyReports, pageReqVO);
+            } else if ("3".equals(selectedDept.getType())) {
+                // 显示单个队伍的汇总数据
+                result = statisticsByProjectDepartment(dailyReports, pageReqVO);
+            } else {
+                // 点击的部门没有类型 判断部门下的是否包含 项目部类型部门 新疆分公司
+                // 以项目部为维度汇总数据
+                result = statisticsByProjectDept(dailyReports, pageReqVO.getDeptId(), pageReqVO);
+            }
+        }
+        // 根据result集合内对象的 sort 属性正序排列 sort 类型为 integer 类型
+        if (CollUtil.isNotEmpty(result)) {
+            result.sort(Comparator.comparing(
+                    IotFiveDailyReportStatisticsRespVO::getSort,
+                    Comparator.nullsLast(Comparator.naturalOrder())
+            ));
+        }
+        return result;
+    }
+
+
+    /**
+     * 按项目部维度 汇总 统计数据
+     * @param dailyReports 日报数据列表
+     * @param rootDeptId 根部门ID(如 388L为 5#国 根部门,或其他公司级部门ID)
+     * @return 项目部维度统计结果列表
+     */
+    private List<IotFiveDailyReportStatisticsRespVO> statisticsByProjectDept(List<IotFiveDailyReportDO> dailyReports,
+                                                                           Long rootDeptId, IotFiveDailyReportPageReqVO pageReqVO) {
+        List<IotFiveDailyReportStatisticsRespVO> 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<>();
+        // key队伍id    value队伍部门
+        Map<Long, DeptDO> teamDeptPair = new HashMap<>();
+
+        // key队伍id/项目部id   value累计 桥塞(个数)
+        Map<Long, BigDecimal> cumulativeBridgePlugPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 注液
+        Map<Long, BigDecimal> cumulativeLiquidPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 作业泵车数量
+        Map<Long, BigDecimal> cumulativeWorkDevicePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 油耗
+        Map<Long, BigDecimal> cumulativeFuelsPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 累计主设备泵车数量
+        Map<Long, BigDecimal> cumulativeMainDevicePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 段数 累计施工-层
+        Map<Long, BigDecimal> cumulativeWorkingLayersPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 台次 当日仪表/混砂
+        Map<Long, BigDecimal> cumulativeMixSandPair = new HashMap<>();
+
+        // 队伍id 集合
+        Set<Long> teamIds = new HashSet<>();
+
+        // 以项目部为维度统计数据
+        // 找到所有项目部与队伍的对应关系
+        // 查询指定根部门下的所有子部门
+        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);
+            }
+            if ("3".equals(dept.getType())) {
+                // 队伍
+                teamIds.add(dept.getId());
+                teamDeptPair.put(dept.getId(), dept);
+            }
+            // 可能是项目部 也可能是队伍
+            teamProjectIdPair.put(dept.getId(), dept.getParentId());
+        });
+
+        // 计算指定时间区间内包含的天数
+        long daysCount;
+        if (ObjUtil.isNotEmpty(pageReqVO.getCreateTime()) && pageReqVO.getCreateTime().length >= 2) {
+            LocalDateTime start = pageReqVO.getCreateTime()[0];
+            LocalDateTime end = pageReqVO.getCreateTime()[1];
+
+            if (ObjUtil.isNotEmpty(start) && ObjUtil.isNotEmpty(end) && !end.isBefore(start)) {
+                // 使用ChronoUnit.DAYS.between计算天数差,并+1包含首尾两天
+                daysCount = ChronoUnit.DAYS.between(
+                        start.toLocalDate(),
+                        end.toLocalDate()
+                ) + 1;
+            } else {
+                daysCount = 0L;
+            }
+        } else {
+            daysCount = 0L;
+        }
+
+        // 累计计算各项 工作量
+        if (CollUtil.isNotEmpty(dailyReports)) {
+            dailyReports.forEach(report -> {
+                // 油耗
+                BigDecimal dailyFuel = report.getDailyFuel();
+                // 当日主压层数(层)
+                BigDecimal dailyLayers = report.getDailyWorkingLayers();
+                // 当日加砂
+                BigDecimal dailySand = report.getDailySandVolume();
+                // 当日注液
+                BigDecimal dailyLiquid = report.getDailyLiquidVolume();
+                // 设备利用率  作业泵车数量/主设备泵车数量
+                BigDecimal wokDeviceNum = report.getWokDeviceNum();
+                BigDecimal mainDeviceNum = report.getMainDeviceNum();
+
+                if (ObjUtil.isNotEmpty(report.getDeptId()) && teamProjectIdPair.containsKey(report.getDeptId())) {
+                    // projectDeptId可能是项目部 也可能是项目的上级
+                    Long projectDeptId = 0l;
+                    if (teamDeptPair.containsKey(report.getDeptId())) {
+                        // 日报deptId如果是队伍 获取队伍的上级项目部
+                        projectDeptId = teamProjectIdPair.get(report.getDeptId());
+                    }
+                    if (projectDeptPair.containsKey(report.getDeptId())) {
+                        // 日报deptId如果是项目部 使用当前项目部
+                        projectDeptId = report.getDeptId();
+                    }
+
+                    if (ObjUtil.isNotEmpty(projectDeptId) && (projectDeptId > 0)) {
+                        // 累计油耗
+                        if (cumulativeFuelsPair.containsKey(projectDeptId)) {
+                            BigDecimal existTotalFuel = cumulativeFuelsPair.get(projectDeptId);
+                            BigDecimal tempTotalFuel = existTotalFuel.add(dailyFuel);
+                            cumulativeFuelsPair.put(projectDeptId, tempTotalFuel);
+                        } else {
+                            cumulativeFuelsPair.put(projectDeptId, dailyFuel);
+                        }
+                        // 累计主压层数(层)
+                        if (cumulativeWorkingLayersPair.containsKey(projectDeptId)) {
+                            BigDecimal existTotalLayers = cumulativeWorkingLayersPair.get(projectDeptId);
+                            BigDecimal tempTotalLayers = existTotalLayers.add(dailyFuel);
+                            cumulativeWorkingLayersPair.put(projectDeptId, tempTotalLayers);
+                        } else {
+                            cumulativeWorkingLayersPair.put(projectDeptId, dailyLayers);
+                        }
+                        // 累计加砂
+                        if (cumulativeMixSandPair.containsKey(projectDeptId)) {
+                            BigDecimal existTotalSand = cumulativeMixSandPair.get(projectDeptId);
+                            BigDecimal tempTotalSand = existTotalSand.add(dailyFuel);
+                            cumulativeMixSandPair.put(projectDeptId, tempTotalSand);
+                        } else {
+                            cumulativeMixSandPair.put(projectDeptId, dailySand);
+                        }
+                        // 累计注液
+                        if (cumulativeLiquidPair.containsKey(projectDeptId)) {
+                            BigDecimal existTotalLiquid = cumulativeLiquidPair.get(projectDeptId);
+                            BigDecimal tempTotalLiquid = existTotalLiquid.add(dailyFuel);
+                            cumulativeLiquidPair.put(projectDeptId, tempTotalLiquid);
+                        } else {
+                            cumulativeLiquidPair.put(projectDeptId, dailyLiquid);
+                        }
+                        // 累计作业泵车数量
+                        if (cumulativeWorkDevicePair.containsKey(projectDeptId)) {
+                            BigDecimal existTotalWorkNum = cumulativeWorkDevicePair.get(projectDeptId);
+                            BigDecimal tempWorkDeviceNum = existTotalWorkNum.add(wokDeviceNum);
+                            cumulativeWorkDevicePair.put(projectDeptId, tempWorkDeviceNum);
+                        } else {
+                            cumulativeWorkDevicePair.put(projectDeptId, wokDeviceNum);
+                        }
+                        // 累计主设备数量
+                        if (cumulativeMainDevicePair.containsKey(projectDeptId)) {
+                            BigDecimal existMainDeviceNum = cumulativeMainDevicePair.get(projectDeptId);
+                            BigDecimal tempMainDeviceNum = existMainDeviceNum.add(mainDeviceNum);
+                            cumulativeMainDevicePair.put(projectDeptId, tempMainDeviceNum);
+                        } else {
+                            cumulativeMainDevicePair.put(projectDeptId, mainDeviceNum);
+                        }
+                    }
+                }
+            });
+        }
+
+        // 生成返回的数据列表集合
+        projectDeptPair.forEach((deptId, dept) -> {
+            IotFiveDailyReportStatisticsRespVO statistics = new IotFiveDailyReportStatisticsRespVO();
+            statistics.setProjectDeptId(deptId);
+            statistics.setProjectDeptName(dept.getName());
+            statistics.setSort(dept.getSort());
+            statistics.setType("2");
+            // 计算项目部下设备利用率
+            if (CollUtil.isNotEmpty(cumulativeWorkDevicePair) && CollUtil.isNotEmpty(cumulativeMainDevicePair)) {
+                BigDecimal workDeviceNum = cumulativeWorkDevicePair.get(deptId);
+                BigDecimal mainDeviceNum = cumulativeMainDevicePair.get(deptId);
+                if (ObjUtil.isNotEmpty(mainDeviceNum) && mainDeviceNum.compareTo(BigDecimal.ZERO) > 0) {
+                    BigDecimal utilizationRate = workDeviceNum.divide(mainDeviceNum, 4, RoundingMode.HALF_UP);
+                    statistics.setUtilizationRate(utilizationRate);
+                }
+            }
+            statistics.setCumulativeWorkingLayers(cumulativeWorkingLayersPair.get(deptId));
+            statistics.setCumulativeMixSand(cumulativeMixSandPair.get(deptId));
+            statistics.setCumulativeLiquidVolume(cumulativeLiquidPair.get(deptId));
+            BigDecimal cumulativeFuel = cumulativeFuelsPair.get(deptId);
+            if (ObjUtil.isNotEmpty(cumulativeFuel)) {
+                // 油耗单位转换成 万升
+                BigDecimal FuelWan = cumulativeFuel
+                        .divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP);
+                statistics.setTotalDailyFuel(FuelWan);
+            }
+
+            statistics.setCumulativeBridgePlug(cumulativeBridgePlugPair.get(deptId));
+
+            result.add(statistics);
+        });
+        return result;
+    }
+
+    /**
+     * 按 队伍 维度统计 汇总 数据
+     * @param dailyReports 日报数据列表
+     * @param pageReqVO (deptId)项目部ID 或 队伍id
+     * @return 队伍 维度统计结果列表
+     */
+    private List<IotFiveDailyReportStatisticsRespVO> statisticsByProjectDepartment(List<IotFiveDailyReportDO> dailyReports, IotFiveDailyReportPageReqVO pageReqVO) {
+        List<IotFiveDailyReportStatisticsRespVO> result = new ArrayList<>();
+
+        Set<Long> teamDeptIds = new HashSet<>();
+        // key项目部id    value项目部名称
+        Map<Long, DeptDO> projectDeptPair = new HashMap<>();
+        // key队伍id    value队伍名称
+        Map<Long, DeptDO> teamDeptPair = new HashMap<>();
+        // key部门id   value部门parentId
+        Map<Long, Long> teamProjectIdPair = new HashMap<>();
+
+        // key队伍id/项目部id   value累计 作业泵车数量
+        Map<Long, BigDecimal> cumulativeWorkDevicePair = new HashMap<>();
+        // key队伍id/项目部id   value累计 趟数
+        Map<Long, BigDecimal> cumulativeLiquidPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 油耗
+        Map<Long, BigDecimal> cumulativeFuelsPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 段数 累计施工-层
+        Map<Long, BigDecimal> cumulativeWorkingLayersPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 台次 当日仪表/混砂
+        Map<Long, BigDecimal> cumulativeMixSandPair = new HashMap<>();
+        // key队伍id/项目部id   value累计 主设备泵车数量
+        Map<Long, BigDecimal> cumulativeMainDevicePair = new HashMap<>();
+
+        // 以 队伍 为维度统计数据
+        // 找到所有项目部与队伍的对应关系
+        // 查询指定根部门下的所有子部门
+        Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
+        DeptListReqVO reqVO = new DeptListReqVO();
+        // 查询某支队伍 或 所属项目部的信息
+        allRhChildDeptIds.add(pageReqVO.getDeptId());
+        reqVO.setDeptIds(allRhChildDeptIds);
+        List<DeptDO> depts = deptService.getDeptList(reqVO);
+
+        // 构建项目部映射和父子部门关系
+        depts.forEach(dept -> {
+            if ("3".equals(dept.getType())) {
+                // 队伍
+                teamDeptIds.add(dept.getId());
+                teamDeptPair.put(dept.getId(), dept);
+            }
+            if ("2".equals(dept.getType())) {
+                // 项目部
+                projectDeptPair.put(dept.getId(), dept);
+            }
+            teamProjectIdPair.put(dept.getId(), dept.getParentId());
+        });
+
+        LocalDateTime[] createTime = pageReqVO.getCreateTime();
+        List<Long> daysCounts = new ArrayList<>();
+        // 如果 createTime 包含的时间是 1天则查询 这1天时间内的 队伍总数 施工队伍数量 施工准备队伍数量 驻地待命队伍数量
+        if (ObjUtil.isNotEmpty(createTime)) {
+            LocalDateTime startTime = createTime[0];
+            LocalDateTime endTime = createTime[1];
+            if (ObjUtil.isNotEmpty(startTime) && ObjUtil.isNotEmpty(endTime) && !endTime.isBefore(startTime)) {
+                // 查询时间区间包含的天数
+                // 使用ChronoUnit.DAYS.between计算天数差,并+1包含首尾两天
+                long daysCount = ChronoUnit.DAYS.between(
+                        startTime.toLocalDate(),
+                        endTime.toLocalDate()
+                ) + 1;
+                daysCounts.add(daysCount);
+            }
+        }
+
+        // 累计计算 工作量
+        if (CollUtil.isNotEmpty(dailyReports)) {
+            dailyReports.forEach(report -> {
+                // 油耗
+                BigDecimal dailyFuel = report.getDailyFuel();
+                // 当日主压层数(层)
+                BigDecimal dailyLayers = report.getDailyWorkingLayers();
+                // 当日加砂
+                BigDecimal dailySand = report.getDailySandVolume();
+                // 当日注液
+                BigDecimal dailyLiquid = report.getDailyLiquidVolume();
+                // 设备利用率  作业泵车数量/主设备泵车数量
+                BigDecimal wokDeviceNum = report.getWokDeviceNum();
+                BigDecimal mainDeviceNum = report.getMainDeviceNum();
+
+                if (ObjUtil.isNotEmpty(report.getDeptId()) && teamProjectIdPair.containsKey(report.getDeptId())) {
+                    // projectDeptId 可能是项目部 也可能是项目的上级
+                    Long detailDeptId = 0l;
+                    detailDeptId = report.getDeptId();
+                    if (ObjUtil.isNotEmpty(detailDeptId) && (detailDeptId > 0)) {
+                        // 累计油耗
+                        if (cumulativeFuelsPair.containsKey(detailDeptId)) {
+                            BigDecimal existTotalFuel = cumulativeFuelsPair.get(detailDeptId);
+                            BigDecimal tempTotalFuel = existTotalFuel.add(dailyFuel);
+                            cumulativeFuelsPair.put(detailDeptId, tempTotalFuel);
+                        } else {
+                            cumulativeFuelsPair.put(detailDeptId, dailyFuel);
+                        }
+                        // 累计主压层数(层)
+                        if (cumulativeWorkingLayersPair.containsKey(detailDeptId)) {
+                            BigDecimal existTotalLayers = cumulativeWorkingLayersPair.get(detailDeptId);
+                            BigDecimal tempTotalLayers = existTotalLayers.add(dailyFuel);
+                            cumulativeWorkingLayersPair.put(detailDeptId, tempTotalLayers);
+                        } else {
+                            cumulativeWorkingLayersPair.put(detailDeptId, dailyLayers);
+                        }
+                        // 累计加砂
+                        if (cumulativeMixSandPair.containsKey(detailDeptId)) {
+                            BigDecimal existTotalSand = cumulativeMixSandPair.get(detailDeptId);
+                            BigDecimal tempTotalSand = existTotalSand.add(dailyFuel);
+                            cumulativeMixSandPair.put(detailDeptId, tempTotalSand);
+                        } else {
+                            cumulativeMixSandPair.put(detailDeptId, dailySand);
+                        }
+                        // 累计注液
+                        if (cumulativeLiquidPair.containsKey(detailDeptId)) {
+                            BigDecimal existTotalLiquid = cumulativeLiquidPair.get(detailDeptId);
+                            BigDecimal tempTotalLiquid = existTotalLiquid.add(dailyFuel);
+                            cumulativeLiquidPair.put(detailDeptId, tempTotalLiquid);
+                        } else {
+                            cumulativeLiquidPair.put(detailDeptId, dailyLiquid);
+                        }
+                        // 累计作业泵车数量
+                        if (cumulativeWorkDevicePair.containsKey(detailDeptId)) {
+                            BigDecimal existTotalWorkNum = cumulativeWorkDevicePair.get(detailDeptId);
+                            BigDecimal tempWorkDeviceNum = existTotalWorkNum.add(wokDeviceNum);
+                            cumulativeWorkDevicePair.put(detailDeptId, tempWorkDeviceNum);
+                        } else {
+                            cumulativeWorkDevicePair.put(detailDeptId, wokDeviceNum);
+                        }
+                        // 累计主设备数量
+                        if (cumulativeMainDevicePair.containsKey(detailDeptId)) {
+                            BigDecimal existMainDeviceNum = cumulativeMainDevicePair.get(detailDeptId);
+                            BigDecimal tempMainDeviceNum = existMainDeviceNum.add(mainDeviceNum);
+                            cumulativeMainDevicePair.put(detailDeptId, tempMainDeviceNum);
+                        } else {
+                            cumulativeMainDevicePair.put(detailDeptId, mainDeviceNum);
+                        }
+                    }
+                }
+            });
+            // 计算每个队伍的设备利用率 (作业泵车数量) / (主设备泵车数量)
+        }
+
+        // 队伍数据  生成返回的数据列表集合
+        teamDeptPair.forEach((teamDeptId, dept) -> {
+            IotFiveDailyReportStatisticsRespVO statistics = new IotFiveDailyReportStatisticsRespVO();
+            statistics.setTeamId(teamDeptId);
+            statistics.setTeamName(dept.getName());
+            statistics.setSort(dept.getSort());
+            if (teamDeptPair.containsKey(teamDeptId)) {
+                statistics.setType("3");
+            }
+            // 计算队伍设备利用率
+            if (CollUtil.isNotEmpty(cumulativeWorkDevicePair) && CollUtil.isNotEmpty(cumulativeMainDevicePair)) {
+                BigDecimal workDeviceNum = cumulativeWorkDevicePair.get(teamDeptId);
+                BigDecimal mainDeviceNum = cumulativeMainDevicePair.get(teamDeptId);
+                if (ObjUtil.isNotEmpty(mainDeviceNum) && mainDeviceNum.compareTo(BigDecimal.ZERO) > 0) {
+                    BigDecimal utilizationRate = workDeviceNum.divide(mainDeviceNum, 4, RoundingMode.HALF_UP);
+                    statistics.setUtilizationRate(utilizationRate);
+                }
+            }
+            statistics.setCumulativeWorkingLayers(cumulativeWorkingLayersPair.get(teamDeptId));
+            statistics.setCumulativeMixSand(cumulativeMixSandPair.get(teamDeptId));
+            statistics.setCumulativeLiquidVolume(cumulativeLiquidPair.get(teamDeptId));
+            BigDecimal cumulativeFuel = cumulativeFuelsPair.get(teamDeptId);
+            if (ObjUtil.isNotEmpty(cumulativeFuel)) {
+                // 油耗单位转换成 万升
+                BigDecimal FuelWan = cumulativeFuel
+                        .divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP);
+                statistics.setTotalDailyFuel(FuelWan);
+            }
+
+            result.add(statistics);
+        });
+
+        return result;
+    }
+
 }

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

@@ -1174,11 +1174,11 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
         // 过滤掉 封存 的 压裂 连油 主设备
         if (CollUtil.isNotEmpty(mainDevices)) {
             mainDevices.forEach(device -> {
-                if ("fc".equals(device.getDeviceStatus())) {
+                /* if ("fc".equals(device.getDeviceStatus())) {
                     fcMainDeviceIds.add(device.getId());
-                } else {
+                } else { */
                     abDeviceIds.add(device.getId());
-                }
+                // }
             });
         }
 
@@ -1586,9 +1586,9 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
         // 筛选出 封存 的主设备
         if (CollUtil.isNotEmpty(mainDevices)) {
             mainDevices.forEach(device -> {
-                if ("fc".equals(device.getDeviceStatus())) {
+                /* if ("fc".equals(device.getDeviceStatus())) {
                     fcMainDeviceIds.add(device.getId());
-                }
+                }*/
             });
         }
 
@@ -2004,9 +2004,9 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
         // 筛选出 封存 的主设备
         if (CollUtil.isNotEmpty(mainDevices)) {
             mainDevices.forEach(device -> {
-                if ("fc".equals(device.getDeviceStatus())) {
+                /* if ("fc".equals(device.getDeviceStatus())) {
                     fcMainDeviceIds.add(device.getId());
-                }
+                } */
             });
         }