ustcyc
2025-01-07 de5d55508afd27fb2b47e6d4d6fd9984525c222c
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
<?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.RealtimeAlarmMapper">
 
 
    <resultMap type="com.zhitan.alarm.domain.RealTimeAlarm"
               id="RealTimeAlarmResult">
        <result property="id" column="id"/>
        <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="content" column="content"/>
    <result property="timeCode" column="time_code"/>
    <result property="alarmCode" column="alarm_code"/>
        <association property="alarmItem"
                     javaType="com.zhitan.alarm.domain.AlarmItem">
            <result property="id" column="itemId"/>
            <result property="timeSlot" column="time_slot"/>
            <result property="limitType" column="limit_type"/>
            <result property="alarmLevel" column="alarm_level"/>
        </association>
  </resultMap>
 
  <resultMap type="JkRealTimeAlarmList" id="JkRealTimeAlarmListResult">
    <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"/>
  </resultMap>
 
 
  <select id="selectRealtimeAlarmList" parameterType="RealTimeAlarm"
    resultMap="RealTimeAlarmResult">
    select id, index_id, index_name, item_id, limiting_value, alarm_value, alarm_value_quality,
    begin_time, content from realtime_alarm
    <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 alarm_value_quality like
        concat('%', #{alarmValueQuality}, '%')
      </if>
      <if test="beginTime != null ">and begin_time like concat('%', #{beginTime}, '%')</if>
      <if test="content != null  and content != ''">and content like concat('%', #{content}, '%')
      </if>
    </where>
  </select>
 
  <select id="selectRealtimeAlarmById" parameterType="String" resultMap="RealTimeAlarmResult">
    select id,
           index_id,
           index_name,
           item_id,
           limiting_value,
           alarm_value,
           alarm_value_quality,
           begin_time,
           content
    from realtime_alarm
    where id = #{id}
  </select>
 
  <insert id="insertRealtimeAlarm" parameterType="RealTimeAlarm">
    insert into realtime_alarm
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">id,</if>
      <if test="indexId != null  and indexId != ''">index_id,</if>
      <if test="indexName != null  and indexName != ''">index_name,</if>
      <if test="itemId != null  and itemId != ''">item_id,</if>
      <if test="limitingValue != null ">limiting_value,</if>
      <if test="alarmValue != null ">alarm_value,</if>
      <if test="alarmValueQuality != null">alarm_value_quality,</if>
      <if test="beginTime != null ">begin_time,</if>
      <if test="content != null  and content != ''">content,</if>
      <if test="timeCode != null  and timeCode != ''">time_code,</if>
      <if test="alarmCode != null  and alarmCode != ''">alarm_code,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">#{id},</if>
      <if test="indexId != null  and indexId != ''">#{indexId},</if>
      <if test="indexName != null  and indexName != ''">#{indexName},</if>
      <if test="itemId != null  and itemId != ''">#{itemId},</if>
      <if test="limitingValue != null ">#{limitingValue},</if>
      <if test="alarmValue != null ">#{alarmValue},</if>
      <if test="alarmValueQuality != null">#{alarmValueQuality},</if>
      <if test="beginTime != null ">#{beginTime},</if>
      <if test="content != null  and content != ''">#{content},</if>
      <if test="timeCode != null  and timeCode != ''">#{timeCode},</if>
      <if test="alarmCode != null  and alarmCode != ''">#{alarmCode},</if>
    </trim>
  </insert>
 
  <update id="updateRealtimeAlarm" parameterType="RealTimeAlarm">
    update realtime_alarm
    <trim prefix="SET" suffixOverrides=",">
      <if test="indexId != null  and indexId != ''">index_id = #{indexId},</if>
      <if test="indexName != null  and indexName != ''">index_name = #{indexName},</if>
      <if test="itemId != null  and itemId != ''">item_id = #{itemId},</if>
      <if test="limitingValue != null ">limiting_value = #{limitingValue},</if>
      <if test="alarmValue != null ">alarm_value = #{alarmValue},</if>
      <if test="alarmValueQuality != null">alarm_value_quality =
        #{alarmValueQuality},
      </if>
      <if test="beginTime != null ">begin_time = #{beginTime},</if>
      <if test="content != null  and content != ''">content = #{content},</if>
    </trim>
    where id = #{id}
  </update>
 
  <delete id="deleteRealtimeAlarmById" parameterType="String">
    delete
    from realtime_alarm
    where id = #{id}
  </delete>
 
  <delete id="deleteRealtimeAlarmByIds" parameterType="String">
    delete from realtime_alarm where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
 
  <!--实时报警列表页面 采集点 主页面列表查询-->
  <select id="selectRealtimeAlarmJkList" parameterType="JkRealTimeAlarmList"
    resultMap="JkRealTimeAlarmListResult">
    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,
    round(cast(bj.alarm_value as numeric ),2) as alarm_value,
    ei.index_id,
    mo.node_id
    FROM
    energy_index ei,
    node_index ni,
    model_node mo,
    realtime_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'
    AND ei.index_type=#{indexType}
    <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>
    order by alarm_level,mo.node_id,limit_type asc
  </select>
  <select id="getRealTimeAlarmByAlarmCode" resultMap="RealTimeAlarmResult">
    select *
    from realtime_alarm
    where alarm_code = #{itemId}
  </select>
  <select id="getRealTimeAlarm" resultMap="RealTimeAlarmResult">
    select *
    from realtime_alarm ra
  </select>
  <select id="getAlarmByItemIdAndTimeCode" resultMap="RealTimeAlarmResult">
    select *
    from realtime_alarm
    where item_id = #{itemId}
      and time_code = #{timeCode}
  </select>
  <select id="selectRealtimeAlarmJkPage" resultMap="JkRealTimeAlarmListResult">
    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,
    round(cast(bj.alarm_value as numeric ),2) as alarm_value,
    ei.index_id,
    mo.node_id
    FROM
    energy_index ei,
    node_index ni,
    model_node mo,
    realtime_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 = #{realTimeAlarmList.nodeId} )
    <if test='realTimeAlarmList.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=#{realTimeAlarmList.indexType}
    <if test="realTimeAlarmList.indexName != null  and realTimeAlarmList.indexName != ''">and ei.name like concat('%', #{realTimeAlarmList.indexName},
      '%')
    </if>
    <if test="realTimeAlarmList.limitType != null  and realTimeAlarmList.limitType != ''">and alit.limit_type=#{realTimeAlarmList.limitType}</if>
    <if test="realTimeAlarmList.alarmLevel != null  and realTimeAlarmList.alarmLevel != ''">and alit.alarm_level=#{realTimeAlarmList.alarmLevel}</if>
    order by alarm_level,mo.node_id,limit_type asc
  </select>
 
</mapper>