ustcyc
2025-04-18 12ea7330bac0a43818b8ec3a8601119dd609dfb9
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?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.zhitan.alarm.mapper.HistoryAlarmMapper">
 
  <resultMap type="com.zhitan.alarm.domain.HistoryAlarm" id="HistoryAlarmResult">
    <result property="id" column="id"/>
    <result property="endTime" column="end_time"/>
    <result property="indexId" column="index_id"/>
    <result property="indexName" column="index_name"/>
    <result property="itemId" column="item_id"/>
    <result property="limitingValue" column="limiting_value"/>
    <result property="alarmValue" column="alarm_value"/>
    <result property="alarmValueQuality" column="alarm_value_quality"/>
    <result property="beginTime" column="begin_time"/>
    <result property="duration" column="duration"/>
    <result property="content" column="content"/>
  </resultMap>
 
  <resultMap type="com.zhitan.alarm.domain.JkHistoryAlarm" id="JkHistoryAlarmResult">
    <result property="modelName" column="modelname"/>
    <result property="code" column="code"/>
    <result property="indexName" column="indexname"/>
    <result property="unitId" column="unit_id"/>
    <result property="alarmLevel" column="alarm_level"/>
    <result property="limitType" column="limit_type"/>
    <result property="limitingValue" column="limiting_value"/>
    <result property="alarmBeginTime" column="begin_time"/>
    <result property="alarmValue" column="alarm_value"/>
    <result property="indexId" column="index_id"/>
    <result property="nodeId" column="node_id"/>
    <result property="duration" column="duration"/>
    <result property="alarmBeginTime" column="begin_time"/>
    <result property="alarmEndTime" column="end_time"/>
  </resultMap>
 
  <sql id="selectHistoryAlarmVo">
    select id,
           index_id,
           index_name,
           item_id,
           limiting_value,
           alarm_value,
           alarm_value_quality,
           begin_time,
           end_time,
           duration,
           content
    from history_alarm
  </sql>
 
  <select id="selectHistoryAlarmList" parameterType="com.zhitan.alarm.domain.HistoryAlarm" resultMap="HistoryAlarmResult">
    <include refid="selectHistoryAlarmVo"/>
    <where>
      <if test="indexName != null  and indexName != ''">and index_name like concat('%',
        #{indexName}, '%')
      </if>
      <if test="itemId != null  and itemId != ''">and item_id like concat('%', #{itemId}, '%')</if>
      <if test="limitingValue != null ">and limiting_value like concat('%', #{limitingValue}, '%')
      </if>
      <if test="alarmValue != null ">and alarm_value like concat('%', #{alarmValue}, '%')</if>
      <if test="alarmValueQuality != null  and alarmValueQuality != ''">and alarm_value_quality like
        concat('%', #{alarmValueQuality}, '%')
      </if>
      <if test="beginTime != null ">and begin_time like concat('%', #{beginTime}, '%')</if>
      <if test="endTime != null ">and end_time like concat('%', #{endTime}, '%')</if>
      <if test="duration != null ">and duration like concat('%', #{duration}, '%')</if>
      <if test="content != null  and content != ''">and content like concat('%', #{content}, '%')
      </if>
    </where>
  </select>
 
  <select id="selectHistoryAlarmById" parameterType="String" resultMap="HistoryAlarmResult">
    <include refid="selectHistoryAlarmVo"/>
    where id = #{id}
  </select>
 
 
  <update id="updateHistoryAlarm" parameterType="com.zhitan.alarm.domain.HistoryAlarm">
    delete from realtime_alarm where alarm_code = #{alarmCode};
    insert into history_alarm
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="historyAlarm.id != null  and historyAlarm.id != ''">id,</if>
      <if test="historyAlarm.indexId != null  and historyAlarm.indexId != ''">index_id,</if>
      <if test="historyAlarm.indexName != null  and historyAlarm.indexName != ''">index_name,</if>
      <if test="historyAlarm.itemId != null  and historyAlarm.itemId != ''">item_id,</if>
      <if test="historyAlarm.limitingValue != null ">limiting_value,</if>
      <if test="historyAlarm.alarmValue != null ">alarm_value,</if>
      <if test="historyAlarm.alarmValueQuality != null">alarm_value_quality,</if>
      <if test="historyAlarm.beginTime != null ">begin_time,</if>
      <if test="historyAlarm.endTime != null ">end_time,</if>
      <if test="historyAlarm.duration != null ">duration,</if>
      <if test="historyAlarm.content != null  and historyAlarm.content != ''">content,</if>
      <if test="historyAlarm.timeCode != null and historyAlarm.timeCode != ''">time_code,</if>
      <if test="historyAlarm.alarmCode != null and historyAlarm.alarmCode != ''">alarm_code,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="historyAlarm.id != null  and historyAlarm.id != ''">#{historyAlarm.id},</if>
      <if test="historyAlarm.indexId != null  and historyAlarm.indexId != ''">#{historyAlarm.indexId},</if>
      <if test="historyAlarm.indexName != null  and historyAlarm.indexName != ''">#{historyAlarm.indexName},</if>
      <if test="historyAlarm.itemId != null  and historyAlarm.itemId != ''">#{historyAlarm.itemId},</if>
      <if test="historyAlarm.limitingValue != null ">#{historyAlarm.limitingValue},</if>
      <if test="historyAlarm.alarmValue != null ">#{historyAlarm.alarmValue},</if>
      <if test="historyAlarm.alarmValueQuality != null">#{historyAlarm.alarmValueQuality},</if>
      <if test="historyAlarm.beginTime != null ">#{historyAlarm.beginTime},</if>
      <if test="historyAlarm.endTime != null ">#{historyAlarm.endTime},</if>
      <if test="historyAlarm.duration != null ">#{historyAlarm.duration},</if>
      <if test="historyAlarm.content != null  and historyAlarm.content != ''">#{historyAlarm.content},</if>
      <if test="historyAlarm.timeCode != null and historyAlarm.timeCode != ''">#{historyAlarm.timeCode},</if>
      <if test="historyAlarm.alarmCode != null and historyAlarm.alarmCode != ''">#{historyAlarm.alarmCode},</if>
    </trim>
    ;
  </update>
 
  <delete id="deleteHistoryAlarmById" parameterType="String">
    delete
    from history_alarm
    where id = #{id}
  </delete>
 
  <delete id="deleteHistoryAlarmByIds" parameterType="String">
    delete from history_alarm where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
 
  <!--历史 报警列表页面 采集点 主页面列表查询-->
  <select id="selectJkHistoryAlarmList" parameterType="com.zhitan.alarm.domain.JkHistoryAlarm"
    resultMap="JkHistoryAlarmResult">
    SELECT
    mo."name" AS modelname,
    ei.code,
    ei.NAME AS indexname,
    ei.unit_id,
    alit.alarm_level,
    alit.limit_type,
    bj.limiting_value,
    bj.begin_time,
    bj.end_time,
    bj.alarm_value,
    bj.duration,
    ei.index_id,
    ei.index_type,
    mo.node_id
    FROM
    energy_index ei,
    node_index ni,
    model_node mo,
    history_alarm bj ,
    alarm_item alit
    WHERE
    ni.node_id IN (
    SELECT node_id FROM model_node WHERE address LIKE (
    SELECT address FROM model_node WHERE node_id = #{nodeId} )
    <if test='eierarchyFlag=="ALL"'>
      || '%'
    </if>
    )
    AND ei.index_id = ni.index_id
    AND mo.node_id = ni.node_id
    AND bj.index_id = ei.index_id
    AND alit.alarm_code = bj.alarm_code
    AND alit.time_slot='LIVE'
    <if test="indexType != null  and indexType != ''">
        AND ei.index_type=#{indexType}
    </if>
    <if test="indexName != null  and indexName != ''">and ei.name like concat('%', #{indexName},
      '%')
    </if>
    <if test="limitType != null  and limitType != ''">and alit.limit_type=#{limitType}</if>
    <if test="alarmLevel != null  and alarmLevel != ''">and alit.alarm_level=#{alarmLevel}</if>
    <if test="beginTime != null and beginTime != ''">and begin_time &gt;=
      to_timestamp(#{beginTime},'yyyy-mm-dd hh24:mi:ss')
    </if>
    <if test="endTime != null and endTime != ''">and begin_time &lt;=
      to_timestamp(#{endTime},'yyyy-mm-dd hh24:mi:ss')
    </if>
    order by alarm_level,mo.node_id,limit_type asc
  </select>
 
  <select id="selectJkHistoryAlarmListExcel" parameterType="com.zhitan.alarm.domain.JkHistoryAlarm"
    resultMap="JkHistoryAlarmResult">
    SELECT
    mo."name" AS modelname,
    ei.code,
    ei.NAME AS indexname,
    fun_getdicedata('sys_unit',ei.unit_id) as unit_id,
    fun_getdicedata('alarm_level',alit.alarm_level) as alarm_level,
    lt.limit_name as limit_type,
    bj.limiting_value,
    bj.begin_time,
    bj.end_time,
    bj.alarm_value,
    bj.duration,
    ei.index_id,
    mo.node_id
    FROM
    energy_index ei,
    node_index ni,
    model_node mo,
    history_alarm bj ,
    alarm_item alit,
    limit_type lt
    WHERE
    ni.node_id IN (
    SELECT node_id FROM model_node WHERE address LIKE (
    SELECT address FROM model_node WHERE node_id = #{nodeId} )
    <if test='eierarchyFlag=="ALL"'>
      || '%'
    </if>
    )
    AND ei.index_id = ni.index_id
    AND mo.node_id = ni.node_id
    AND bj.index_id = ei.index_id
    AND alit.alarm_code = bj.alarm_code
    AND alit.time_slot='LIVE'
    AND ei.index_type=#{indexType}
    AND lt.limit_code=alit.limit_type
    <if test="indexName != null  and indexName != ''">and ei.name like concat('%', #{indexName},
      '%')
    </if>
    <if test="limitType != null  and limitType != ''">and alit.limit_type=#{limitType}</if>
    <if test="alarmLevel != null  and alarmLevel != ''">and alit.alarm_level=#{alarmLevel}</if>
    <if test="beginTime != null and beginTime != '' ">and begin_time &gt;=
      to_timestamp(#{beginTime},'yyyy-mm-dd hh24:mi:ss')
    </if>
    <if test="endTime != null and endTime != ''">and begin_time &lt;=
      to_timestamp(#{endTime},'yyyy-mm-dd hh24:mi:ss')
    </if>
    order by alarm_level,mo.node_id,limit_type asc
  </select>
 
  <select id="selectHistoryAlarmNoteList" parameterType="com.zhitan.alarm.domain.JkHistoryAlarm"
    resultMap="JkHistoryAlarmResult">
    SELECT
    ei.code,
    ei.NAME AS indexname,
    fun_getdicedata('sys_unit',ei.unit_id) as unit_id,
    fun_getdicedata('alarm_level',alit.alarm_level) as alarm_level,
    lt.limit_name as limit_type,
    bj.limiting_value,
    bj.begin_time,
    bj.end_time,
    bj.alarm_value,
    bj.duration,
    ei.index_id
    FROM
    energy_index ei,
    history_alarm bj ,
    sys_svg_info svg,
    alarm_item alit,
    limit_type lt
    WHERE
    svg.node_id=#{nodeId}
    AND ei.code = svg.tag
    AND bj.index_id = ei.index_id
    AND alit.alarm_code = bj.alarm_code
    AND alit.time_slot='LIVE'
    AND ei.index_type=#{indexType}
    AND lt.limit_code=alit.limit_type
    <if test="indexName != null  and indexName != ''">and ei.name like concat('%', #{indexName},
      '%')
    </if>
    <if test="limitType != null  and limitType != ''">and alit.limit_type=#{limitType}</if>
    <if test="alarmLevel != null  and alarmLevel != ''">and alit.alarm_level=#{alarmLevel}</if>
    <if test="beginTime != null and beginTime != '' ">and begin_time &gt;=
      to_timestamp(#{beginTime},'yyyy-mm-dd hh24:mi:ss')
    </if>
    <if test="endTime != null and endTime != ''">and begin_time &lt;=
      to_timestamp(#{endTime},'yyyy-mm-dd hh24:mi:ss')
    </if>
    order by alarm_level,limit_type asc
  </select>
  <select id="selectJkHistoryAlarmPage" resultType="com.zhitan.alarm.domain.JkHistoryAlarm">
    SELECT
    mo."name" AS modelname,
    ei.code,
    ei.NAME AS indexname,
    ei.unit_id,
    alit.alarm_level,
    alit.limit_type,
    bj.limiting_value,
    bj.begin_time,
    bj.end_time,
    bj.alarm_value,
    bj.duration,
    ei.index_id,
    ei.index_type,
    ei.energy_id,
    mo.node_id
    FROM
    energy_index ei,
    node_index ni,
    model_node mo,
    history_alarm bj,
    alarm_item alit
    WHERE
    ni.node_id IN (
    SELECT node_id FROM model_node WHERE address LIKE (
    SELECT address FROM model_node WHERE node_id = #{jkHistoryAlarm.nodeId} )
    <if test='jkHistoryAlarm.eierarchyFlag=="ALL"'>
      || '%'
    </if>
    )
    AND ei.index_id = ni.index_id
    AND mo.node_id = ni.node_id
    AND bj.index_id = ei.index_id
    AND alit.alarm_code = bj.alarm_code
    AND alit.time_slot='LIVE'
    AND ei.index_type=#{jkHistoryAlarm.indexType}
    <if test="jkHistoryAlarm.indexName != null  and jkHistoryAlarm.indexName != ''">
      and ei.name like concat('%', #{jkHistoryAlarm.indexName}, '%')
    </if>
    <if test="jkHistoryAlarm.limitType != null  and jkHistoryAlarm.limitType != ''">
      and alit.limit_type=#{jkHistoryAlarm.limitType}
      </if>
    <if test="jkHistoryAlarm.alarmLevel != null  and jkHistoryAlarm.alarmLevel != ''">
      and alit.alarm_level=#{jkHistoryAlarm.alarmLevel}
      </if>
    <if test="jkHistoryAlarm.beginTime != null and jkHistoryAlarm.beginTime != ''">
      and begin_time &gt;= to_timestamp(#{jkHistoryAlarm.beginTime}, 'yyyy-mm-dd hh24:mi:ss')
    </if>
    <if test="jkHistoryAlarm.endTime != null and jkHistoryAlarm.endTime != ''">
      and begin_time &lt;= to_timestamp(#{jkHistoryAlarm.endTime},'yyyy-mm-dd hh24:mi:ss')
    </if>
    order by alarm_level,mo.node_id,limit_type asc
  </select>
 
  <select id="selectCountByTime" resultType="java.lang.Integer">
    select count(0)
    from history_alarm 
    <where>
      <if test="beginTime != null ">
        and begin_time &gt;= #{beginTime}
      </if>
      <if test="endTime != null ">
        and begin_time &lt;= #{endTime}
      </if>
      <if test="indexIdList != null and indexIdList.size() > 0">
        and index_id in
        <foreach collection="indexIdList" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
      </if>
    </where>
  </select>
    <select id="getHistoryAlarmList" resultType="com.zhitan.alarm.domain.JkHistoryAlarm">
      SELECT
        mn.node_id nodeId,
        mn."name" modelName,
        mi.meter_name meterName,
        mi.energy_type energyId,
        his.index_id indexId,
        ei."name" indexName,
        ei.index_type indexType,
        ei.code code,
        ei.unit_id unitId,
        ai.alarm_level alarmLevel,
        ai.limit_type limitType,
        his.limiting_value limitingValue,
        his.alarm_value alarmValue,
        his.begin_time alarmBeginTime,
        his.end_time alarmEndTime,
        his.duration duration
      FROM
        history_alarm his
          LEFT JOIN alarm_item ai ON his.item_id = ai."id"
          LEFT JOIN energy_index ei ON his.index_id = ei.index_id
          LEFT JOIN meter_implement mi ON ei.meter_id = mi."id"
          LEFT JOIN model_node mn ON mn.node_id = ai.node_id
      WHERE
        his.begin_time BETWEEN #{beginTime} AND #{endTime}
        <if test="indexIdList != null and indexIdList.size() > 0">
          AND his.index_id IN
          <foreach collection="indexIdList" item="item" open="(" separator="," close=")">
            #{item}
          </foreach>
        </if>
    </select>
 
</mapper>