1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?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 &gt;= to_timestamp(#{params.beginTime},'yyyy-MM-DD HH24:MI:ss')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND alarm_time &lt;= to_timestamp(#{params.endTime},'yyyy-MM-DD HH24:MI:ss')
            </if>
        </where>
        order by alarm_time desc
    </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&lt;=#{alarmTime}
          and view_time is null
    </update>
</mapper>