Parcourir la source

pms 工单完成情况 汇总

zhangcl il y a 10 heures
Parent
commit
06218fab4a

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

@@ -57,6 +57,9 @@ public class IotRhDailyReportStatisticsRespVO {
     @Schema(description = "运行时效")
     private BigDecimal transitTime = BigDecimal.ZERO;
 
+    @Schema(description = "非生产时效")
+    private BigDecimal nonProductiveTime = BigDecimal.ZERO;
+
     @Schema(description = "运行时效")
     @ExcelProperty("运行时效")
     private String transitTimePercent;

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

@@ -61,6 +61,9 @@ public class IotRyDailyReportStatisticsRespVO {
     @Schema(description = "运行时效")
     private BigDecimal transitTime = BigDecimal.ZERO;
 
+    @Schema(description = "非生产时效")
+    private BigDecimal nonProductiveTime = BigDecimal.ZERO;
+
     @Schema(description = "运行时效")
     @ExcelProperty("运行时效")
     private String transitTimePercent;

+ 36 - 9
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotRepairController.java

@@ -61,6 +61,20 @@ public class IotRepairController {
         BigDecimal totalFee = iotMaintainMapper.getMaintainFeeIn(pageReqVO);
         pageReqVO.setType("out");
         BigDecimal outFee = iotMaintainMapper.getMaintainFee(pageReqVO);
+        // 同比 去年同期相同统计数据对比 无数据
+        IotMainWorkOrderPageReqVO workOrderReqVO = new IotMainWorkOrderPageReqVO();
+        workOrderReqVO.setDeptIds(ids);
+        workOrderReqVO.setCreateTime(pageReqVO.getCreateTime());
+        List<IotMainWorkOrderDO> workOrders = iotMainWorkOrderService.workOrders(workOrderReqVO);
+        BigDecimal byFee = workOrders.stream()
+                .map(IotMainWorkOrderDO::getCost)
+                .map(fee -> Objects.isNull(fee) ? BigDecimal.ZERO : fee)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        BigDecimal tbByFee = new BigDecimal("0");
+        BigDecimal hbByFee = new BigDecimal("0");
+        // 同比 去年同期相同统计数据对比 无数据
+        tbByFee = tbByFee==null?BigDecimal.ZERO:tbByFee;
         //获取环比
         LocalDateTime lastYearStart = pageReqVO.getCreateTime()[0].minusYears(1);
         LocalDateTime lastYearEnd = pageReqVO.getCreateTime()[1].minusYears(1);
@@ -81,6 +95,8 @@ public class IotRepairController {
         if ("year".equals(pageReqVO.getTimeType())){
             tbTotalFee = hbTotalFee==null?BigDecimal.ZERO:hbTotalFee;
             tbOutFee = hbOutFee==null?BigDecimal.ZERO:hbOutFee;
+            // 保养 年 无同比环比数据
+            hbByFee = hbByFee==null?BigDecimal.ZERO:hbByFee;
         } else if ("month".equals(pageReqVO.getTimeType())){
             LocalDateTime lastMonthStart = startTime.minusMonths(1);
             LocalDateTime lastMonthEnd = endTime.minusMonths(1);
@@ -92,6 +108,13 @@ public class IotRepairController {
             tbTotalFee = iotMaintainMapper.getMaintainFeeIn(pageReqVO);
             pageReqVO.setType("out");
             tbOutFee = iotMaintainMapper.getMaintainFee(pageReqVO);
+            // 保养
+            workOrderReqVO.setCreateTime(monthTime);
+            List<IotMainWorkOrderDO> monthWorkOrders = iotMainWorkOrderService.workOrders(workOrderReqVO);
+            hbByFee = monthWorkOrders.stream()
+                    .map(IotMainWorkOrderDO::getCost)
+                    .map(fee -> Objects.isNull(fee) ? BigDecimal.ZERO : fee)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
         } else if ("day".equals(pageReqVO.getTimeType())){
             LocalDateTime lastDayStart = startTime.minusDays(1);
             LocalDateTime lastDayEnd = endTime.minusDays(1);
@@ -103,16 +126,20 @@ public class IotRepairController {
             tbTotalFee = iotMaintainMapper.getMaintainFeeIn(pageReqVO);
             pageReqVO.setType("out");
             tbOutFee = iotMaintainMapper.getMaintainFee(pageReqVO);
+            // 保养
+            workOrderReqVO.setCreateTime(dayTime);
+            List<IotMainWorkOrderDO> dayWorkOrders = iotMainWorkOrderService.workOrders(workOrderReqVO);
+            hbByFee = dayWorkOrders.stream()
+                    .map(IotMainWorkOrderDO::getCost)
+                    .map(fee -> Objects.isNull(fee) ? BigDecimal.ZERO : fee)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
         }
         // 查询保养费用
-        IotMainWorkOrderPageReqVO workOrderReqVO = new IotMainWorkOrderPageReqVO();
-        workOrderReqVO.setDeptIds(ids);
-        workOrderReqVO.setCreateTime(pageReqVO.getCreateTime());
-        List<IotMainWorkOrderDO> workOrders = iotMainWorkOrderService.workOrders(workOrderReqVO);
-        BigDecimal byFee = workOrders.stream()
-                .map(IotMainWorkOrderDO::getCost)
-                .map(fee -> Objects.isNull(fee) ? BigDecimal.ZERO : fee)
-                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        Map<String, Object> byMap = new HashMap<>();
+        byMap.put("total", byFee);
+        byMap.put("hb", hbByFee==null|| hbByFee.equals(BigDecimal.ZERO) ? hbByFee :((byFee.subtract(hbByFee)).divide(hbByFee,2, RoundingMode.HALF_UP)));
+        byMap.put("tb", tbByFee==null||tbByFee.equals(BigDecimal.ZERO)?tbByFee:((byFee.subtract(tbByFee)).divide(tbByFee,2, RoundingMode.HALF_UP)));
+
         Map<String, Object> totalMap = new HashMap<>();
         totalMap.put("total", totalFee);
         totalMap.put("hb", hbTotalFee==null|| hbTotalFee.equals(BigDecimal.ZERO) ? hbTotalFee :((totalFee.subtract(hbTotalFee)).divide(hbTotalFee,2, RoundingMode.HALF_UP)));
@@ -122,7 +149,7 @@ public class IotRepairController {
         outMap.put("hb", hbOutFee==null||hbOutFee.equals(BigDecimal.ZERO)?hbOutFee:((outFee.subtract(hbOutFee)).divide(hbOutFee,2, RoundingMode.HALF_UP)));
         outMap.put("tb", tbOutFee==null||tbOutFee.equals(BigDecimal.ZERO)?tbOutFee:((outFee.subtract(tbOutFee)).divide(tbOutFee,2, RoundingMode.HALF_UP)));
         return CommonResult.success(ImmutableMap.of("repair", totalMap,
-                "out", outMap, "byFee", byFee));
+                "out", outMap, "byFee", byMap));
     }
 
 

+ 126 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotReportOrderController.java

@@ -1,12 +1,16 @@
 package cn.iocoder.yudao.module.pms.controller.admin.stat;
 
 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.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotprojecttask.vo.IotProjectTaskPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotrddailyreport.vo.IotRdDailyReportPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportPageReqVO;
+import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.AllOrderResp;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
@@ -14,6 +18,9 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWorkOrderBomDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojecttask.IotProjectTaskDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotrddailyreport.IotRdDailyReportDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotrhdailyreport.IotRhDailyReportDO;
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotrydailyreport.IotRyDailyReportDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectOrderDeviceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectOrderMapper;
@@ -40,6 +47,9 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.security.PermitAll;
 import javax.validation.Valid;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
@@ -71,6 +81,8 @@ public class IotReportOrderController {
     @Operation(summary = "各工单状态数量统计")
     @GetMapping("/number")
     public CommonResult<ImmutableMap> getOrderStat(@Valid IotMaintainPageReqVO pageReqVO) {
+        LocalDateTime startTime = pageReqVO.getCreateTime()[0];
+        LocalDateTime endTime = pageReqVO.getCreateTime()[1];
         Set<Long> ids;
         if (Objects.isNull(pageReqVO.getDeptId())){
             Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
@@ -84,8 +96,25 @@ public class IotReportOrderController {
         List<AllOrderResp> maintains = iotMaintainMapper.selectStatusNumber(pageReqVO);
         List<AllOrderResp> inspects = iotInspectOrderMapper.selectStatusNumber(pageReqVO);
         List<AllOrderResp> operations = iotOpeationFillMapper.selectStatusNumber(pageReqVO);
+        // 保养
         List<AllOrderResp> workOrders = iotMainWorkOrderMapper.selectStatusNumber(pageReqVO);
+        // 保养工单总数量
+        Long byNum = 0l;
+        if (CollUtil.isNotEmpty(workOrders)) {
+            for (AllOrderResp order : workOrders) {
+                if (ObjUtil.isNotEmpty(order.getNum())) {
+                    byNum = byNum + order.getNum();
+                }
+            }
+        }
+        Long tbByNum = 0l;
+        Long hbByNum = 0l;
         // 日报
+        Long tbRbNum = 0l;
+        Long hbRbNum = 0l;
+        // 同比 去年同期相同统计数据对比 无数据
+        tbByNum = tbByNum == null ? 0l : tbByNum;
+
         List<AllOrderResp> dailyReports = iotRhDailyReportMapper.selectStatusNumber(pageReqVO);
         List<AllOrderResp> ryDailyReports = iotRyDailyReportMapper.selectStatusNumber(pageReqVO);
         List<AllOrderResp> rdDailyReports = iotRdDailyReportMapper.selectStatusNumber(pageReqVO);
@@ -121,12 +150,107 @@ public class IotReportOrderController {
         }
         AllOrderResp noReport = new AllOrderResp();
         noReport.setStatus("0");
-        noReport.setNum(Long.valueOf(noStatus.get()));
+        noReport.setNum(noStatus.get());
         reports.add(noReport);
         AllOrderResp yesReport = new AllOrderResp();
         yesReport.setStatus("1");
-        yesReport.setNum(Long.valueOf(yesStatus.get()));
+        yesReport.setNum(yesStatus.get());
         reports.add(yesReport);
+        // 当前日报总数量
+        Long rbNum = yesStatus.get() + noStatus.get();
+
+        if ("year".equals(pageReqVO.getTimeType())){
+            // 保养 年 无同比环比数据
+            hbByNum = hbByNum==null ? 0l : hbByNum;
+        }  else if ("month".equals(pageReqVO.getTimeType())){
+            LocalDateTime lastMonthStart = startTime.minusMonths(1);
+            LocalDateTime lastMonthEnd = endTime.minusMonths(1);
+            LocalDateTime[] monthTime = pageReqVO.getCreateTime();
+            monthTime[0] = lastMonthStart;
+            monthTime[1] = lastMonthEnd;
+            pageReqVO.setCreateTime(monthTime);
+            List<AllOrderResp> monthWorkOrders = iotMainWorkOrderMapper.selectStatusNumber(pageReqVO);
+            if (CollUtil.isNotEmpty(monthWorkOrders)) {
+                for (AllOrderResp order : monthWorkOrders) {
+                    if (ObjUtil.isNotEmpty(order.getNum())) {
+                        hbByNum = hbByNum + order.getNum();
+                    }
+                }
+            }
+            IotRhDailyReportPageReqVO reqVO = new IotRhDailyReportPageReqVO();
+            reqVO.setCreateTime(monthTime);
+            reqVO.setDeptIds(ids);
+            List<IotRhDailyReportDO> monthDailyReports = iotRhDailyReportMapper.dailyReports(reqVO);
+            if (CollUtil.isNotEmpty(monthDailyReports)) {
+                hbRbNum = hbRbNum + monthDailyReports.size();
+            }
+            IotRyDailyReportPageReqVO ryReqVO = new IotRyDailyReportPageReqVO();
+            ryReqVO.setCreateTime(monthTime);
+            ryReqVO.setDeptIds(ids);
+            List<IotRyDailyReportDO> monthRyDailyReports = iotRyDailyReportMapper.dailyReports(ryReqVO);
+            if (CollUtil.isNotEmpty(monthRyDailyReports)) {
+                hbRbNum = hbRbNum + monthRyDailyReports.size();
+            }
+            IotRdDailyReportPageReqVO rdReqVO = new IotRdDailyReportPageReqVO();
+            rdReqVO.setCreateTime(monthTime);
+            rdReqVO.setDeptIds(ids);
+            List<IotRdDailyReportDO> monthRdDailyReports = iotRdDailyReportMapper.dailyReports(rdReqVO);
+            if (CollUtil.isNotEmpty(monthRdDailyReports)) {
+                hbRbNum = hbRbNum + monthRdDailyReports.size();
+            }
+
+        }  else if ("day".equals(pageReqVO.getTimeType())){
+            LocalDateTime lastDayStart = startTime.minusDays(1);
+            LocalDateTime lastDayEnd = endTime.minusDays(1);
+            LocalDateTime[] dayTime = pageReqVO.getCreateTime();
+            dayTime[0] = lastDayStart;
+            dayTime[1] = lastDayEnd;
+            pageReqVO.setCreateTime(dayTime);
+            List<AllOrderResp> dayWorkOrders = iotMainWorkOrderMapper.selectStatusNumber(pageReqVO);
+            if (CollUtil.isNotEmpty(dayWorkOrders)) {
+                for (AllOrderResp order : dayWorkOrders) {
+                    if (ObjUtil.isNotEmpty(order.getNum())) {
+                        hbByNum = hbByNum + order.getNum();
+                    }
+                }
+            }
+            IotRhDailyReportPageReqVO reqVO = new IotRhDailyReportPageReqVO();
+            reqVO.setCreateTime(dayTime);
+            reqVO.setDeptIds(ids);
+            List<IotRhDailyReportDO> monthDailyReports = iotRhDailyReportMapper.dailyReports(reqVO);
+            if (CollUtil.isNotEmpty(monthDailyReports)) {
+                hbRbNum = hbRbNum + monthDailyReports.size();
+            }
+            IotRyDailyReportPageReqVO ryReqVO = new IotRyDailyReportPageReqVO();
+            ryReqVO.setCreateTime(dayTime);
+            ryReqVO.setDeptIds(ids);
+            List<IotRyDailyReportDO> monthRyDailyReports = iotRyDailyReportMapper.dailyReports(ryReqVO);
+            if (CollUtil.isNotEmpty(monthRyDailyReports)) {
+                hbRbNum = hbRbNum + monthRyDailyReports.size();
+            }
+            IotRdDailyReportPageReqVO rdReqVO = new IotRdDailyReportPageReqVO();
+            rdReqVO.setCreateTime(dayTime);
+            rdReqVO.setDeptIds(ids);
+            List<IotRdDailyReportDO> monthRdDailyReports = iotRdDailyReportMapper.dailyReports(rdReqVO);
+            if (CollUtil.isNotEmpty(monthRdDailyReports)) {
+                hbRbNum = hbRbNum + monthRdDailyReports.size();
+            }
+        }
+
+        Map<String, Object> byMap = new HashMap<>();
+        byMap.put("total", byNum);
+        byMap.put("hb", (hbByNum==null || hbByNum==0l) ? hbByNum :
+                ((new BigDecimal(byNum).subtract(new BigDecimal(hbByNum))).divide(new BigDecimal(hbByNum),2, RoundingMode.HALF_UP)));
+        byMap.put("tb", (tbByNum==null || tbByNum==0l) ? tbByNum :
+                ((new BigDecimal(byNum).subtract(new BigDecimal(tbByNum))).divide(new BigDecimal(tbByNum),2, RoundingMode.HALF_UP)));
+
+        Map<String, Object> rbMap = new HashMap<>();
+        rbMap.put("total", rbNum);
+        rbMap.put("hb", (hbRbNum==null || hbRbNum==0l) ? hbRbNum :
+                ((new BigDecimal(rbNum).subtract(new BigDecimal(hbRbNum))).divide(new BigDecimal(hbRbNum),2, RoundingMode.HALF_UP)));
+        rbMap.put("tb", (tbRbNum==null || tbRbNum==0l) ? tbRbNum :
+                ((new BigDecimal(rbNum).subtract(new BigDecimal(tbRbNum))).divide(new BigDecimal(tbRbNum),2, RoundingMode.HALF_UP)));
+
         return CommonResult.success(ImmutableMap.of("wx", maintains, "xj", inspects, "yx", operations, "by", workOrders, "rb", reports));
     }
 

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

@@ -904,6 +904,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         Map<Long, Integer> zddmTeamCountPair = new HashMap<>();
         // 队伍id 集合
         Set<Long> teamIds = new HashSet<>();
+        // key队伍id/项目部id   value非生产时间集合
+        Map<Long, List<BigDecimal>> cumulativeNonProductionTimePair = new HashMap<>();
+        // key队伍id/项目部id   value非生产时效
+        Map<Long, BigDecimal> cumulativeNonProductionPair = new HashMap<>();
 
         // 以项目部为维度统计数据
         // 找到所有项目部与队伍的对应关系
@@ -1011,6 +1015,19 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                             BigDecimal tempCapacity = teamCapacityPair.get(report.getDeptId());
                             cumulativeCapacityPair.merge(projectDeptId, tempCapacity, BigDecimal::add);
                         }
+                        // 非生产时间 用于计算非生产时效
+                        BigDecimal nonProductionTime = report.getNonProductionTime();
+                        if (nonProductionTime.compareTo(BigDecimal.ZERO) > 0) {
+                            if (cumulativeNonProductionTimePair.containsKey(projectDeptId)) {
+                                List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(projectDeptId);
+                                tempNonProductionTimes.add(nonProductionTime);
+                                cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
+                            } else {
+                                List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
+                                tempNonProductionTimes.add(nonProductionTime);
+                                cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
+                            }
+                        }
                     }
                 }
             });
@@ -1031,6 +1048,19 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             }
         }
 
