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
<?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.AlarmItemMapper">
 
  <resultMap type="AlarmItem" id="AlarmItemResult">
    <result property="id" column="id"/>
    <result property="createTime" column="create_time"/>
    <result property="createBy" column="create_by"/>
    <result property="updateTime" column="update_time"/>
    <result property="updateBy" column="update_by"/>
    <result property="dwid" column="dwid"/>
    <result property="startStop" column="start_stop"/>
    <result property="timeSlot" column="time_slot"/>
    <result property="limitType" column="limit_type"/>
    <result property="limitVal" column="limit_val"/>
    <result property="alarmLevel" column="alarm_level"/>
    <result property="nodeId" column="node_id"/>
    <result property="indexCode" column="index_code"/>
    <result property="alarmCode" column="alarm_code"/>
  </resultMap>
 
  <sql id="selectAlarmItemVo">
    select id,
           create_time,
           create_by,
           update_time,
           update_by,
           dwid,
           start_stop,
           time_slot,
           limit_type,
           limit_val,
           alarm_level,
           node_id
    from alarm_item
  </sql>
 
  <select id="selectAlarmItemList" parameterType="AlarmItem" resultMap="AlarmItemResult">
    <include refid="selectAlarmItemVo"/>
    <where>
    </where>
  </select>
 
  <select id="selectAlarmItemById" parameterType="String" resultMap="AlarmItemResult">
    <include refid="selectAlarmItemVo"/>
    where id = #{id}
  </select>
 
  <insert id="insertAlarmItem" parameterType="AlarmItem">
    insert into alarm_item
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">id,</if>
      <if test="createTime != null ">create_time,</if>
      <if test="createBy != null  and createBy != ''">create_by,</if>
      <if test="updateTime != null ">update_time,</if>
      <if test="updateBy != null  and updateBy != ''">update_by,</if>
      <if test="dwid != null  and dwid != ''">dwid,</if>
      <if test="startStop != null  and startStop != ''">start_stop,</if>
      <if test="timeSlot != null  and timeSlot != ''">time_slot,</if>
      <if test="limit_type != null  and limit_type != ''">limit_type,</if>
      <if test="limitVal != null  and limitVal != ''">limit_val,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null  and id != ''">#{id},</if>
      <if test="createTime != null ">#{createTime},</if>
      <if test="createBy != null  and createBy != ''">#{createBy},</if>
      <if test="updateTime != null ">#{updateTime},</if>
      <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
      <if test="dwid != null  and dwid != ''">#{dwid},</if>
      <if test="startStop != null  and startStop != ''">#{startStop},</if>
      <if test="timeSlot != null  and timeSlot != ''">#{timeSlot},</if>
      <if test="limitType != null  and limitType != ''">#{limitType},</if>
      <if test="limitVal != null  and limitVal != ''">#{limitVal},</if>
    </trim>
  </insert>
 
  <update id="updateAlarmItem" parameterType="AlarmItem">
    update alarm_item
    <trim prefix="SET" suffixOverrides=",">
      <if test="createTime != null ">create_time = #{createTime},</if>
      <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
      <if test="updateTime != null ">update_time = #{updateTime},</if>
      <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
      <if test="dwid != null  and dwid != ''">dwid = #{dwid},</if>
      <if test="startStop != null  and startStop != ''">start_stop = #{startStop},</if>
      <if test="timeSlot != null  and timeSlot != ''">time_slot = #{timeSlot},</if>
      <if test="limitType != null  and limitType != ''">limit = #{limitType},</if>
      <if test="limitVal != null  and limitVal != ''">limit_val = #{limitVal},</if>
    </trim>
    where id = #{id}
  </update>
 
  <delete id="deleteAlarmItemById" parameterType="String">
    delete
    from alarm_item
    where id = #{id}
  </delete>
 
  <delete id="deleteAlarmItemByIds" parameterType="String">
    delete from alarm_item where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
 
  <select id="selectAlarmItemtingById" parameterType="String" resultMap="AlarmItemResult">
    <include refid="selectAlarmItemVo"/>
    where dwid = #{id}
  </select>
 
  <update id="updateStartStop">
    update alarm_item SET start_stop=#{flag},update_time=now(),update_by=#{update_by} where dwid in
    <foreach item="id" collection="ids" open="(" separator="," close=")">
      #{id}
    </foreach>
  </update>
  <select id="getStartStop" resultType="String">
    select DISTINCT start_stop
    from alarm_item
    where dwid = #{indexid};
  </select>
 
  <update id="updateLimitVal">
    delete from alarm_item where dwid = #{id};
    <foreach collection="data" item="item" index="index" separator=";">
      insert into alarm_item
      <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null  and id != ''">id,</if>
        <if test="item.indexId != null  and item.indexId != ''">dwid,</if>
        <if test="item.state != null  and item.state != ''">start_stop,</if>
        <if test="item.timeSlotVal != null  and item.timeSlotVal != ''">time_slot,</if>
        <if test="item.limitTypeVal != null  and item.limitTypeVal != ''">limit_type,</if>
        <if test="item.limitVal != null  and item.limitVal != ''">limit_val,</if>
        <if test="item.alarmLevel != null  and item.alarmLevel != ''">alarm_level,</if>
        <if test="item.nodeId != null  and item.nodeId != ''">node_id,</if>
        <if test="id != null  and id != ''">update_time,</if>
        <if test="id != null  and id != ''">create_time,</if>
        <if test="id != null  and id != ''">update_by,</if>
        <if test="id != null  and id != ''">create_by,</if>
        <if test="id != null  and id != ''">alarm_code,</if>
      </trim>
      <trim prefix="values (" suffix=")" suffixOverrides=",">
        <if test="id != null  and id != ''">#{item.id},</if>
        <if test="item.indexId != null  and item.indexId != ''">#{item.indexId},</if>
        <if test="item.state != null  and item.state != ''">#{item.state},</if>
        <if test="item.timeSlotVal != null  and item.timeSlotVal != ''">#{item.timeSlotVal},</if>
        <if test="item.limitTypeVal != null  and item.limitTypeVal != ''">#{item.limitTypeVal},</if>
        <if test="item.limitVal != null  and item.limitVal != ''">#{item.limitVal},</if>
        <if test="item.alarmLevel != null  and item.alarmLevel != ''">#{item.alarmLevel},</if>
        <if test="item.nodeId != null  and item.nodeId != ''">#{item.nodeId},</if>
        <if test="id != null  and id != ''">now(),</if>
        <if test="id != null  and id != ''">now(),</if>
        <if test="id != null  and id != ''">#{username},</if>
        <if test="id != null  and id != ''">#{username},</if>
        <if test="id != null  and id != ''">#{item.alarmCode},</if>
      </trim>
    </foreach>
  </update>
