| <?xml version="1.0" encoding="UTF-8" ?> | 
| <!DOCTYPE mapper | 
| PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | 
| "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
| <mapper namespace="com.ruoyi.alarm.external.mapper.ArdAlarmExternalMapper"> | 
|   | 
|     <resultMap type="ArdAlarmExternal" id="ArdAlarmExternalResult"> | 
|         <result property="id"    column="id"    /> | 
|         <result property="alarmId"    column="alarm_id"    /> | 
|         <result property="alarmName"    column="alarm_name"    /> | 
|         <result property="defenseId"    column="defense_id"    /> | 
|         <result property="defenseName"    column="defense_name"    /> | 
|         <result property="alarmType"    column="alarm_type"    /> | 
|         <result property="alarmTime"    column="alarm_time"    /> | 
|         <result property="subSysNo"    column="sub_sys_no"    /> | 
|         <result property="alarmHostId"    column="alarm_host_id"    /> | 
|         <result property="longitude"    column="longitude"    /> | 
|         <result property="latitude"    column="latitude"    /> | 
|         <result property="altitude"    column="altitude"    /> | 
|         <result property="recordUrl"    column="record_url"    /> | 
|         <result property="viewTime"    column="view_time"    /> | 
|         <result property="deptId"    column="dept_id"    /> | 
|         <result property="userId"    column="user_id"    /> | 
|         <result property="createBy"    column="create_by"    /> | 
|         <result property="createTime"    column="create_time"    /> | 
|     </resultMap> | 
|   | 
|     <sql id="selectArdAlarmExternalVo"> | 
|         select id, alarm_id, alarm_name, defense_id, defense_name, alarm_type, alarm_time, sub_sys_no, alarm_host_id, longitude, latitude, altitude, record_url, view_time, dept_id, user_id, create_by, create_time from ard_alarm_external | 
|     </sql> | 
|   | 
|     <select id="selectArdAlarmExternalList" parameterType="ArdAlarmExternal" resultMap="ArdAlarmExternalResult"> | 
|         <include refid="selectArdAlarmExternalVo"/> | 
|         <where> | 
|             <if test="alarmId != null  and alarmId != ''"> and alarm_id = #{alarmId}</if> | 
|             <if test="alarmName != null  and alarmName != ''"> and alarm_name like '%'||#{alarmName}||'%'</if> | 
|             <if test="defenseId != null  and defenseId != ''"> and defense_id = #{defenseId}</if> | 
|             <if test="defenseName != null  and defenseName != ''"> and defense_name like '%'||#{defenseName}||'%'</if> | 
|             <if test="alarmType != null  and alarmType != ''"> and alarm_type = #{alarmType}</if> | 
|             <if test="subSysNo != null  and subSysNo != ''"> and sub_sys_no = #{subSysNo}</if> | 
|             <if test="alarmHostId != null  and alarmHostId != ''"> and alarm_host_id = #{alarmHostId}</if> | 
|             <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if> | 
|             <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if> | 
|             <if test="altitude != null  and altitude != ''"> and altitude = #{altitude}</if> | 
|             <if test="recordUrl != null  and recordUrl != ''"> and record_url = #{recordUrl}</if> | 
|             <if test="viewTime != null "> and view_time = #{viewTime}</if> | 
|             <if test="deptId != null  and deptId != ''"> and dept_id = #{deptId}</if> | 
|             <if test="userId != null  and userId != ''"> and user_id = #{userId}</if> | 
|             <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | 
|                 AND alarm_time >= to_timestamp(#{params.beginTime},'yyyy-MM-DD HH24:MI:ss') | 
|             </if> | 
|             <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | 
|                 AND alarm_time <= to_timestamp(#{params.endTime},'yyyy-MM-DD HH24:MI:ss') | 
|             </if> | 
|         </where> | 
|     </select> | 
|   | 
|     <select id="selectArdAlarmExternalById" parameterType="String" resultMap="ArdAlarmExternalResult"> | 
|         <include refid="selectArdAlarmExternalVo"/> | 
|         where id = #{id} | 
|     </select> | 
|   | 
|     <insert id="insertArdAlarmExternal" parameterType="ArdAlarmExternal"> | 
|         insert into ard_alarm_external | 
|         <trim prefix="(" suffix=")" suffixOverrides=","> | 
|             <if test="id != null">id,</if> | 
|             <if test="alarmId != null">alarm_id,</if> | 
|             <if test="alarmName != null">alarm_name,</if> | 
|             <if test="defenseId != null">defense_id,</if> | 
|             <if test="defenseName != null">defense_name,</if> | 
|             <if test="alarmType != null">alarm_type,</if> | 
|             <if test="alarmTime != null">alarm_time,</if> | 
|             <if test="subSysNo != null">sub_sys_no,</if> | 
|             <if test="alarmHostId != null">alarm_host_id,</if> | 
|             <if test="longitude != null">longitude,</if> | 
|             <if test="latitude != null">latitude,</if> | 
|             <if test="altitude != null">altitude,</if> | 
|             <if test="recordUrl != null">record_url,</if> | 
|             <if test="viewTime != null">view_time,</if> | 
|             <if test="deptId != null">dept_id,</if> | 
|             <if test="userId != null">user_id,</if> | 
|             <if test="createBy != null">create_by,</if> | 
|             <if test="createTime != null">create_time,</if> | 
|         </trim> | 
|         <trim prefix="values (" suffix=")" suffixOverrides=","> | 
|             <if test="id != null">#{id},</if> | 
|             <if test="alarmId != null">#{alarmId},</if> | 
|             <if test="alarmName != null">#{alarmName},</if> | 
|             <if test="defenseId != null">#{defenseId},</if> | 
|             <if test="defenseName != null">#{defenseName},</if> | 
|             <if test="alarmType != null">#{alarmType},</if> | 
|             <if test="alarmTime != null">#{alarmTime},</if> | 
|             <if test="subSysNo != null">#{subSysNo},</if> | 
|             <if test="alarmHostId != null">#{alarmHostId},</if> | 
|             <if test="longitude != null">#{longitude},</if> | 
|             <if test="latitude != null">#{latitude},</if> | 
|             <if test="altitude != null">#{altitude},</if> | 
|             <if test="recordUrl != null">#{recordUrl},</if> | 
|             <if test="viewTime != null">#{viewTime},</if> | 
|             <if test="deptId != null">#{deptId},</if> | 
|             <if test="userId != null">#{userId},</if> | 
|             <if test="createBy != null">#{createBy},</if> | 
|             <if test="createTime != null">#{createTime},</if> | 
|         </trim> | 
|     </insert> | 
|   | 
|     <update id="updateArdAlarmExternal" parameterType="ArdAlarmExternal"> | 
|         update ard_alarm_external | 
|         <trim prefix="SET" suffixOverrides=","> | 
|             <if test="alarmId != null">alarm_id = #{alarmId},</if> | 
|             <if test="alarmName != null">alarm_name = #{alarmName},</if> | 
|             <if test="defenseId != null">defense_id = #{defenseId},</if> | 
|             <if test="defenseName != null">defense_name = #{defenseName},</if> | 
|             <if test="alarmType != null">alarm_type = #{alarmType},</if> | 
|             <if test="alarmTime != null">alarm_time = #{alarmTime},</if> | 
|             <if test="subSysNo != null">sub_sys_no = #{subSysNo},</if> | 
|             <if test="alarmHostId != null">alarm_host_id = #{alarmHostId},</if> | 
|             <if test="longitude != null">longitude = #{longitude},</if> | 
|             <if test="latitude != null">latitude = #{latitude},</if> | 
|             <if test="altitude != null">altitude = #{altitude},</if> | 
|             <if test="recordUrl != null">record_url = #{recordUrl},</if> | 
|             <if test="viewTime != null">view_time = #{viewTime},</if> | 
|             <if test="deptId != null">dept_id = #{deptId},</if> | 
|             <if test="userId != null">user_id = #{userId},</if> | 
|             <if test="createBy != null">create_by = #{createBy},</if> | 
|             <if test="createTime != null">create_time = #{createTime},</if> | 
|         </trim> | 
|         where id = #{id} | 
|     </update> | 
|   | 
|     <delete id="deleteArdAlarmExternalById" parameterType="String"> | 
|         delete from ard_alarm_external where id = #{id} | 
|     </delete> | 
|   | 
|     <delete id="deleteArdAlarmExternalByIds" parameterType="String"> | 
|         delete from ard_alarm_external where id in | 
|         <foreach item="id" collection="array" open="(" separator="," close=")"> | 
|             #{id} | 
|         </foreach> | 
|     </delete> | 
|     <select id="selectCountByAlarmTime" resultType="Integer"> | 
|         SELECT COUNT(DISTINCT aae.defense_name) | 
|         FROM ard_alarm_external aae | 
|         WHERE aae.alarm_time >= CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE | 
|           and aae.alarm_type = #{alarmType} | 
|           and aae.view_time is null | 
|     </select> | 
|     <select id="selectListAllByCommand" resultMap="ArdAlarmExternalResult"> | 
|         SELECT T | 
|                    .* | 
|         FROM | 
|             ( | 
|                 SELECT | 
|                     aae.ID, | 
|                     aae.alarm_id, | 
|                     aae.alarm_name, | 
|                     aae.defense_id, | 
|                     aae.defense_name, | 
|                     aae.alarm_type, | 
|                     aae.alarm_time, | 
|                     aae.longitude, | 
|                     aae.latitude, | 
|                     ROW_NUMBER () OVER ( PARTITION BY aae.defense_name ORDER BY aae.alarm_time DESC ) AS rn, | 
|                         COUNT ( CASE WHEN aae.view_time IS NULL THEN 1 END ) OVER ( PARTITION BY aae.defense_name ) AS COUNT, | 
|         COUNT ( aae.alarm_time ) OVER ( PARTITION BY aae.defense_name ) AS total | 
|                 FROM | 
|                     ard_alarm_external aae | 
|                 WHERE | 
|                     aae.alarm_time >= ( CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE ) | 
|                   AND aae.alarm_type = #{ alarmType } | 
|                 ORDER BY | 
|                     aae.alarm_time DESC | 
|             ) T | 
|         WHERE | 
|             T.rn = 1 | 
|     </select> | 
|     <update id="updateViewTimeByCondition" parameterType="String"> | 
|         update ard_alarm_external | 
|         set view_time=#{viewTime} | 
|         where defense_name = #{defenseName} | 
|           and alarm_type=#{alarmType} | 
|           and alarm_time<=#{alarmTime} | 
|           and view_time is null | 
|     </update> | 
| </mapper> |