+        if (CollUtil.isNotEmpty(cumulativeNonProductionTimePair)) {
+            // 计算各项目部的平均时效
+            cumulativeNonProductionTimePair.forEach((projectDeptId, nonProductTimes) -> {
+                // nonProductTimes 集合中元素的数量就是 分母中应该计算非生产时效的天数
+                BigDecimal totalNonProductionTime = nonProductTimes.stream()
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                BigDecimal denominator = new BigDecimal(nonProductTimes.size() * 24);
+                BigDecimal nonProductionEfficiency = totalNonProductionTime
+                        .divide(denominator, 4, RoundingMode.HALF_UP);
+                cumulativeNonProductionPair.put(projectDeptId, nonProductionEfficiency);
+            });
+        }
+
         // 生成返回的数据列表集合
         projectDeptPair.forEach((deptId, dept) -> {
             IotRhDailyReportStatisticsRespVO statistics = new IotRhDailyReportStatisticsRespVO();
@@ -1043,6 +1073,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(deptId));
             statistics.setCumulativeFuelConsumption(cumulativeOilConsumptionPair.get(deptId));
             statistics.setTransitTime(cumulativeTransitTimePair.get(deptId));
+            statistics.setNonProductiveTime(cumulativeNonProductionPair.get(deptId));
             // 队伍数量
             if (CollUtil.isNotEmpty(teamCountPair)) {
                 statistics.setTeamCount(teamCountPair.get(deptId));
@@ -1061,7 +1092,6 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             }
             result.add(statistics);
         });
