Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

lipenghui 1 hónapja
szülő
commit
8dc7c2cc31

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmaintenancebom/IotMaintenanceBomController.java

@@ -194,6 +194,7 @@ public class IotMaintenanceBomController {
         Map<Long, List<IotDeviceRunLogRespVO>> deviceRunLogPair = new HashMap<>();
         // key(设备id-累计时长属性名称)    value时长属性累计时长数值
         Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
+        // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         // key(设备id-累计公里数属性名称)    value公里数属性累计公里数值
         Map<String, BigDecimal> tempTotalMileagePair = new HashMap<>();

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotopeationfill/IotOpeationFillController.java

@@ -95,6 +95,7 @@ public class IotOpeationFillController {
         dailyToTotalMap.put("当日注气量", "累计注气量");
         dailyToTotalMap.put("当日公里数", "累计公里数");
         dailyToTotalMap.put("当日用电量", "累计用电量");
+        dailyToTotalMap.put("当日注水量", "累计注水量");
         //泵车
         dailyToTotalMap.put("发动机累计公里数填报", "发动机累计公里数");
         dailyToTotalMap.put("变速箱累计公里数填报", "变速箱累计公里数");

+ 56 - 20
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/mainworkorder/CreateMainWorkOrderJob.java

@@ -42,7 +42,6 @@ import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -91,9 +90,18 @@ public class CreateMainWorkOrderJob implements JobHandler {
             return "没有待保养项";
         }
         List<Long> deviceIds = new ArrayList<>();
+        // 运行记录模板中 多种 累计时长 公里数 属性名称集合
+        Set<String> boundedMultiAttrNames = new HashSet<>();
         mainBomList.forEach(bom -> {
             // 查询保养计划明细中所有设备id
             deviceIds.add(bom.getDeviceId());
+            // 查询保养计划明细已经绑定的 多种 累计时长 公里数 属性名称
+            if (StrUtil.isNotBlank(bom.getCode())) {
+                boundedMultiAttrNames.add(bom.getCode());
+            }
+            if (StrUtil.isNotBlank(bom.getType())) {
+                boundedMultiAttrNames.add(bom.getType());
+            }
         });
         if (CollUtil.isEmpty(deviceIds)) {
             return "没有设备信息";
@@ -116,6 +124,20 @@ public class CreateMainWorkOrderJob implements JobHandler {
         }
         // 查询所有设备名称 设备编码集合
         Map<Long, IotDeviceRespVO> devices = iotDeviceService.getDeviceMap(deviceIds);
+        // 查询 保养计划保养明细中已经绑定的 多种累计时长 公里数 属性集合
+        List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
+        if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+        }
+        // key(设备id-累计时长属性名称)    value时长属性累计时长数值
+        Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
+        if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
+            multipleAccumulatedData.forEach(data -> {
+                String uniqueKey = StrUtil.join("-", data.getDeviceId(), data.getPointName());
+                tempTotalRunDataPair.put(uniqueKey, data.getTotalRunTime());
+            });
+        }
+
         // 查询保养计划明细中所有设备的累计运行里程、累计运行时间
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(mainBomList,
                 bom -> Stream.of(bom.getDeviceId())));
@@ -130,30 +152,44 @@ public class CreateMainWorkOrderJob implements JobHandler {
             boolean runningKiloArrive = false;
             boolean naturalDateArrive = false;
             // 只有维护了累计运行时间、累计运行里程 运行记录的设备才能触发 里程周期 时间周期 保养规则
+            BigDecimal totalRunTime = BigDecimal.ZERO;
+            BigDecimal totalMileage = BigDecimal.ZERO;
             if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
-                BigDecimal totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
-                BigDecimal totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
-                if (0 == bom.getRunningTimeRule()) {
-                    // 累计运行时间规则   累计运行时间 >= (上次保养运行时间+运行时间周期-提前量)
-                    BigDecimal lastRunningTime = bom.getLastRunningTime();      // 上次保养运行时间
-                    BigDecimal runningTimePeriod = bom.getNextRunningTime();    // 运行时间周期
-                    BigDecimal timePeriodLead = bom.getTimePeriodLead();        // 运行时间周期提前量
-                    if (((runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime))).subtract(timePeriodLead)).compareTo(BigDecimal.ZERO) <= 0) {
-                        runningTimeArrive = true;
-                    }
+                // 正常的累计时长 公里数
+                totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
+                totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
+            } else {
+                // 保养项绑定的 累计时长 类型的属性值
+                String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getCode());
+                if (tempTotalRunDataPair.containsKey(uniqueKey)) {
+                    totalRunTime = tempTotalRunDataPair.get(uniqueKey);
                 }
