Browse Source

pms 瑞恒 瑞鹰 非生产时效逻辑优化

zhangcl 7 hours ago
parent
commit
607d2bcef0

+ 22 - 31
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotrydailyreport/IotRyDailyReportMapper.java

@@ -164,40 +164,31 @@ public interface IotRyDailyReportMapper extends BaseMapperX<IotRyDailyReportDO>
                     .eq(IotRyDailyReportDO::getProjectClassification, "1")
                     .or().eq(IotRyDailyReportDO::getProjectClassification, "")
             );
-            // 查询非生产时效
-            if ("Y".equals(reqVO.getNonProductFlag())) {
-                queryWrapper.and(wrapper -> wrapper
-                        .gt(IotRyDailyReportDO::getAccidentTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getRepairTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getSelfStopTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getComplexityTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getRelocationTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getRectificationTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getWaitingStopTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getWinterBreakTime, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getPartyaDesign, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getPartyaPrepare, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getPartyaResource, BigDecimal.ZERO)
-                        .or()
-                        .gt(IotRyDailyReportDO::getOtherNptTime, BigDecimal.ZERO)
-                );
-            }
         } else {
             // 其他情况:有值则精确匹配,无值则不添加条件(保持原逻辑) 修井
             queryWrapper.eqIfPresent(IotRyDailyReportDO::getProjectClassification, projectClassification);
-            if ("Y".equals(reqVO.getNonProductFlag())) {
-                queryWrapper.and(wrapper -> wrapper.gt(IotRyDailyReportDO::getNonProductionTime, BigDecimal.ZERO));
-            }
+        }
+        // 查询非生产时效
+        if ("Y".equals(reqVO.getNonProductFlag())) {
+            queryWrapper.and(wrapper -> wrapper
+                    .gt(IotRyDailyReportDO::getAccidentTime, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getRepairTime, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getComplexityTime, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getRectificationTime, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getWaitingStopTime, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getPartyaDesign, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getPartyaPrepare, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getPartyaResource, BigDecimal.ZERO)
+                    .or()
+                    .gt(IotRyDailyReportDO::getOtherNptTime, BigDecimal.ZERO)
+            );
         }
 
         return selectPage(reqVO, queryWrapper);

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

@@ -75,6 +75,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 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.module.pms.enums.ErrorCodeConstant.*;
@@ -1185,15 +1186,31 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                             cumulativeCapacityPair.merge(projectDeptId, tempCapacity, BigDecimal::add);
                         }
                         // 非生产时间 用于计算非生产时效
-                        BigDecimal nonProductionTime = report.getNonProductionTime();
-                        if (nonProductionTime.compareTo(BigDecimal.ZERO) > 0) {
+                        // NPT 归类 设备故障repair_time 工程质量accident_time 技术受限complexity_time 生产组织rectification_time 不可抗力waiting_stop_time
+                        // 甲方设计partya_design 甲方准备partya_prepare 甲方资源partya_resource 其他非生产时间other_npt_time
+                        // BigDecimal nonProductionTime = report.getNonProductionTime();
+                        BigDecimal nonProductionTimeSum = Stream.of(
+                                        report.getAccidentTime(),
+                                        report.getRepairTime(),
+                                        report.getComplexityTime(),
+                                        report.getRectificationTime(),
+                                        report.getWaitingStopTime(),
+                                        report.getPartyaDesign(),
+                                        report.getPartyaPrepare(),
+                                        report.getPartyaResource(),
+                                        report.getOtherNptTime()
+                                )
+                                .map(time -> ObjUtil.defaultIfNull(time, BigDecimal.ZERO))
+                                .reduce(BigDecimal.ZERO, BigDecimal::add);
+                        // BigDecimal nonProductionTime = report.getNonProductionTime();
+                        if (nonProductionTimeSum.compareTo(BigDecimal.ZERO) > 0) {
                             if (cumulativeNonProductionTimePair.containsKey(projectDeptId)) {
                                 List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(projectDeptId);
-                                tempNonProductionTimes.add(nonProductionTime);
+                                tempNonProductionTimes.add(nonProductionTimeSum);
                                 cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
                             } else {
                                 List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
-                                tempNonProductionTimes.add(nonProductionTime);
+                                tempNonProductionTimes.add(nonProductionTimeSum);
                                 cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
                             }
                         }
@@ -1238,15 +1255,18 @@ 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);
+                if (CollUtil.isNotEmpty(daysCounts) && projectTeamPair.containsKey(projectDeptId)) {
+                    Set<Long> tempTeamIds = projectTeamPair.get(projectDeptId);
+                    BigDecimal denominator = new BigDecimal(daysCounts.get(0) * 24 * tempTeamIds.size());
+                    BigDecimal nonProductionEfficiency = totalNonProductionTime
+                            .divide(denominator, 4, RoundingMode.HALF_UP);
+                    cumulativeNonProductionPair.put(projectDeptId, nonProductionEfficiency);
+                }
             });
         }
 