-
         return result;
     }
 
@@ -1211,6 +1241,10 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         Map<Long, BigDecimal> cumulativeCapacityPair = new HashMap<>();
         // key队伍id/项目部id   value累计运行时效   累计注气量/累计产能
         Map<Long, BigDecimal> cumulativeTransitTimePair = new HashMap<>();
+        // key队伍id/项目部id   value非生产时间集合
+        Map<Long, List<BigDecimal>> cumulativeNonProductionTimePair = new HashMap<>();
+        // key队伍id/项目部id   value非生产时效
+        Map<Long, BigDecimal> cumulativeNonProductionPair = new HashMap<>();
 
         // 以 队伍 为维度统计数据
         // 找到所有项目部与队伍的对应关系
@@ -1250,6 +1284,19 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                         BigDecimal tempCapacity = teamCapacityPair.get(report.getDeptId());
                         cumulativeCapacityPair.merge(report.getDeptId(), tempCapacity, BigDecimal::add);
                     }
+                    // 非生产时效
+                    BigDecimal nonProductionTime = report.getNonProductionTime();
+                    if (nonProductionTime.compareTo(BigDecimal.ZERO) > 0) {
+                        if (cumulativeNonProductionTimePair.containsKey(report.getDeptId())) {
+                            List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(report.getDeptId());
+                            tempNonProductionTimes.add(nonProductionTime);
+                            cumulativeNonProductionTimePair.put(report.getDeptId(), tempNonProductionTimes);
+                        } else {
+                            List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
+                            tempNonProductionTimes.add(nonProductionTime);
+                            cumulativeNonProductionTimePair.put(report.getDeptId(), tempNonProductionTimes);
+                        }
+                    }
                 }
             });
             // 根据 累计注气量 累计产能 计算指定队伍下的平均产能