<!--  <insert id="updateLimitValNoDel">-->
<!--    <foreach collection="data" item="item" index="index" separator=";">-->
<!--      insert into alarm_item-->
<!--      <trim prefix="(" suffix=")" suffixOverrides=",">-->
<!--        <if test="id != null  and id != ''">id,</if>-->
<!--        <if test="item.indexId != null  and item.indexId != ''">dwid,</if>-->
<!--        <if test="item.state != null  and item.state != ''">start_stop,</if>-->
<!--        <if test="item.timeSlotVal != null  and item.timeSlotVal != ''">time_slot,</if>-->
<!--        <if test="item.limitTypeVal != null  and item.limitTypeVal != ''">limit_type,</if>-->
<!--        <if test="item.limitVal != null  and item.limitVal != ''">limit_val,</if>-->
<!--        <if test="item.alarmLevel != null  and item.alarmLevel != ''">alarm_level,</if>-->
<!--        <if test="item.nodeId != null  and item.nodeId != ''">node_id,</if>-->
<!--        <if test="id != null  and id != ''">update_time,</if>-->
<!--        <if test="id != null  and id != ''">create_time,</if>-->
<!--        <if test="id != null  and id != ''">update_by,</if>-->
<!--        <if test="id != null  and id != ''">create_by,</if>-->
<!--        <if test="id != null  and id != ''">alarm_code,</if>-->
<!--      </trim>-->
<!--      <trim prefix="values (" suffix=")" suffixOverrides=",">-->
<!--        <if test="id != null  and id != ''">#{item.id},</if>-->
<!--        <if test="item.indexId != null  and item.indexId != ''">#{item.indexId},</if>-->
<!--        <if test="item.state != null  and item.state != ''">#{item.state},</if>-->
<!--        <if test="item.timeSlotVal != null  and item.timeSlotVal != ''">#{item.timeSlotVal},</if>-->
<!--        <if test="item.limitTypeVal != null  and item.limitTypeVal != ''">#{item.limitTypeVal},</if>-->
<!--        <if test="item.limitVal != null  and item.limitVal != ''">#{item.limitVal},</if>-->
<!--        <if test="item.alarmLevel != null  and item.alarmLevel != ''">#{item.alarmLevel},</if>-->
<!--        <if test="item.nodeId != null  and item.nodeId != ''">#{item.nodeId},</if>-->
<!--        <if test="id != null  and id != ''">now(),</if>-->
<!--        <if test="id != null  and id != ''">now(),</if>-->
<!--        <if test="id != null  and id != ''">#{username},</if>-->
<!--        <if test="id != null  and id != ''">#{username},</if>-->
<!--        <if test="id != null  and id != ''">#{item.alarm_code},</if>-->
<!--      </trim>-->
<!--    </foreach>-->
<!--  </insert>-->
  <insert id="updateLimitValNoDel">
    insert into alarm_item (id, create_time, create_by, update_time, update_by, dwid, start_stop, time_slot,
        limit_type,  limit_val, alarm_level, node_id, alarm_code)
    values 
    <foreach collection="data" item="item" index="index" separator=",">
        (#{item.id},now(),#{username},now(),#{username},#{item.indexId},#{item.state},#{item.timeSlotVal},
        #{item.limitTypeVal},#{item.limitVal},#{item.alarmLevel},#{item.nodeId},#{item.alarmCode})
    </foreach>
  </insert>
  <select id="selectCountById" resultType="int">
    select count(id)
    from alarm_item
    where dwid = #{id};
  </select>
  <delete id="deleteAllLimitVal">
    delete
    from alarm_item
    where dwid = #{id};
  </delete>
  <select id="getSettingCount" resultType="int">
    select count(id)
    from alarm_item
    where dwid = #{id};
  </select>
  <select id="getAllAlarmItem" resultMap="AlarmItemResult">
    select ai.*, ei.code as index_code
    from alarm_item ai
           left join energy_index ei on ai.dwid = ei.index_id
    where start_stop = '1';
  </select>
</mapper>