@@ -1526,15 +1546,30 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                         cumulativeCapacityPair.merge(report.getDeptId(), tempCapacity, BigDecimal::add);
                     }
                     // 非生产时效
-                    BigDecimal nonProductionTime = report.getNonProductionTime();
-                    if (nonProductionTime.compareTo(BigDecimal.ZERO) > 0) {
+                    // NPT 归类 设备故障repair_time 工程质量accident_time 技术受限complexity_time 生产组织rectification_time 不可抗力waiting_stop_time
+                    // 甲方设计partya_design 甲方准备partya_prepare 甲方资源partya_resource 其他非生产时间other_npt_time
+                    // BigDecimal nonProductionTime = report.getNonProductionTime();
+                    BigDecimal nonProductionTimeSum = Stream.of(
+                                    report.getAccidentTime(),
+                                    report.getRepairTime(),
+                                    report.getComplexityTime(),
+                                    report.getRectificationTime(),
+                                    report.getWaitingStopTime(),
+                                    report.getPartyaDesign(),
+                                    report.getPartyaPrepare(),
+                                    report.getPartyaResource(),
+                                    report.getOtherNptTime()
+                            )
+                            .map(time -> ObjUtil.defaultIfNull(time, BigDecimal.ZERO))
+                            .reduce(BigDecimal.ZERO, BigDecimal::add);
+                    if (nonProductionTimeSum.compareTo(BigDecimal.ZERO) > 0) {
                         if (cumulativeNonProductionTimePair.containsKey(report.getDeptId())) {
                             List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(report.getDeptId());
-                            tempNonProductionTimes.add(nonProductionTime);
+                            tempNonProductionTimes.add(nonProductionTimeSum);
                             cumulativeNonProductionTimePair.put(report.getDeptId(), tempNonProductionTimes);
                         } else {
                             List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
-                            tempNonProductionTimes.add(nonProductionTime);
+                            tempNonProductionTimes.add(nonProductionTimeSum);
                             cumulativeNonProductionTimePair.put(report.getDeptId(), tempNonProductionTimes);
                         }
                     }
@@ -1559,10 +1594,12 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                     // 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);
+                    if (CollUtil.isNotEmpty(daysCounts)) {
+                        BigDecimal denominator = new BigDecimal(daysCounts.get(0) * 24);
+                        BigDecimal nonProductionEfficiency = totalNonProductionTime
+                                .divide(denominator, 4, RoundingMode.HALF_UP);
+                        cumulativeNonProductionPair.put(teamId, nonProductionEfficiency);
+                    }
                 });
             }
 

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

@@ -1170,41 +1170,45 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
                     }
 
                     // 修井 非生产时间 用于计算非生产时效