@@ -1265,6 +1312,18 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     }
                 });
             }
+            if (CollUtil.isNotEmpty(cumulativeNonProductionTimePair)) {
+                // 计算各队伍的 非生产时效
+                cumulativeNonProductionTimePair.forEach((teamId, nonProductTimes) -> {
+                    // nonProductTimes 集合中元素的数量就是 分母中应该计算非生产时效的天数
+                    BigDecimal totalNonProductionTime = nonProductTimes.stream()
+                            .reduce(BigDecimal.ZERO, BigDecimal::add);
+                    BigDecimal denominator = new BigDecimal(nonProductTimes.size() * 24);
+                    BigDecimal nonProductionEfficiency = totalNonProductionTime
+                            .divide(denominator, 4, RoundingMode.HALF_UP);
+                    cumulativeNonProductionPair.put(teamId, nonProductionEfficiency);
+                });
+            }
         }
 
         // 生成返回的数据列表集合
@@ -1279,6 +1338,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
             statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(teamDeptId));
             statistics.setCumulativeFuelConsumption(cumulativeOilConsumptionPair.get(teamDeptId));
             statistics.setTransitTime(cumulativeTransitTimePair.get(teamDeptId));
+            statistics.setNonProductiveTime(cumulativeNonProductionPair.get(teamDeptId));
             result.add(statistics);
         });
 