-                if (0 == bom.getMileageRule()) {
-                    // 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
-                    BigDecimal lastRunningKilo = bom.getLastRunningKilometers();      // 上次保养运行里程
-                    BigDecimal runningKiloPeriod = bom.getNextRunningKilometers();    // 运行里程周期
-                    BigDecimal kiloCycleLead = bom.getKiloCycleLead();                // 运行里程周期提前量
-                    if (((runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo))).subtract(kiloCycleLead)).compareTo(BigDecimal.ZERO) <= 0) {
-                        runningTimeArrive = true;
-                    }
+                // 保养项绑定的 累计公里数类型的属性值
+                String uniqueKeyType = StrUtil.join("-", bom.getDeviceId(), bom.getType());
+                if (tempTotalRunDataPair.containsKey(uniqueKeyType)) {
+                    totalMileage = tempTotalRunDataPair.get(uniqueKeyType);
+                }
+            }
+            if (ObjUtil.isNotEmpty(bom.getRunningTimeRule()) && 0 == bom.getRunningTimeRule()) {
+                // 累计运行时间规则   累计运行时间 >= (上次保养运行时间+运行时间周期-提前量)
+                BigDecimal lastRunningTime = bom.getLastRunningTime();      // 上次保养运行时间
+                BigDecimal runningTimePeriod = bom.getNextRunningTime();    // 运行时间周期
+                BigDecimal timePeriodLead = bom.getTimePeriodLead();        // 运行时间周期提前量
+                if (((runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime))).subtract(timePeriodLead)).compareTo(BigDecimal.ZERO) <= 0) {
+                    runningTimeArrive = true;
+                }
+            }
+            if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0 == bom.getMileageRule()) {
+                // 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
+                BigDecimal lastRunningKilo = bom.getLastRunningKilometers();      // 上次保养运行里程
+                BigDecimal runningKiloPeriod = bom.getNextRunningKilometers();    // 运行里程周期
+                BigDecimal kiloCycleLead = bom.getKiloCycleLead();                // 运行里程周期提前量
+                if (((runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo))).subtract(kiloCycleLead)).compareTo(BigDecimal.ZERO) <= 0) {
+                    runningTimeArrive = true;
                 }
             }
             // 没有维护 累计运行时间、累计运行里程 运行记录的设备 可以触发 自然日周期 保养规则
-            if (0 == bom.getNaturalDateRule()) {
+            if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0 == bom.getNaturalDateRule()) {
                 // 自然日期规则  当前日期 >= (上次保养自然日期+自然日周期-提前量)
                 LocalDateTime lastNaturalDate = bom.getLastNaturalDate();      // 上次保养自然日期
                 BigDecimal naturalDatePeriod = bom.getNextNaturalDate();       // 自然日周期

+ 50 - 13
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java

@@ -177,6 +177,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         } else {
             mainBomS = iotMaintenanceBomMapper.selectList(mainBomReqVO);
         }
+        Set<String> boundedMultiAttrNames = new HashSet<>();
         if (CollUtil.isNotEmpty(mainBomS)) {
             mainBomDeviceIds = CollUtil.isEmpty(mainBomS)
                     ? Collections.emptySet()
@@ -184,14 +185,38 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                     .map(IotMaintenanceBomDO::getDeviceId) // 获取 deviceId
                     .filter(Objects::nonNull)      // 过滤非空值
                     .collect(Collectors.toSet());  // 收集到 Set 中
+            // 查询所有保养计划 保养项 中已经绑定的 多个累计时长 公里数 属性名称值
+            mainBomS.forEach(bom -> {
+                if (StrUtil.isNotBlank(bom.getType())) {
+                    // 累计公里数属性
+                    boundedMultiAttrNames.add(bom.getType());
+                }
+                if (StrUtil.isNotBlank(bom.getCode())) {
+                    // 累计时长属性
+                    boundedMultiAttrNames.add(bom.getCode());
+                }
+            });
         }
         deviceIds.addAll(mainBomDeviceIds);
         if (CollUtil.isEmpty(deviceIds)){
             // 没有设备信息,返回空列表
             return PageResult.empty();
         }
