Browse Source

相机截图开发

gao.qiang 3 weeks atrás
parent
commit
73c6dd6660

+ 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) {

+ 32 - 60
business-service/src/main/resources/mapper/service/MsgAlarmMapper.xml

@@ -390,66 +390,38 @@
         a.released_reason AS releasedReason,
         a.remark AS remark
         FROM
-        msg_alarm AS a join
-        base_camera_management AS b on a.camera_code=b.camera_code join
-        base_railway_management AS l on b.railway_code=l.railway_code
-        <where>
-            <if test="railwayCode != null and railwayCode != ''">
-                concat(l.railway_name,l.railway_code)
-                like concat("%",#{railwayCode},"%")
-            </if>
-            <if test="beginMile != null and beginMile != 0">
-                and b.begin_mile &gt;=#{beginMile}
-            </if>
-            <if test="endMile != null and endMile != 0">
-                and b.end_mile &lt;=#{endMile}
-            </if>
-            <if test="ids != null and ids.size>0">
-                and a.id in
-                <foreach item="items" collection="ids" separator="," open="(" close=")" index="">
-                    #{items}
-                </foreach>
-            </if>
-            <if test="!dsFlay">
-                and
-                <trim prefix="(" prefixOverrides="or" suffix=")">
-                    <if test="dsUserId != null and dsUserId != ''">
-                        or a.create_by=#{dsUserId}
-                    </if>
-                    <if test="dsDeptId != null and dsDeptId != 0">
-                        or b.dept_id=#{dsDeptId}
-                    </if>
-                    <if test="dsDeptIds != null">
-                        or b.dept_id in
-                        <foreach item="item" collection="dsDeptIds" separator="," open="(" close=")" index="">
-                            #{item}
-                        </foreach>
-                    </if>
-                </trim>
-            </if>
-            <if test="alarmType != null and alarmType != 0">
-                and a.alarm_type=#{alarmType}
-            </if>
-            <if test="alarmMile != null and alarmMile != 0">
-                and a.alarm_mile=#{alarmMile}
-            </if>
-            <if test="isLock != null and isLock != 0">
-                and a.is_lock=#{isLock}
-            </if>
-            <if test="lineDir != null and lineDir != 0">
-                and a.line_dir =#{lineDir}
-            </if>
-            <if test="releasedType != null and releasedType != 0">
-                and a.released_type =#{releasedType}
-            </if>
-            <if test="beginAlarmTime != null and beginAlarmTime != ''">
-                and date_format(a.alarm_time,'%Y-%m-%d') &gt;= date_format(#{beginAlarmTime},'%Y-%m-%d')
-            </if>
-            <if test="endAlarmTime != null and endAlarmTime != ''">
-                AND date_format(a.alarm_time,'%Y-%m-%d') &lt;= date_format(#{endAlarmTime},'%Y-%m-%d')
-            </if>
-        </where>
-        order by a.alarm_time desc
+        msg_alarm AS a
+        JOIN
+        base_camera_management AS b ON a.camera_code = b.camera_code
+        JOIN
+        base_railway_management AS l ON b.railway_code = l.railway_code
+        WHERE
+        (railwayCode IS NULL OR railwayCode = '' OR CONCAT(l.railway_name, l.railway_code) LIKE CONCAT('%', #{railwayCode}, '%'))
+        AND (beginMile IS NULL OR beginMile = 0 OR b.begin_mile >= #{beginMile})
+        AND (endMile IS NULL OR endMile = 0 OR b.end_mile <= #{endMile})
+        AND (ids IS NULL OR ids.size = 0 OR a.id IN
+        <foreach item="item" collection="ids" separator=",">
+            #{item}
+        </foreach>)
+        AND (dsFlay OR (
+        (dsUserId IS NULL OR dsUserId = '' OR a.create_by = #{dsUserId}) OR
+        (dsDeptId IS NULL OR dsDeptId = 0 OR b.dept_id = #{dsDeptId}) OR
+        (dsDeptIds IS NULL OR (
+        b.dept_id IN
+        <foreach item="item" collection="dsDeptIds" separator=",">
+            #{item}
+        </foreach>
+        ))
+        ))
+        AND (alarmType IS NULL OR alarmType = 0 OR a.alarm_type = #{alarmType})
+        AND (alarmMile IS NULL OR alarmMile = 0 OR a.alarm_mile = #{alarmMile})
+        AND (isLock IS NULL OR isLock = 0 OR a.is_lock = #{isLock})
+        AND (lineDir IS NULL OR lineDir = 0 OR a.line_dir = #{lineDir})
+        AND (releasedType IS NULL OR releasedType = 0 OR a.released_type = #{releasedType})
+        AND (beginAlarmTime IS NULL OR beginAlarmTime = '' OR DATE_FORMAT(a.alarm_time, '%Y-%m-%d') >= DATE_FORMAT(#{beginAlarmTime}, '%Y-%m-%d'))
+        AND (endAlarmTime IS NULL OR endAlarmTime = '' OR DATE_FORMAT(a.alarm_time, '%Y-%m-%d') <= DATE_FORMAT(#{endAlarmTime}, '%Y-%m-%d'))
+        ORDER BY
+        a.alarm_time DESC;
     </select>
 
     <select id="getByAlarmId" resultType="com.ozs.service.entity.MsgAlarm" parameterType="java.lang.String">