+ 64 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportServiceImpl.java

@@ -62,6 +62,7 @@ import java.util.*;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@@ -227,7 +228,9 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Long deptId = createReqVO.getDeptId();
         DataPermissionUtils.executeIgnore(() -> {
             DeptDO dept = deptService.getDept(deptId);
-            System.out.println("当前查询到的部门是NULL:" + deptId);
+            if (ObjUtil.isEmpty(dept)) {
+                System.out.println("当前查询到的部门是NULL:" + deptId);
+            }
             Long parentId = dept.getParentId();
             if (ObjUtil.isNotEmpty(parentId)) {
                 DeptDO projectDept = deptService.getDept(parentId);
@@ -1002,6 +1005,10 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Map<Long, BigDecimal> cumulativeRatedTimePair = new HashMap<>();
         // key队伍id/项目部id   value累计运行时效
         Map<Long, BigDecimal> cumulativeTransitTimePair = new HashMap<>();
+        // key队伍id/项目部id   value非生产时间集合
+        Map<Long, List<BigDecimal>> cumulativeNonProductionTimePair = new HashMap<>();
+        // key队伍id/项目部id   value非生产时效
+        Map<Long, BigDecimal> cumulativeNonProductionPair = new HashMap<>();
 
         // key部门id-任务id
         Set<String> deptTaskConstrcts = new HashSet<>();
@@ -1094,6 +1101,47 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
                         // 生产时间
                         cumulativeProductTimePair.merge(projectDeptId, report.getProductionTime(), BigDecimal::add);
                     }
+
+                    // 修井 非生产时间 用于计算非生产时效
+                    if ("2".equals(pageReqVO.getProjectClassification())) {
+                        BigDecimal nonProductionTime = report.getNonProductionTime();
+                        if (nonProductionTime.compareTo(BigDecimal.ZERO) > 0) {
+                            if (cumulativeNonProductionTimePair.containsKey(projectDeptId)) {
+                                List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(projectDeptId);
+                                tempNonProductionTimes.add(nonProductionTime);
+                                cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
+                            } else {
+                                List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
+                                tempNonProductionTimes.add(nonProductionTime);
+                                cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
+                            }
+                        }
+                    } else {
+                        // 钻井 非生产时间 事故 修理 自停 复杂 搬迁 整改 等停 冬休
+                        BigDecimal drillingNonProductionTimeSum = Stream.of(
+                                        report.getAccidentTime(),
+                                        report.getRepairTime(),
+                                        report.getSelfStopTime(),
+                                        report.getComplexityTime(),
+                                        report.getRelocationTime(),
+                                        report.getRectificationTime(),
+                                        report.getWaitingStopTime(),
+                                        report.getWinterBreakTime()
+                                )
+                                .map(time -> ObjUtil.defaultIfNull(time, BigDecimal.ZERO))
+                                .reduce(BigDecimal.ZERO, BigDecimal::add);
+                        if (drillingNonProductionTimeSum.compareTo(BigDecimal.ZERO) > 0) {
+                            if (cumulativeNonProductionTimePair.containsKey(projectDeptId)) {
+                                List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(projectDeptId);
+                                tempNonProductionTimes.add(drillingNonProductionTimeSum);
+                                cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
+                            } else {
+                                List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
+                                tempNonProductionTimes.add(drillingNonProductionTimeSum);
+                                cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
+                            }
+                        }
+                    }
                 }
             });
             // 筛选每个队伍对应的项目部 设置每个项目部的 累计施工井数 累计完工井数 totalTasksPair   completedTasksPair
