Explorar o código

相机截图开发

gao.qiang hai 3 semanas
pai
achega
2e2a5a760f

+ 3 - 0
business-service/src/main/java/com/ozs/service/mapper/MsgAlarmMapper.java

@@ -50,4 +50,7 @@ public interface MsgAlarmMapper extends BaseMapper<MsgAlarm> {
     List<MsgAlarm> queryAlarmInfoByAfterTenMinute();
 
     List<MsgAlarm> selectMsgAlarmListHome(MsgAlarmVo msgAlarmVo);
+
+    // 新的方法,直接查询统计结果
+    Map<String, Integer> selectAlarmStatistics(MsgAlarmVo msgAlarmVo);
 }

+ 9 - 53
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -242,63 +242,19 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
 
     @Override
     public AjaxResult alarmStatistics(MsgAlarmVo msgAlarmVo1) {
-        // 查询所有报警数据
-        List<MsgAlarm> list = msgAlarmMapper.selectMsgAlarmList(msgAlarmVo1);
+        // 执行合并查询以获取统计结果
+        Map<String, Integer> statistics = msgAlarmMapper.selectAlarmStatistics(msgAlarmVo1);
 
-        // 查询未解除的报警数据
-        msgAlarmVo1.setIsLock(2);
-        List<MsgAlarm> alarmList = msgAlarmMapper.selectMsgAlarmList(msgAlarmVo1);
+        // 创建返回结果的 map
+        Map<String, Integer> results = new HashMap<>();
+        results.put("highAlarmCount", statistics.get("highAlarmCount"));
+        results.put("puAlarmCount", statistics.get("puAlarmCount"));
+        results.put("highUnresolvedCount", statistics.get("highUnresolvedCount"));
+        results.put("puUnresolvedCount", statistics.get("puUnresolvedCount"));
 
-        HashMap<String, Integer> map = new HashMap<>();
-
-        // 处理已解决的报警
-        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);
+        return AjaxResult.success(results);
     }
-    // 定义一个方法来计算高铁和普铁报警数量
-    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) {

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

@@ -390,38 +390,66 @@
         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
-        (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;
+        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
     </select>
 
     <select id="getByAlarmId" resultType="com.ozs.service.entity.MsgAlarm" parameterType="java.lang.String">
@@ -526,4 +554,43 @@
           and a.released_url is null
           and a.alarm_time &lt;= DATE_SUB(NOW(), INTERVAL 10 MINUTE)
     </select>
+    <select id="selectAlarmStatistics" resultType="java.util.HashMap">
+        SELECT
+        SUM(CASE WHEN rm.railway_type = 1 THEN 1 ELSE 0 END) AS highAlarmCount,
+        SUM(CASE WHEN rm.railway_type &lt;&gt; 1 THEN 1 ELSE 0 END) AS puAlarmCount,
+        SUM(CASE WHEN am.is_lock = 2 AND rm.railway_type = 1 THEN 1 ELSE 0 END) AS highUnresolvedCount,
+        SUM(CASE WHEN am.is_lock = 2 AND rm.railway_type &lt;&gt; 1 THEN 1 ELSE 0 END) AS puUnresolvedCount
+        FROM
+        msg_alarm am
+        JOIN
+        base_camera_management cm ON am.camera_code = cm.camera_code
+        JOIN
+        base_railway_management rm ON cm.railway_code = rm.railway_code
+        <where>
+            am.is_lock IN (1, 2)
+            <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 am.create_by=#{dsUserId}
+                    </if>
+                    <if test="dsDeptId != null and dsDeptId != 0">
+                        or cm.dept_id=#{dsDeptId}
+                    </if>
+                    <if test="dsDeptIds != null">
+                        or cm.dept_id in
+                        <foreach item="item" collection="dsDeptIds" separator="," open="(" close=")" index="">
+                            #{item}
+                        </foreach>
+                    </if>
+                </trim>
+            </if>
+        </where>
+    </select>
 </mapper>