Quellcode durchsuchen

pms 修改保养计划 查询保养项 调整 多个累计公里/时长属性赋值逻辑

zhangcl vor 1 Woche
Ursprung
Commit
d6ef2f1a16

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

@@ -266,8 +266,10 @@ public class IotMaintenanceBomController {
                 }
             });
         }
-        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(convertListByFlatMap(BOMs,
-                bom -> Stream.of(bom.getDeviceId())));
+        // 查询正常的累计运行时长 公里数 时需要 携带 设备分类id 方便快速定位 累计属性值
+
+        Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMapAlone(convertListByFlatMap(BOMs,
+                bom -> Stream.of(bom.getDeviceId())), new ArrayList<>(deviceCategoryIds));
         // 2. 转换成 VO
         return BeanUtils.toBean(BOMs, IotMaintenanceBomRespVO.class, bomVO -> {
             // 设置设备相关信息

+ 2 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotdevicerunlog/IotDeviceRunLogMapper.java

@@ -47,7 +47,8 @@ public interface IotDeviceRunLogMapper extends BaseMapperX<IotDeviceRunLogDO> {
      * @param deviceIds
      * @return
      */
-    List<IotDeviceRunLogRespVO> distinctDevices(@Param("deviceIds") Collection<Long> deviceIds);
+    List<IotDeviceRunLogRespVO> distinctDevices(@Param("deviceIds") Collection<Long> deviceIds,
+                                                @Param("deviceCategoryIds") Collection<Long> deviceCategoryIds);
 
     /**
      * 查询指定设备 运行记录模板属性对应的累计时长 累计里程

+ 36 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogService.java

@@ -61,7 +61,7 @@ public interface IotDeviceRunLogService {
      *
      * @return 设备运行数据记录
      */
-    List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids);
+    List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds);
 
     /**
      * 查询指定设备 运行记录模板属性对应的累计时长 累计里程
@@ -77,7 +77,41 @@ public interface IotDeviceRunLogService {
      * @return 设备bom 关联 列表
      */
     default Map<Long, IotDeviceRunLogRespVO> getDeviceRunLogMap(List<Long> ids){
-        List<IotDeviceRunLogRespVO> list = distinctDevices(ids);
+        List<IotDeviceRunLogRespVO> list = distinctDevices(ids, null);
+        // 删除集合中的NULL元素
+        list.removeIf(deviceLog -> isAllFieldsNull(deviceLog));
+        // 暂时将查询出的2条记录设置为1条
+        // device_id	total_run_time	total_mileage	point_name				point_code
+        // 136			2444.00			0.00			台上发动机累计运转时长	    sc
+        // 136			0.00			16510.00		底盘发动机累计公里数	    gls
+        // 按 deviceId 分组并合并数据
+        Map<Long, IotDeviceRunLogRespVO> mergedMap = new HashMap<>();
+        for (IotDeviceRunLogRespVO log : list) {
+            Long deviceId = log.getDeviceId();
+            // 跳过无效设备ID
+            if (deviceId == null) continue;
+
+            if (mergedMap.containsKey(deviceId)) {
+                // 合并已有记录
+                IotDeviceRunLogRespVO existing = mergedMap.get(deviceId);
+                mergeLogRecords(existing, log);
+            } else {
+                // 首次遇到该设备ID,直接放入Map
+                mergedMap.put(deviceId, log);
+            }
+        }
+        List<IotDeviceRunLogRespVO> mergedList = new ArrayList<>(mergedMap.values());
+        return CollectionUtils.convertMap(mergedList, IotDeviceRunLogRespVO::getDeviceId);
+    }
+
+    /**
+     * 根据设备id查询设备关联信息
+     *
+     * @param ids 设备id集合
+     * @return 设备bom 关联 列表
+     */
+    default Map<Long, IotDeviceRunLogRespVO> getDeviceRunLogMapAlone(List<Long> ids, List<Long> deviceCategoryIds){
+        List<IotDeviceRunLogRespVO> list = distinctDevices(ids, deviceCategoryIds);
         // 删除集合中的NULL元素
         list.removeIf(deviceLog -> isAllFieldsNull(deviceLog));
         // 暂时将查询出的2条记录设置为1条

+ 2 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicerunlog/IotDeviceRunLogServiceImpl.java

@@ -73,8 +73,8 @@ public class IotDeviceRunLogServiceImpl implements IotDeviceRunLogService {
     }
 
     @Override
-    public List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids) {
-        return iotDeviceRunLogMapper.distinctDevices(ids);
+    public List<IotDeviceRunLogRespVO> distinctDevices(List<Long> ids, List<Long> deviceCategoryIds) {
+        return iotDeviceRunLogMapper.distinctDevices(ids, deviceCategoryIds);
     }
 
     @Override

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotDeviceRunLogMapper.xml

@@ -25,6 +25,12 @@
             </foreach>
         </if>
         AND (mta.`code` = 'sc' OR mta.`code` = 'gls')
+        <if test="deviceCategoryIds != null and deviceCategoryIds.size &gt; 0">
+            AND mta.device_category_id IN
+            <foreach collection="deviceCategoryIds" index="index" item="key" open="(" separator="," close=")">
+                #{key}
+            </foreach>
+        </if>
         GROUP BY drl.device_id, mta.`code`
     </select>