+        // 查询 运行记录模板中包含多个累计 时长 公里数 属性的集合
+        List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
+        if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
+            multipleAccumulatedData = iotDeviceRunLogService.multipleAccumulatedData(deviceIds, boundedMultiAttrNames);
+        }
+        // key(设备id-累计时长属性名称)    value时长属性累计时长数值
+        Map<String, BigDecimal> tempTotalRunDataPair = new HashMap<>();
+        if (CollUtil.isNotEmpty(multipleAccumulatedData)) {
+            multipleAccumulatedData.forEach(data -> {
+                String uniqueKey = StrUtil.join("-", data.getDeviceId(), data.getPointName());
+                tempTotalRunDataPair.put(uniqueKey, data.getTotalRunTime());
+            });
+        }
 
-        // 如果没有待执行的保养工单,
+        // 查询 运行记录模板中 正常的累计时长 公里数集合
         Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
         // 以设备为维度统计每个设备相关的保养项的最近保养距离 key设备id    value设备下每个保养项的的最小保养距离集合
         Map<Long, List<Map<String, Object>>> orderDistancePair = new HashMap<>();
@@ -206,25 +231,37 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                 // 计算每个保养项 每个保养规则下的 距离保养时间 单位 小时
                 if (ObjUtil.isNotEmpty(bom.getRunningTimeRule()) && 0 == bom.getRunningTimeRule()) {
                     // 运行时间保养规则
+                    BigDecimal totalRunTime = BigDecimal.ZERO;
                     if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
-                        BigDecimal totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
-                        BigDecimal lastRunningTime = bom.getLastRunningTime();      // 上次保养运行时间
-                        BigDecimal runningTimePeriod = bom.getNextRunningTime();    // 运行时间周期
-                        BigDecimal timePeriodLead = bom.getTimePeriodLead();    // 运行时间周期提前量
-                        // runningTimeDistance = (lastRunningTime.add(runningTimePeriod).subtract(timePeriodLead)).subtract(totalRunTime);
-                        runningTimeDistance = runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime));
+                        totalRunTime = deviceRunLogMap.get(bom.getDeviceId()).getTotalRunTime();
+                    } else {
+                        // 运行记录模板中包含多个累计时长 公里数类型的属性
+                        String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getCode());
+                        if (tempTotalRunDataPair.containsKey(uniqueKey)) {
+                            totalRunTime = tempTotalRunDataPair.get(uniqueKey);
+                        }
                     }
+                    BigDecimal lastRunningTime = bom.getLastRunningTime();      // 上次保养运行时间
+                    BigDecimal runningTimePeriod = bom.getNextRunningTime();    // 运行时间周期
+                    BigDecimal timePeriodLead = bom.getTimePeriodLead();    // 运行时间周期提前量
+                    runningTimeDistance = runningTimePeriod.subtract(totalRunTime.subtract(lastRunningTime));
                 }
                 if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0 == bom.getMileageRule()) {
                     // 运行里程保养规则 累计运行里程规则 累计运行里程 >= (上次保养运行里程+运行里程周期-提前量)
+                    BigDecimal totalMileage = BigDecimal.ZERO;
                     if (deviceRunLogMap.containsKey(bom.getDeviceId())) {
-                        BigDecimal totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
-                        BigDecimal lastRunningKilo = bom.getLastRunningKilometers();      // 上次保养运行里程
-                        BigDecimal runningKiloPeriod = bom.getNextRunningKilometers();    // 运行里程周期
-                        BigDecimal kiloCycleLead = bom.getKiloCycleLead();    // 运行里程周期提前量
-                        // runningKiloDistance = (lastRunningKilo.add(runningKiloPeriod).subtract(kiloCycleLead)).subtract(totalMileage);
-                        runningKiloDistance = runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo));
+                        totalMileage = deviceRunLogMap.get(bom.getDeviceId()).getTotalMileage();
+                    } else {
+                        // 运行记录模板中包含多个累计时长 公里数类型的属性
+                        String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getType());
+                        if (tempTotalRunDataPair.containsKey(uniqueKey)) {
+                            totalMileage = tempTotalRunDataPair.get(uniqueKey);
+                        }
                     }
