zhanghua
2023-09-08 7ef4892f9f24f941aca37e6b3991b808a0aca619
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?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.ycl.mapper.caseHandler.BaseCaseMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ycl.entity.caseHandler.BaseCase">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="event_source" property="eventSource"/>
        <result column="category" property="category"/>
        <result column="street_id" property="streetId"/>
        <result column="community_id" property="communityId"/>
        <result column="site" property="site"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="alarm_time" property="alarmTime"/>
        <result column="create_user" property="createUser"/>
        <result column="state" property="state"/>
        <result column="handling_opinion" property="handlingOpinion"/>
        <result column="remark" property="remark"/>
        <result column="audit_opinion" property="auditOpinion"/>
        <result column="final_opinion" property="finalOpinion"/>
        <result column="create_time" property="createTime"/>
    </resultMap>
    <resultMap type="com.ycl.entity.caseHandler.BaseCase" id="CondMapResultMap" extends="BaseResultMap">
        <result column="category_text" property="categoryText"/>
        <result column="street_text" property="streetText"/>
        <result column="community_text" property="communityText"/>
        <result column="create_user_text" property="createUserText"/>
    </resultMap>
 
    <!-- 通用查询映射结果 -->
    <resultMap id="settingsResultMap" type="com.ycl.vo.IllegalBuildingSettingVO">
        <id column="number" property="number"/>
        <result column="type" property="type"/>
        <result column="typeFirst" property="typeFirst"/>
        <result column="typeSecond" property="typeSecond"/>
        <result column="typeThird" property="typeThird"/>
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , code, event_source, category, street_id, community_id, site, longitude, latitude, alarm_time, create_user, state, handling_opinion, remark, audit_opinion, final_opinion, create_time
    </sql>
 
    <select id="listViolationsPage" resultType="com.ycl.vo.casePool.CasePoolViolationVO">
        SELECT
        ubc.`id`,
        ubc.`code`,
        ubc.event_source,
        uv.action_cause,
        t3.name as category,
        t4.name as type,
        t5.region_name as street,
        ubc.site,
        ubc.alarm_time,
        ubc.close_time
        FROM
        `ums_base_case` AS ubc
        JOIN ums_violations AS uv ON ubc.id = uv.id
        LEFT JOIN ums_data_dictionary AS t3 ON uv.category_id = t3.id
        LEFT JOIN ums_data_dictionary AS t4 ON uv.type_id = t4.id
        LEFT JOIN ums_sccg_region t5 ON ubc.street_id = t5.id
        <where>
            <if test="state!=null and state!=6">
                ubc.state=#{state}
            </if>
            <if test="state!=null and state==6">
                ubc.state &gt;=#{state}
            </if>
            <if test="resource!=null">
                and ubc.event_source=#{resource}
            </if>
            <if test="type!=null">
                and ubc.category=#{type}
            </if>
            <if test="code!=null">
                and ubc.code=#{code}
            </if>
            <if test="categoryBig != null">
                and t3.name like concat('%', #{categoryBig},'%')
            </if>
            <if test="categorySmall != null">
                and t4.name like concat('%', #{categorySmall},'%')
            </if>
            <if test="street != null">
                and ubc.street_id = #{street}
            </if>
            <if test="site">
                and ubc.site like concat('%', #{site},'%')
            </if>
            <if test="startTime !='' and endTime !='' and startTime!=null and endTime !=null">
                and ubc.create_time between #{startTime} and #{endTime}
            </if>
            <if test="violationsTypeId !=null">
                and uv.grade_id = #{violationsTypeId}
            </if>
            <if test="videoId !=null">
                and uv.video_point_id = #{videoId}
            </if>
        </where>
        order by id desc
    </select>
 
    <select id="listIllegalBuildingsPage" resultType="com.ycl.vo.casePool.CasePoolIllegalBuildingVO">
        SELECT
        ubc.`id`,
        ubc.`code`,
        ubc.event_source,
        t1.name as category,
        ubc.site,
        t2.region_name as community,
        uib.building_high,
        uib.building_width,
        uib.building_length,
        uib.building_area,
        uib.materials
        FROM
        `ums_base_case` AS ubc
        left JOIN ums_illegal_building AS uib ON ubc.id = uib.base_case_id
        left JOIN ums_data_dictionary AS t1 ON uib.category_id = t1.id
        left JOIN ums_sccg_region t2 ON ubc.community_id = t2.id
        <where>
            <if test="state!=null and state!=6">
                ubc.state=#{state}
            </if>
            <if test="state!=null and state==6">
                ubc.state &gt;=#{state}
            </if>
            <if test="resource!=null">
                and ubc.event_source=#{resource}
            </if>
            <if test="type!=null">
                and ubc.category=#{type}
            </if>
        </where>
        order by ubc.id desc
    </select>
 
 
    <select id="selectCondMap" parameterType="map" resultMap="CondMapResultMap">
        SELECT ubc.*,
               udd.name         category_text,
               usr.region_name  street_text,
               usr2.region_name community_text,
               ua.username      create_user_text
        FROM ums_base_case ubc
                 LEFT JOIN ums_data_dictionary udd on ubc.category = udd.id
                 LEFT JOIN ums_sccg_region usr on ubc.street_id = usr.id
                 LEFT JOIN ums_sccg_region usr2 on ubc.community_id = usr2.id
                 LEFT JOIN ums_admin ua on ubc.create_user = ua.id
        WHERE ubc.`code` = #{code}
    </select>
 
    <select id="selectBaseCasePage" resultType="com.ycl.entity.caseHandler.BaseCase">
        select t1.*,
        t3.region_name community_text
        from ums_base_case t1
        left join ums_sccg_region t3 on t1.community_id=t3.id
        <where>
            <if test="categories != null">
                t1.category = #{categories}
            </if>
            <if test="communityId != null">
                and t1.community_id = #{communityId}
            </if>
            <if test=" streetId != null">
                and t1.street_id = #{streetId}
            </if>
            <if test="code != null and code !=''">
                and t1.code like concat('%',#{code},'%')
            </if>
            <if test="code != null and code !=''">
                and t1.code like concat('%',#{code},'%')
            </if>
            <if test="state != null and state!=''">
                and t1.state =#{state}
            </if>
         <if test="site != null and site!=''">
                and t1.site like concat('%',#{site},'%')
            </if>
            <if test="startTime!=null and endTime !=null">
                and t1.create_time between #{startTime} and #{endTime}
            </if>
        </where>
        order by t1.alarm_time desc
    </select>
 
    <select id="selectViolationPage" resultType="com.ycl.vo.casePool.QueryForViolationVO"
            parameterType="com.ycl.dto.caseHandler.QueryForViolationParam">
        SELECT
        t1.`code`,
        t1.alarm_time,
        t1.handling_opinion,
        CASE
        t1.event_source
        WHEN 1 THEN
        "视频巡查"
        WHEN 2 THEN
        "人工上报"
        END AS event_source,
        t1.site,
        CASE
        t1.state
        WHEN 7 THEN
        "待审核"
        WHEN 8 THEN
        "已审核"
        END AS state,
        t3.`name` as categoryName,
        t4.`name` AS typeName,
        t5.`name` as gradeName,
        t2.car_number,
        t6.region_name as communityName,
        t7.region_name as streetName,
        t8.url,
        t9.address
        FROM
        ums_base_case t1
        LEFT JOIN ums_violations t2 on t1.id=t2.id
        LEFT JOIN ums_data_dictionary t3 on t3.id=t2.category_id
        LEFT JOIN ums_data_dictionary t4 on t4.id=t2.type_id
        LEFT JOIN ums_data_dictionary t5 on t5.id=t2.grade_id
        LEFT JOIN ums_sccg_region t6 on t6.id=t1.community_id
        LEFT JOIN ums_sccg_region t7 on t7.id=t1.street_id
        LEFT JOIN ums_image_resources t8 on t8.belong_to_id=t1.id
        LEFT JOIN ums_video_point t9 on t9.id=t2.video_point_id
        <where>
            <if test="queryForViolationParam.eventSource != null">
                and t1.event_source=#{queryForViolationParam.eventSource}
            </if>
            <if test="queryForViolationParam.categoryId != null">
                and t2.category_id=#{queryForViolationParam.categoryId}
            </if>
            <if test="queryForViolationParam.startTime != null and queryForViolationParam.startTime !='' and queryForViolationParam.endTime !=null and queryForViolationParam.endTime !=''">
                and t1.alarm_time between #{queryForViolationParam.startTime} and #{queryForViolationParam.endTime}
            </if>
            <if test="queryForViolationParam.code != null and queryForViolationParam.code != '' ">
                and t1.code like concat('%',#{queryForViolationParam.code},'%')
            </if>
            <if test=" queryForViolationParam.typeId!= null">
                and t2.type_id=#{v.typeId}
            </if>
            <if test="queryForViolationParam.gradeId != null">
                and t2.grade_id=#{queryForViolationParam.gradeId}
            </if>
            <if test="queryForViolationParam.streetId != null">
                and t1.street_id=#{queryForViolationParam.streetId}
            </if>
            <if test="queryForViolationParam.communityId != null">
                and t1.community_id=#{queryForViolationParam.communityId}
            </if>
            <if test="queryForViolationParam.state != null">
                and t1.state=#{queryForViolationParam.state}
            </if>
            <if test="queryForViolationParam.carNumber != null and  queryForViolationParam.carNumber!=''">
                and t2.car_number like concat('%',#{queryForViolationParam.carNumber},'%')
            </if>
            <if test="queryForViolationParam.videoPointId != null">
                and t2.video_point_id=#{queryForViolationParam.videoPointId}
            </if>
            <if test="queryForViolationParam.handlingOpinion != null and queryForViolationParam.handlingOpinion !=''">
                and t1.handling_opinion like concat('%',#{queryForViolationParam.handlingOpinion},'%')
            </if>
        </where>
 
    </select>
 
    <select id="selectVideoInspection" resultType="com.ycl.vo.casePool.BaseCaseVO">
        SELECT t1.id as baseId,
        t1.`code`,
        t3.`name`,
        t3.url_address,
        t3.longitude,
        t3.latitude,
        t4.pic_data,
        t5.`name` as grade,
        t3.address,
        t3.plat_resource_id as platResourceId,
        t3.code as videoCode,
        t1.alarm_time as alarmTime,
        t1.alarm_time as currentAlarmTime,
        t4.algo_name as algoName
        FROM ums_base_case t1
        LEFT JOIN ums_violations t2 ON t1.id = t2.id
        LEFT JOIN ums_video_point t3 on t2.video_point_id = t3.id
        LEFT JOIN ums_video_alarm_report t4 on t4.id = t2.video_alarm_report_id
        LEFT JOIN ums_data_dictionary t5 on t5.id = t2.grade_id
        WHERE t1.state = 1
        <if test="gradeId!=null">
            and t2.grade_id = #{gradeId}
        </if>
        <if test="videoId!=null">
            and t2.video_point_id = #{videoId}
        </if>
        <if test="beginTime!=null and beginTime!=''">
            and t1.alarm_time between #{beginTime} and #{endTime}
        </if>
        group by t1.id
        order by t1.id desc
    </select>
 
    <select id="selectRegisterCount" resultType="java.lang.Long">
        select count(1)
        from ums_base_case
        where state in (2, 6, 7, 8, 9)
          and to_days(create_time) = TO_DAYS(now());
    </select>
 
    <select id="selectStudyCount" resultType="java.lang.Long">
        select count(1)
        from ums_base_case
        where state = 3
          and to_days(create_time) = TO_DAYS(now());
    </select>
 
    <select id="dayCount" resultType="java.lang.Integer">
        SELECT
            count(1)
        FROM
            ums_base_case
        WHERE
            create_time BETWEEN CONCAT( CURDATE(), ' 00:00:00' )
                AND CONCAT( CURDATE(), ' 23:59:59' );
    </select>
    <select id="weekCount" resultType="java.lang.Integer">
        SELECT
            count( 1 )
        FROM
            ums_base_case
        WHERE
                YEARWEEK(
                        date_format( create_time, '%Y-%m-%d' ), 1) = YEARWEEK(
                        now(), 1);
    </select>
    <select id="dispatchCount" resultType="java.lang.Integer">
        select count(1)
        FROM ums_base_case t1
                 LEFT JOIN ums_dispose_record t2 ON t1.id = t2.base_case_id
        WHERE t2.workflow_config_step_id = 1
    </select>
    <select id="alCount" resultType="java.lang.Integer">
        select count(1)
        FROM ums_base_case
        WHERE event_source = 1;
    </select>
    <select id="selectEventList" resultType="com.ycl.vo.cockpit.enforcementEvents.EventVO">
        SELECT
        t1.alarm_time,
        t1.longitude,
        t1.latitude,
        dd.name AS type,
        ( CASE WHEN t1.event_source = 1 THEN "视频巡查" WHEN t1.event_source = 2 THEN "网格巡查" ELSE "其他" END ) AS source,
        t1.site AS address,
        t2.description,
        t3.`name` AS point,
        t4.pic_data AS picture,
        (case
        WHEN t1.state = 0 THEN '待处理'
        WHEN t1.state = 1 THEN '报警'
        WHEN t1.state = 2 THEN '上报'
        WHEN t1.state = 3 THEN '再学习'
        WHEN t1.state = 4 THEN '暂不处理'
        WHEN t1.state = 5 THEN '立案'
        WHEN t1.state = 6 THEN '调度'
        WHEN t1.state = 7 THEN '处置'
        WHEN t1.state = 8 THEN '核查'
        WHEN t1.state = 9 THEN '结案'
        END) `alarmAdvice` ,
        pdd.`name` as grade
        FROM
        ums_base_case t1
        LEFT JOIN ums_violations t2 ON t1.id = t2.id
        LEFT JOIN ums_video_point t3 ON t3.id = t2.video_point_id
        LEFT JOIN ums_video_alarm_report t4 ON t4.id = t2.video_alarm_report_id
        LEFT JOIN ums_data_dictionary dd on t2.grade_id = dd.id
        LEFT JOIN ums_data_dictionary pdd on pdd.id = dd.parent_id
        <where>
            t1.category=1
            <if test="beginTime !=''and beginTime!=null and endTime!=''and endTime!=null">
                and t1.create_time BETWEEN #{beginTime}
                AND #{endTime}
            </if>
 
        </where>
        order by t1.id desc
    </select>
    <select id="areaCount" resultType="com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO">
        SELECT t2.region_name name,
               COUNT(1) AS count
        FROM
            `ums_base_case` t1
            LEFT JOIN ums_sccg_region t2
        ON t1.street_id = t2.id
        GROUP BY
            street_id
    </select>
 
    <select id="selectDelayVOList" resultType="com.ycl.dto.cockpitManage.DelayDO">
        SELECT t1.`code`,
               t3.description,
               t2.start_time,
               t2.end_time,
               t2.limit_time
        FROM `ums_base_case` t1
                 LEFT JOIN ums_dispose_record t2 ON t1.id = t2.base_case_id
                 LEFT JOIN ums_violations t3 on t1.id = t3.id
        WHERE t2.workflow_config_step_id IN (1, 2)
    </select>
 
    <select id="selectType" resultType="com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO">
        SELECT IFNULL(t2.`name`, "其他") as name,
               COUNT(1) as count
        FROM
            ums_violations t1
            LEFT JOIN ums_data_dictionary t2
        ON t1.grade_id = t2.id
        GROUP BY
            t1.grade_id
        ORDER BY         COUNT(1) desc
    </select>
 
    <select id="selectLastMonthCount" resultType="java.lang.Long">
        SELECT
        count(1)
        FROM
        ums_base_case
        WHERE
        state in
        <foreach collection="list" open="(" separator="," close=")" item="state">
            #{state}
        </foreach>
        AND PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( create_time, '%Y%m' ) ) =1
    </select>
 
    <select id="selectRecentlyMonthCount" resultType="java.lang.Long">
        SELECT
        count(1)
        FROM
        ums_base_case
        WHERE
        state in
        <foreach collection="list" open="(" separator="," close=")" item="state">
            #{state}
        </foreach>
        AND PERIOD_DIFF( date_format( now( ), '%Y%m' ), date_format( create_time, '%Y%m' ) ) =0
    </select>
 
    <select id="selectOnTimeCaseCount" resultType="java.lang.Long">
        SELECT COUNT(1)
        FROM ums_dispose_record
        WHERE end_time &lt; limit_time
    </select>
 
    <select id="selectOnTimeCaseLastMonthCount" resultType="java.lang.Long">
        SELECT COUNT(1)
        FROM ums_dispose_record
        WHERE end_time &lt; limit_time
          AND PERIOD_DIFF(date_format(now(), '%Y%m'), date_format(create_time, '%Y%m')) = 1
    </select>
 
    <select id="selectOnTimeCaseRecentlyMonthCount" resultType="java.lang.Long">
        SELECT COUNT(1)
        FROM ums_dispose_record
        WHERE end_time &lt; limit_time
          AND PERIOD_DIFF(date_format(now(), '%Y%m'), date_format(create_time, '%Y%m')) = 0
    </select>
</mapper>