zxl
2026-03-25 d1dfb6e35f38e27fd960dc3ad0130c8d0f5c39bb
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
<?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.tievd.jyz.mapper.OilEventMapper">
 
    <select id="monthlyAlarmCount" parameterType="map" resultType="int">
        select
            count(1)
        from
            t_oil_event toe
        where
            toe.org_code like concat(#{orgCode}, '%')
          and date_format(toe.event_time, '%Y-%m') = #{date}
    </select>
 
    <select id="alarmStat" parameterType="map" resultType="com.tievd.jyz.entity.vo.AlarmOverviewVO">
        select
            count(toe.id) alarmCount,
            count(toe.audit_time) dealedAlarmCount,
            count(if(toe.audit_result = 1, 1, null)) confirmedAlarmCount
        from
            t_oil_event toe
        where
            toe.org_code like concat(#{orgCode}, '%')
          and date_format(toe.event_time, '%Y-%m-%d') = #{date}
    </select>
 
    <select id="alarmStatRange" parameterType="map" resultType="com.tievd.jyz.dto.AlarmStatDTO">
        select
        count(toe.id) alarmCount,
        count(if(toe.audit_result = 1, 1, null)) confirmedAlarmCount,
        a.date
        from
        (
        select
        date_format(date_add(#{endDay}, interval -t.help_topic_id day), '%Y-%m-%d') as 'date'
        from
        mysql.help_topic t
        where t.help_topic_id <![CDATA[ < ]]> #{intervalDay}
        ) as a
        left join t_oil_event toe on toe.event_day = a.date
        and toe.org_code like concat(#{orgCode}, '%')
        group by a.date
        order by a.date asc
    </select>
 
    <select id="regionAlarmStat" parameterType="map" resultType="com.tievd.jyz.dto.AlarmStatDTO">
        select
            sum(b.alarmCount) alarmCount,
            sum(b.confirmedAlarmCount) confirmedAlarmCount,
            sum(b.dealedAlarmCount) dealedAlarmCount,
            departName,
            orgCode
        from
            (
                select
                    count(toe.id) alarmCount,
                    count(if(toe.audit_result != 0, 1, null)) dealedAlarmCount,
                    count(if(toe.audit_result = 1, 1, null)) confirmedAlarmCount,
                    sd.depart_name departName,
                    sd.org_code orgCode
                from
                    sys_depart sd
                        left join t_oil_event toe on
                                sd.org_code = toe.org_code
                            and toe.event_day = #{date}
                where
                    sd.org_category = 3
                  and sd.org_code like concat(#{orgCode}, '%')
                group by sd.org_code
                union all
                select
                    count(toe.id) alarmCount,
                    count(if(toe.audit_result != 0, 1, null)) dealedAlarmCount,
                    count(if(toe.audit_result = 1, 1, null)) confirmedAlarmCount,
                    sd.depart_name departName,
                    sd.org_code orgCode
                from
                    sys_depart sd
                        left join t_oilout_event toe on
                                sd.org_code = toe.org_code
                            and toe.event_day = #{date}
                            and toe.event_type = 2
                where
                    sd.org_category = 3
                  and sd.org_code like concat(#{orgCode}, '%')
                group by sd.org_code
            ) b
        group by orgCode
        order by alarmCount desc, confirmedAlarmCount desc
        limit #{limit}
    </select>
 
    <select id="alarmTypeStatByDay" parameterType="map" resultType="com.tievd.jyz.dto.AlarmTypeStatDTO">
        select
            toe.algorithm_name,
            count(toe.id) alarmCount
        from
            t_oil_event toe
        where
            toe.org_code like concat(#{orgCode},'%')
          and toe.event_day = #{date}
        group by toe.algorithm_code
        union all
        select
            toe.algorithm_name,
            count(toe.id) alarmCount
        from
            t_oilout_event toe
        where
            toe.org_code like concat(#{orgCode},'%')
          and toe.event_day = #{date}
          and toe.event_type = 2
        group by toe.algorithm_code
        limit 6
    </select>
 
    <select id="alarmTypeStatByMonth" parameterType="map" resultType="com.tievd.jyz.dto.AlarmTypeStatDTO">
        select
            toe.algorithm_name,
            count(toe.id) alarmCount
        from
            t_oil_event toe
        where
            toe.org_code like concat(#{orgCode},'%')
          and date_format(toe.event_day, '%Y-%m') = #{date}
        group by toe.algorithm_code
        union all
        select
            toe.algorithm_name,
            count(toe.id) alarmCount
        from
            t_oilout_event toe
        where
            toe.org_code like concat(#{orgCode},'%')
          and date_format(toe.event_day, '%Y-%m') = #{date}
          and toe.event_type = 2
        group by toe.algorithm_code
        limit 6
    </select>
 
    <select id="getLatestAlarm" parameterType="map" resultType="com.tievd.jyz.entity.vo.AlarmEventVO">
        select
            *
        from
            (
                select
                    toe.org_name departName,
                    toe.camera_name cameraName,
                    toe.event_time alarmTime,
                    '异常事件' eventType,
                    toe.algorithm_name algorithmName
                from
                    t_oil_event toe
                where
                    toe.org_code like concat(#{orgCode},'%')
                  and toe.event_day = #{date}
                union all
                select
                    toe.org_name departName,
                    toe.camera_name cameraName,
                    toe.event_time alarmTime,
                    '异常告警' eventType,
                    toe.algorithm_name algorithmName
                from
                    t_oilout_event toe
                where
                    toe.org_code like concat(#{orgCode}, '%')
                  and toe.event_type = 2
                  and toe.event_day = #{date}
            ) a
        order by alarmTime desc
        limit #{limit}
    </select>
 
    <select id="alarmTrendStatRange" parameterType="map" resultType="com.tievd.jyz.dto.AlarmStatDTO">
        select
            count(toe.id) oilEventAlarmCount,
            a.date
        from
        (
            select
                date_format(date_add(#{endDay}, interval -t.help_topic_id day), '%Y-%m-%d') as 'date'
            from
                mysql.help_topic t
            where
                t.help_topic_id <![CDATA[ < ]]> #{intervalDay}
        ) as a
        left join t_oil_event toe on
            toe.event_day = a.date
            and toe.org_code like concat(#{orgCode}, '%')
        group by a.date
        order by a.date asc
    </select>
 
    <select id="getAlarmRankingByDay" parameterType="map" resultType="com.tievd.jyz.entity.vo.OrgAlarmCountVO">
        select
            cameraCode,
            cameraName,
            alarmCount
        from
            (
                select
                    tc.code cameraCode,
                    tc.name cameraName,
                    count(toe.id) alarmCount
                from
                    t_camera tc
                        left join t_oil_event toe on
                        toe.camera_code = tc.code
                where
                        toe.event_day =
                        #{date} and toe.org_code like concat(#{orgCode}, '%') group by tc.code
                union all
                select
                    tc.code cameraCode,
                    tc.name cameraName,
                    count(toe.id) alarmCount
                from
                    t_camera tc
                        left join t_oilout_event toe on
                        toe.camera_code = tc.code
                where
                        toe.event_day =
                        #{date} and toe.event_type = 2 and toe.org_code like concat(#{orgCode}, '%') group by tc.code
            ) a
        order by alarmCount desc
        limit #{limit}
    </select>
 
    <select id="getAlarmRankingByMonth" parameterType="map" resultType="com.tievd.jyz.entity.vo.OrgAlarmCountVO">
        select
            cameraCode,
            cameraName,
            alarmCount
        from
            (
                select
                    tc.code cameraCode,
                    tc.name cameraName,
                    count(toe.id) alarmCount
                from
                    t_camera tc
                        left join t_oil_event toe on
                        toe.camera_code = tc.code
                where
                    date_format(toe.event_day, '%Y-%m') = #{date}
                  and toe.org_code like concat(#{orgCode}, '%')
                group by tc.code
                union all
                select
                    tc.code cameraCode,
                    tc.name cameraName,
                    count(toe.id) alarmCount
                from t_camera tc
                         left join t_oilout_event toe on
                    toe.camera_code = tc.code
                where
                    date_format(toe.event_day, '%Y-%m') = #{date}
                  and toe.event_type = 2
                  and toe.org_code like concat(#{orgCode}, '%')
                group by tc.code
            ) a
        order by alarmCount desc
        limit #{limit}
    </select>
 
    <select id="getPartirionAlarmStat" parameterType="map" resultType="com.tievd.jyz.entity.vo.PartitionAlarmStatVO">
        select
            toe.event_address partitionName,
            count(toe.id) alarmCount,
            count(if(toe.audit_result = 1, 1, null)) confirmedAlarmCount
        from
            t_oil_event toe
        where
            toe.org_code like concat(#{orgCode}, '%')
          and toe.event_day = #{date}
        group by toe.event_address
        union all
        select
            1 partitionName,
            count(toe.id) alarmCount,
            count(if(toe.audit_result = 1, 1, null)) confirmedAlarmCount
        from
            t_oilout_event toe
        where
            toe.org_code like concat(#{orgCode}, '%')
          and toe.event_day = #{date}
          and toe.event_type = 2
    </select>
 
    <select id="eventMergeList" parameterType="map" resultType="com.tievd.jyz.entity.vo.MergeEventVo">
        select
        id, event_time, algorithm_code, algorithm_name, camera_code, camera_name, device_id, device_name, org_code, org_name, img_uid, img_path, video_path, audit_user, audit_result, audit_comment, audit_time, create_time,
        1 type,
        event_address eventAddress,
        null eventPhrase
        from t_oil_event
        where DATE(event_time) = CURRENT_DATE and img_path is not null and video_path is not null
        <if test="current != null"> and create_time > #{current}</if>
        <if test="cameraCode != null and cameraCode !=''"> and camera_code = #{cameraCode}</if>
        union all
        select
        id, event_time, algorithm_code, algorithm_name, camera_code, camera_name, device_id, device_name, org_code, org_name, img_uid, img_path, video_path, audit_user, audit_result, audit_comment, audit_time, create_time,
        2 type,
        null eventAddress,
        event_phrase eventPhrase
        from t_oilout_event
        where DATE(event_time) = CURRENT_DATE and event_type=2
        <if test="current != null"> and create_time > #{current}</if>
        <if test="cameraCode != null and cameraCode !=''"> and camera_code = #{cameraCode}</if>
        ORDER BY event_time desc
        <if test="limit != null">limit #{limit}</if>
    </select>
</mapper>