+                    BigDecimal lastRunningKilo = bom.getLastRunningKilometers();      // 上次保养运行里程
+                    BigDecimal runningKiloPeriod = bom.getNextRunningKilometers();    // 运行里程周期
+                    BigDecimal kiloCycleLead = bom.getKiloCycleLead();    // 运行里程周期提前量
+                    runningKiloDistance = runningKiloPeriod.subtract(totalMileage.subtract(lastRunningKilo));
                 }
                 if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0 == bom.getNaturalDateRule()) {
                     // 自然日期保养规则

+ 43 - 21
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotOpeationFillMapper.xml

@@ -647,37 +647,59 @@
         -- 统计指定部门及其子部门的工单状态
         -- 第一行:汇总数据
         SELECT
-            COUNT(a.id) AS total_count,
-            SUM(CASE WHEN a.is_fill = 1 THEN 1 ELSE 0 END) AS filled_count,
-            COUNT(a.id) - SUM(CASE WHEN a.is_fill = 1 THEN 1 ELSE 0 END) AS unfilled_count
+        COUNT(*) AS total_count,
+        SUM(CASE WHEN is_fill = 1 THEN 1 ELSE 0 END) AS filled_count,
+        COUNT(*) - SUM(CASE WHEN is_fill = 1 THEN 1 ELSE 0 END) AS unfilled_count
+        from(
+        select
+        distinct
+        a.device_code,
+        a.device_name,
+        a.create_time,
+        b.name dept_name,
+        a.is_fill,
+        d.nickname,
+        e.order_name
         FROM rq_iot_opeation_fill a
+        LEFT JOIN system_dept b
+        ON a.dept_id = b.id
+        AND b.deleted = 0 -- 将删除检查移至JOIN条件
+        LEFT JOIN rq_iot_device_person c
+        ON a.device_id = c.device_id
+        AND c.deleted = 0 -- 将删除检查移至JOIN条件
+        LEFT JOIN system_users d
+        ON c.person_id = d.id
+        AND d.deleted = 0 -- 将删除检查移至JOIN条件
+        LEFT JOIN rq_iot_opeation_fill_order e
+        ON a.order_id = e.id
+        and e.deleted = 0
         WHERE a.deleted = 0
-          AND EXISTS (
-                SELECT 1 FROM system_dept b
-                WHERE a.dept_id = b.id
-                  AND b.deleted = 0
-                  AND (b.id = #{deptId} OR b.parent_id = #{deptId}
-                    OR b.parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})
-                    OR b.parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId}))
-                    OR b.parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})))
-                    )
-            )
-          AND EXISTS (
-                SELECT 1 FROM rq_iot_opeation_fill_order e
-                WHERE a.order_id = e.id
-                  AND e.deleted = 0
-                  AND e.order_name IS NOT NULL
-            )
+        and e.order_name is not null
+        AND b.id IN (
+        SELECT id FROM system_dept WHERE id = #{deptId}
+        UNION ALL
+        SELECT id FROM system_dept WHERE parent_id = #{deptId}
+        UNION ALL
+        SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})
+        UNION ALL
+        SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM
+        system_dept WHERE parent_id = #{deptId}))
+        UNION ALL
+        SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id IN (SELECT id FROM
+        system_dept WHERE parent_id IN (SELECT id FROM system_dept WHERE parent_id = #{deptId})))
+        )
         <if test="createTime != null and createTime.length > 0">
             <choose>
                 <when test="createTime.length == 1">
                     AND a.create_time = #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
                 </when>
                 <otherwise>
-                    AND a.create_time BETWEEN #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
+                    AND a.create_time BETWEEN
+                    #{createTime[0],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} AND
+                    #{createTime[1],typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler}
                 </otherwise>
             </choose>
-        </if>
+        </if>) a
     </select>
 
 </mapper>