@@ -1131,6 +1179,20 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
                     }
                 });
             }
+
+            if (CollUtil.isNotEmpty(cumulativeNonProductionTimePair)) {
+                // 计算各项目部的平均时效
+                cumulativeNonProductionTimePair.forEach((projectDeptId, nonProductTimes) -> {
+                    // nonProductTimes 集合中元素的数量就是 分母中应该计算非生产时效的天数
+                    BigDecimal totalNonProductionTime = nonProductTimes.stream()
+                            .reduce(BigDecimal.ZERO, BigDecimal::add);
+                    BigDecimal denominator = new BigDecimal(nonProductTimes.size() * 24);
+                    BigDecimal nonProductionEfficiency = totalNonProductionTime
+                            .divide(denominator, 4, RoundingMode.HALF_UP);
+                    cumulativeNonProductionPair.put(projectDeptId, nonProductionEfficiency);
+                });
+            }
+
         }
 
         // 生成返回的数据列表集合
@@ -1146,6 +1208,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             statistics.setCumulativePowerConsumption(cumulativePowerConsumptionPair.get(deptId));
             statistics.setCumulativeFuelConsumption(cumulativeFuelConsumptionPair.get(deptId));
             statistics.setTransitTime(cumulativeTransitTimePair.get(deptId));
+            statistics.setNonProductiveTime(cumulativeNonProductionPair.get(deptId));
             result.add(statistics);
         });