Browse Source

相机截图开发

gao.qiang 3 tuần trước cách đây
mục cha
commit
400f9d03cc

+ 51 - 44
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -242,56 +242,63 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
 
     @Override
     public AjaxResult alarmStatistics(MsgAlarmVo msgAlarmVo1) {
-        int count = 0;
-        int unresolvedCount = 0;
-        //找出所有报警数据
+        // 查询所有报警数据
         List<MsgAlarm> list = msgAlarmMapper.selectMsgAlarmList(msgAlarmVo1);
-        //未解除的报警
+
+        // 查询未解除的报警数据
         msgAlarmVo1.setIsLock(2);
         List<MsgAlarm> alarmList = msgAlarmMapper.selectMsgAlarmList(msgAlarmVo1);
+
         HashMap<String, Integer> map = new HashMap<>();
-        if (!ObjectUtils.isEmpty(list)) {
-            //获取所有报警的相机编码
-            //找出所有报警数据 1=高铁的数量
-            count = (int) list.stream()
-                    .map(base -> baseCameraManagementMapper.selectOne(new LambdaQueryWrapper<BaseCameraManagement>()
-                            .eq(BaseCameraManagement::getCameraCode, base.getCameraCode())))
-                    .filter(Objects::nonNull)  // 确保 management 不是 null
-                    .map(management -> baseRailwayManagementMapper.selectOne(new LambdaQueryWrapper<BaseRailwayManagement>()
-                            .eq(BaseRailwayManagement::getRailwayCode, management.getRailwayCode()))) // 确保管理信息不是空的
-                    .filter(Objects::nonNull) // 确保 baseRailwayManagement 不是 null
-                    .filter(baseRailwayManagement -> baseRailwayManagement.getRailwayType() == 1)
-                    .count();
-            //普铁的数量
-            int pu = list.size() - count;
-            map.put("highAlarmCount", count);
-            map.put("puAlarmCount", pu);
-        } else {
-            map.put("highAlarmCount", 0);
-            map.put("puAlarmCount", 0);
-        }
-        if (!ObjectUtils.isEmpty(alarmList)) {
-            //获取所有报警的相机编码
-            //找出所有未解除报警数据 1=高铁的数量
-            unresolvedCount = (int) alarmList.stream()
-                    .map(base -> baseCameraManagementMapper.selectOne(new LambdaQueryWrapper<BaseCameraManagement>()
-                            .eq(BaseCameraManagement::getCameraCode, base.getCameraCode())))
-                    .filter(Objects::nonNull)
-                    .map(management -> baseRailwayManagementMapper.selectOne(new LambdaQueryWrapper<BaseRailwayManagement>()
-                            .eq(BaseRailwayManagement::getRailwayCode, management.getRailwayCode()))) // 确保管理信息不是空的
-                    .filter(Objects::nonNull) // 确保 baseRailwayManagement 不是 null
-                    .filter(baseRailwayManagement -> baseRailwayManagement.getRailwayType() == 1)
-                    .count();
-            //普铁的数量
-            int puUnresolvedCount = alarmList.size() - unresolvedCount;
-            map.put("highUnresolvedCount", unresolvedCount);
-            map.put("puUnresolvedCount", puUnresolvedCount);
-        } else {
-            map.put("highUnresolvedCount", 0);
-            map.put("puUnresolvedCount", 0);
-        }
+
+        // 处理已解决的报警
+        HashMap<String, Integer> resolvedCounts = calculateAlarmCounts(list);
+        map.put("highAlarmCount", resolvedCounts.get("highAlarmCount"));
+        map.put("puAlarmCount", resolvedCounts.get("puAlarmCount"));
+
+        // 处理未解决的报警
+        HashMap<String, Integer> unresolvedCounts = calculateAlarmCounts(alarmList);
+        map.put("highUnresolvedCount", unresolvedCounts.get("highAlarmCount"));
+        map.put("puUnresolvedCount", unresolvedCounts.get("puAlarmCount"));
+
         return AjaxResult.success(map);
     }
+    // 定义一个方法来计算高铁和普铁报警数量
+    private HashMap<String, Integer> calculateAlarmCounts(List<MsgAlarm> alarms) {
+        HashMap<String, Integer> counts = new HashMap<>();
+        if (ObjectUtils.isEmpty(alarms)) {
+            counts.put("highAlarmCount", 0);
+            counts.put("puAlarmCount", 0);
+            return counts;
+        }
+
+        // 收集相机编码并批量查询
+        Set<String> cameraCodes = alarms.stream().map(MsgAlarm::getCameraCode).collect(Collectors.toSet());
+        List<BaseCameraManagement> cameraManagements = baseCameraManagementMapper.selectList(new LambdaQueryWrapper<BaseCameraManagement>()
+                .in(BaseCameraManagement::getCameraCode, cameraCodes));
+
+        // 收集有效的铁路编码
+        Set<String> railwayCodes = cameraManagements.stream()
+                .filter(Objects::nonNull)
+                .map(BaseCameraManagement::getRailwayCode)
+                .collect(Collectors.toSet());
+
+        List<BaseRailwayManagement> railwayManagements = baseRailwayManagementMapper.selectList(new LambdaQueryWrapper<BaseRailwayManagement>()
+                .in(BaseRailwayManagement::getRailwayCode, railwayCodes));
+
+        // 计算高铁和普铁的数量
+        long highCount = railwayManagements.stream()
+                .filter(Objects::nonNull)
+                .filter(rw -> rw.getRailwayType() == 1)
+                .count();
+
+        int puCount = alarms.size() - (int) highCount;
+
+        counts.put("highAlarmCount", (int) highCount);
+        counts.put("puAlarmCount", puCount);
+
+        return counts;
+    }
 
     @Override
     public AjaxResult alarmCountSort(MsgAlarmVo msgAlarmVo) {