+                    // NPT 归类 设备故障repair_time 工程质量accident_time 技术受限complexity_time 生产组织rectification_time 不可抗力waiting_stop_time
+                    // 甲方设计partya_design 甲方准备partya_prepare 甲方资源partya_resource 其他非生产时间other_npt_time
+                    // 钻井 非生产时间 事故 修理 自停 复杂 搬迁 整改 等停 冬休
+                    BigDecimal nonProductionTimeSum = Stream.of(
+                                    report.getAccidentTime(),
+                                    report.getRepairTime(),
+                                    report.getComplexityTime(),
+                                    report.getRectificationTime(),
+                                    report.getWaitingStopTime(),
+                                    report.getPartyaDesign(),
+                                    report.getPartyaPrepare(),
+                                    report.getPartyaResource(),
+                                    report.getOtherNptTime()
+                            )
+                            .map(time -> ObjUtil.defaultIfNull(time, BigDecimal.ZERO))
+                            .reduce(BigDecimal.ZERO, BigDecimal::add);
                     if ("2".equals(pageReqVO.getProjectClassification())) {
-                        BigDecimal nonProductionTime = report.getNonProductionTime();
-                        if (nonProductionTime.compareTo(BigDecimal.ZERO) > 0) {
+                        // BigDecimal nonProductionTime = report.getNonProductionTime();
+                        if (nonProductionTimeSum.compareTo(BigDecimal.ZERO) > 0) {
                             if (cumulativeNonProductionTimePair.containsKey(projectDeptId)) {
                                 List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(projectDeptId);
-                                tempNonProductionTimes.add(nonProductionTime);
+                                tempNonProductionTimes.add(nonProductionTimeSum);
                                 cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
                             } else {
                                 List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
-                                tempNonProductionTimes.add(nonProductionTime);
+                                tempNonProductionTimes.add(nonProductionTimeSum);
                                 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 (nonProductionTimeSum.compareTo(BigDecimal.ZERO) > 0) {
                             if (cumulativeNonProductionTimePair.containsKey(projectDeptId)) {
                                 List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(projectDeptId);
-                                tempNonProductionTimes.add(drillingNonProductionTimeSum);
+                                tempNonProductionTimes.add(nonProductionTimeSum);
                                 cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
                             } else {
                                 List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
-                                tempNonProductionTimes.add(drillingNonProductionTimeSum);
+                                tempNonProductionTimes.add(nonProductionTimeSum);
                                 cumulativeNonProductionTimePair.put(projectDeptId, tempNonProductionTimes);
                             }
                         }
@@ -1246,19 +1250,6 @@ 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);
-                });
-            }
         }
 
         Long days;
@@ -1276,6 +1267,22 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             days = 0l;
         }
 
+        if (CollUtil.isNotEmpty(cumulativeNonProductionTimePair)) {
+            // 计算各项目部的非生产时效 分母为查询时间区间的总天数
+            cumulativeNonProductionTimePair.forEach((projectDeptId, nonProductTimes) -> {
+                // nonProductTimes 集合中元素的数量就是 分母中应该计算非生产时效的天数
+                BigDecimal totalNonProductionTime = nonProductTimes.stream()
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                if (days > 0 && projectTeamPair.containsKey(projectDeptId)) {
+                    Set<Long> tempTeamIds = projectTeamPair.get(projectDeptId);
+                    BigDecimal denominator = new BigDecimal(days * 24 * tempTeamIds.size());
+                    BigDecimal nonProductionEfficiency = totalNonProductionTime
+                            .divide(denominator, 4, RoundingMode.HALF_UP);
+                    cumulativeNonProductionPair.put(projectDeptId, nonProductionEfficiency);
+                }
+            });
+        }
+
         // 计算各项目部的平均设备利用率
         if (CollUtil.isNotEmpty(projectTeamPair)) {
             projectTeamPair.forEach((projectDeptId, resultTeamIds) -> {
@@ -1559,6 +1566,10 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Map<Long, BigDecimal> cumulativeRatedTimePair = new HashMap<>();
         // key队伍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   value设备利用率
         Map<Long, BigDecimal> deviceUtilizationPair = new HashMap<>();
 
@@ -1674,9 +1685,36 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
                     }
                     // 生产时间
                     cumulativeProductTimePair.merge(report.getDeptId(), report.getProductionTime(), BigDecimal::add);
+                    // NPT 归类 设备故障repair_time 工程质量accident_time 技术受限complexity_time 生产组织rectification_time 不可抗力waiting_stop_time
+                    // 甲方设计partya_design 甲方准备partya_prepare 甲方资源partya_resource 其他非生产时间other_npt_time
+                    // BigDecimal nonProductionTime = report.getNonProductionTime();
+                    BigDecimal nonProductionTimeSum = Stream.of(
+                                    report.getAccidentTime(),
+                                    report.getRepairTime(),
+                                    report.getComplexityTime(),
+                                    report.getRectificationTime(),
+                                    report.getWaitingStopTime(),
+                                    report.getPartyaDesign(),
+                                    report.getPartyaPrepare(),
+                                    report.getPartyaResource(),
+                                    report.getOtherNptTime()
+                            )
+                            .map(time -> ObjUtil.defaultIfNull(time, BigDecimal.ZERO))
+                            .reduce(BigDecimal.ZERO, BigDecimal::add);
+                    if (nonProductionTimeSum.compareTo(BigDecimal.ZERO) > 0) {
+                        if (cumulativeNonProductionTimePair.containsKey(report.getDeptId())) {
+                            List<BigDecimal> tempNonProductionTimes = cumulativeNonProductionTimePair.get(report.getDeptId());
+                            tempNonProductionTimes.add(nonProductionTimeSum);
+                            cumulativeNonProductionTimePair.put(report.getDeptId(), tempNonProductionTimes);
+                        } else {
+                            List<BigDecimal> tempNonProductionTimes = new ArrayList<>();
+                            tempNonProductionTimes.add(nonProductionTimeSum);
+                            cumulativeNonProductionTimePair.put(report.getDeptId(), tempNonProductionTimes);
+                        }
+                    }
                 }
             });
-            // 根据 累计注气量 累计产能 计算指定队伍下的平均产能
+            // 根据 计算指定队伍下的平均产能
             if (CollUtil.isNotEmpty(cumulativeProductTimePair) && CollUtil.isNotEmpty(cumulativeRatedTimePair)) {
                 cumulativeProductTimePair.forEach((teamDeptId, productionTime) -> {
                     if (cumulativeRatedTimePair.containsKey(teamDeptId)) {
@@ -1706,6 +1744,21 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             days = 0l;
         }
 
+        if (CollUtil.isNotEmpty(cumulativeNonProductionTimePair)) {
+            // 计算各队伍的 非生产时效
+            cumulativeNonProductionTimePair.forEach((teamId, nonProductTimes) -> {
+                // nonProductTimes 集合中元素的数量就是 分母中应该计算非生产时效的天数
+                BigDecimal totalNonProductionTime = nonProductTimes.stream()
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                if (days > 0) {
+                    BigDecimal denominator = new BigDecimal(days * 24);
+                    BigDecimal nonProductionEfficiency = totalNonProductionTime
+                            .divide(denominator, 4, RoundingMode.HALF_UP);
+                    cumulativeNonProductionPair.put(teamId, nonProductionEfficiency);
+                }
+            });
+        }
+
         // 计算各队伍的平均设备利用率
         if (CollUtil.isNotEmpty(teamReportPair)) {
             teamReportPair.forEach((teamDeptId, reportCount) -> {
@@ -1729,6 +1782,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             statistics.setTeamName(dept.getName());
             statistics.setSort(dept.getSort());
             statistics.setType("3");
+            statistics.setNonProductiveTime(cumulativeNonProductionPair.get(teamDeptId));
             statistics.setUtilizationRate(deviceUtilizationPair.get(teamDeptId));
             statistics.setCumulativeFootage(cumulativeFootagePair.get(teamDeptId));
             statistics.setCumulativeConstructWells(totalTasksPair.get(teamDeptId));

+ 3 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/iotprojecttask/IotRhDailyReportMapper.xml

@@ -195,7 +195,9 @@
             </foreach>
         </if>
         <if test='reqVO.nonProductFlag != null and reqVO.nonProductFlag == "Y"'>
-            AND rdr.non_production_time &gt; 0
+            AND (rdr.accident_time &gt; 0 OR rdr.repair_time &gt; 0 OR rdr.complexity_time &gt; 0 OR rdr.rectification_time &gt; 0
+                     OR rdr.waiting_stop_time &gt; 0 OR rdr.partya_design &gt; 0 OR rdr.partya_prepare &gt; 0
+                     OR rdr.partya_resource &gt; 0 OR rdr.other_npt_time &gt; 0)
         </if>
         <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
             <!-- 处理“开始时间”(数组第1位,如 createTime[0] = 2024-01-01 00:00:00) -->