吉安感知网项目-后端
linwei
2026-01-14 bc1a6bb5bb2803ed6a5669a976bf2b47f3dacfca
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<?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="org.sxkj.fw.area.mapper.FwAreaDivideMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="fwAreaDivideResultMap" type="org.sxkj.fw.area.vo.FwAreaDivideVO">
        <result column="id" property="id"/>
        <result column="area_name" property="areaName"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="area_size" property="areaSize"/>
        <result column="geom" property="geom"/>
        <result column="area_type" property="areaType"/>
        <result column="trigger_condition" property="triggerCondition"/>
        <result column="response_mechanism" property="responseMechanism"/>
        <result column="control_level" property="controlLevel"/>
        <result column="police_station_id" property="policeStationId"/>
        <result column="device_ids" property="deviceIds"/>
        <result column="fly_date_start" property="flyDateStart"/>
        <result column="fly_date_end" property="flyDateEnd"/>
        <result column="area_code" property="areaCode"/>
        <result column="police_station_name" property="policeStationName"/>
        <result column="police_station_contact_person" property="policeStationContactPerson"/>
        <result column="police_station_contact_phone" property="policeStationContactPhone"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
 
    <resultMap id="fwAreaDivideStatisticsResultMap" type="org.sxkj.fw.area.vo.FwAreaDivideStatisticsVO">
        <result column="id" property="id"/>
        <result column="area_name" property="areaName"/>
        <result column="area_type" property="areaType"/>
        <result column="scene_name" property="sceneName"/>
        <result column="scene_type" property="sceneType"/>
        <result column="device_count" property="deviceCount"/>
        <result column="alarm_count" property="alarmCount"/>
        <result column="counter_count" property="counterCount"/>
        <result column="counter_success_count" property="counterSuccessCount"/>
        <result column="control_effect" property="controlEffect"/>
    </resultMap>
 
 
    <select id="selectFwAreaDividePage" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.longitude,
        ad.latitude,
        ad.area_size,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
        ps.station_name as police_station_name,
        ad.create_user,
        ad.create_dept,
        ad.create_time,
        ad.update_user,
        ad.update_time,
        ad.status,
        ad.is_deleted
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0
        <where>
            ad.is_deleted = 0
            <if test="param2.id != null and param2.id != ''">
                and ad.id = #{param2.id}
            </if>
            <if test="param2.areaName != null and param2.areaName != ''">
                and ad.area_name like concat('%', #{param2.areaName}, '%')
            </if>
            <if test="param2.longitude != null and param2.longitude != ''">
                and ad.longitude = #{param2.longitude}
            </if>
            <if test="param2.latitude != null and param2.latitude != ''">
                and ad.latitude = #{param2.latitude}
            </if>
            <if test="param2.areaSize != null and param2.areaSize != ''">
                and ad.area_size = #{param2.areaSize}
            </if>
            <if test="param2.areaType != null and param2.areaType != ''">
                and ad.area_type = #{param2.areaType}
            </if>
            <if test="param2.triggerCondition != null and param2.triggerCondition != ''">
                and ad.trigger_condition = #{param2.triggerCondition}
            </if>
            <if test="param2.responseMechanism != null and param2.responseMechanism != ''">
                and ad.response_mechanism = #{param2.responseMechanism}
            </if>
            <if test="param2.controlLevel != null and param2.controlLevel != ''">
                and ad.control_level = #{param2.controlLevel}
            </if>
            <if test="param2.policeStationId != null and param2.policeStationId != ''">
                and ad.police_station_id = #{param2.policeStationId}
            </if>
            <if test="param2.deviceIds != null and param2.deviceIds != ''">
                and ad.device_ids = #{param2.deviceIds}
            </if>
            <if test="param2.flyDateStart != null and param2.flyDateStart != ''">
                and ad.fly_date_start &gt;= #{param2.flyDateStart}
            </if>
            <if test="param2.flyDateEnd != null and param2.flyDateEnd != ''">
                and ad.fly_date_end &lt;= #{param2.flyDateEnd}
            </if>
            <if test="param2.areaCode != null and param2.areaCode != ''">
                and ad.area_code = #{param2.areaCode}
            </if>
        </where>
    </select>
 
    <select id="selectFwAreaDivideList" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.longitude,
        ad.latitude,
        ad.area_size,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
        ps.station_name as police_station_name,
        ad.create_user,
        ad.create_dept,
        ad.create_time,
        ad.update_user,
        ad.update_time,
        ad.status,
        ad.is_deleted
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0
        <where>
            ad.is_deleted = 0
            <if test="filterSelected != null and filterSelected == 1">
                and (
                    not exists (
                        select 1
                        from ja_fw_defense_scene ds
                        where ds.is_deleted = 0
                          and ds.area_divide_ids is not null
                          and ds.area_divide_ids != ''
                          and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
                    )
                    <if test="sceneId != null">
                        or exists (
                            select 1
                            from ja_fw_defense_scene ds
                            where ds.is_deleted = 0
                              and ds.id = #{sceneId}
                              and ds.area_divide_ids is not null
                              and ds.area_divide_ids != ''
                              and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
                        )
                    </if>
                )
            </if>
            <if test="sceneId != null and (filterSelected == null or filterSelected != 1)">
                and exists (
                    select 1
                    from ja_fw_defense_scene ds
                    where ds.is_deleted = 0
                      and ds.id = #{sceneId}
                      and ds.area_divide_ids is not null
                      and ds.area_divide_ids != ''
                      and find_in_set(ad.id, replace(ds.area_divide_ids, ' ', ''))
                )
            </if>
        </where>
    </select>
 
    <select id="selectFwAreaDivideListByDeviceIds" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.device_ids
        from ja_fw_area_divide ad
        <where>
            ad.is_deleted = 0
            and ad.device_ids is not null
            and ad.device_ids != ''
            <if test="deviceIds != null and deviceIds.size > 0">
                and (
                    <foreach collection="deviceIds" item="deviceId" separator=" or ">
                        find_in_set(#{deviceId}, replace(ad.device_ids, ' ', ''))
                    </foreach>
                )
            </if>
        </where>
    </select>
 
    <select id="selectFwDefenseSceneListByAreaIds" resultType="org.sxkj.fw.area.vo.FwDefenseSceneVO">
        select
        ds.id,
        ds.scene_name as sceneName,
        ds.area_divide_ids as areaDivideIds
        from ja_fw_defense_scene ds
        <where>
            ds.is_deleted = 0
            and ds.area_divide_ids is not null
            and ds.area_divide_ids != ''
            <if test="areaIds != null and areaIds.size > 0">
                and (
                    <foreach collection="areaIds" item="areaId" separator=" or ">
                        find_in_set(#{areaId}, replace(ds.area_divide_ids, ' ', ''))
                    </foreach>
                )
            </if>
        </where>
    </select>
 
    <select id="selectFwAreaDivideDetail" resultMap="fwAreaDivideResultMap">
        select
        ad.id,
        ad.area_name,
        ad.longitude,
        ad.latitude,
        ad.area_size,
        case
            when ad.geom is null then null
            when ST_SRID(ad.geom) is null or ST_SRID(ad.geom) = 0 then ST_AsText(ad.geom)
            else concat(ST_AsText(ST_SwapXY(ad.geom)), ' | ', ST_SRID(ad.geom))
        end as geom,
        ad.area_type,
        ad.trigger_condition,
        ad.response_mechanism,
        ad.control_level,
        ad.police_station_id,
        ad.device_ids,
        ad.fly_date_start,
        ad.fly_date_end,
        ad.area_code,
        ps.station_name as police_station_name,
        ps.contact_person as police_station_contact_person,
        ps.contact_phone as police_station_contact_phone,
        ad.create_user,
        ad.create_dept,
        ad.create_time,
        ad.update_user,
        ad.update_time,
        ad.status,
        ad.is_deleted
        from ja_fw_area_divide ad
        left join ja_fw_police_station ps on ps.id = ad.police_station_id and ps.is_deleted = 0
        where ad.is_deleted = 0
          and ad.id = #{id}
    </select>
 
    <select id="selectFwAreaDivideStatisticsPage" resultMap="fwAreaDivideStatisticsResultMap">
        select
        stats.id,
        stats.area_name,
        stats.area_type,
        stats.scene_name,
        stats.scene_type,
        stats.device_count,
        stats.alarm_count,
        stats.counter_count,
        stats.counter_success_count,
        case
            when stats.counter_count = 0 then '/'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 80 then '好'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 60 then '一般'
            else '差'
        end as control_effect
        from (
            select
            ad.id,
            ad.area_name,
            ad.area_type,
            (
                select group_concat(distinct ds.scene_name)
                from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
            ) as scene_name,
            (
                select group_concat(distinct ds.scene_type)
                from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
            ) as scene_type,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else length(replace(ad.device_ids, ' ', '')) - length(replace(replace(ad.device_ids, ' ', ''), ',', '')) + 1
            end as device_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_drone_alarm_record ar
                    join ja_fw_device d on d.id = ar.device_id and d.is_deleted = 0
                    where ar.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                )
            end as alarm_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                )
            end as counter_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and ee.counter_effect = 'success'
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                )
            end as counter_success_count
            from ja_fw_area_divide ad
            <where>
                ad.is_deleted = 0
                <if test="param2.id != null and param2.id != ''">
                    and ad.id = #{param2.id}
                </if>
                <if test="param2.areaName != null and param2.areaName != ''">
                    and ad.area_name like concat('%', #{param2.areaName}, '%')
                </if>
                <if test="param2.areaType != null and param2.areaType != ''">
                    and ad.area_type = #{param2.areaType}
                </if>
                <if test="param2.sceneType != null and param2.sceneType != ''">
                    and exists (
                        select 1
                        from ja_fw_defense_scene ds
                        where ds.is_deleted = 0
                          and find_in_set(ad.id, ds.area_divide_ids)
                          and ds.scene_type = #{param2.sceneType}
                    )
                </if>
                <if test="param2.areaCode != null and param2.areaCode != ''">
                    and ad.area_code = #{param2.areaCode}
                </if>
            </where>
        ) stats
    </select>
 
    <select id="selectFwAreaDivideStatisticsDetail" resultMap="fwAreaDivideStatisticsResultMap">
        select
        stats.id,
        stats.area_name,
        stats.area_type,
        stats.scene_name,
        stats.scene_type,
        stats.device_count,
        stats.alarm_count,
        stats.counter_count,
        stats.counter_success_count,
        case
            when stats.counter_count = 0 then '/'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 80 then '好'
            when stats.counter_success_count * 100.0 / stats.counter_count &gt;= 60 then '一般'
            else '差'
        end as control_effect
        from (
            select
            ad.id,
            ad.area_name,
            ad.area_type,
            (
                select group_concat(distinct ds.scene_name)
                from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
            ) as scene_name,
            (
                select group_concat(distinct ds.scene_type)
                from ja_fw_defense_scene ds
                where ds.is_deleted = 0
                  and find_in_set(ad.id, ds.area_divide_ids)
            ) as scene_type,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else length(replace(ad.device_ids, ' ', '')) - length(replace(replace(ad.device_ids, ' ', ''), ',', '')) + 1
            end as device_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_drone_alarm_record ar
                    join ja_fw_device d on d.id = ar.device_id and d.is_deleted = 0
                    where ar.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                )
            end as alarm_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                )
            end as counter_count,
            case
                when ad.device_ids is null or trim(ad.device_ids) = '' then 0
                else (
                    select count(1)
                    from ja_fw_effect_eval ee
                    join ja_fw_device d on d.id = ee.device_id and d.is_deleted = 0
                    where ee.is_deleted = 0
                      and ee.counter_effect = 'success'
                      and find_in_set(d.id, replace(ad.device_ids, ' ', ''))
                )
            end as counter_success_count
            from ja_fw_area_divide ad
            <where>
                ad.is_deleted = 0
                <if test="id != null and id != ''">
                    and ad.id = #{id}
                </if>
                <if test="areaCode != null and areaCode != ''">
                    and ad.area_code = #{areaCode}
                </if>
            </where>
        ) stats
    </select>
 
 
    <select id="exportFwAreaDivide" resultType="org.sxkj.fw.area.excel.FwAreaDivideExcel">
        SELECT
        id,
        area_name,
        longitude,
        latitude,
        area_size,
        concat(ST_AsText(geom), ' | ', ST_SRID(geom)) as geom,
        area_type,
        trigger_condition,
        response_mechanism,
        control_level,
        police_station_id,
        device_ids,
        fly_date_start,
        fly_date_end,
        area_code,
        create_user,
        create_dept,
        create_time,
        update_user,
        update_time,
        status,
        is_deleted
        FROM ja_fw_area_divide ${ew.customSqlSegment}
    </select>
 
    <insert id="insertWithGeom" parameterType="org.sxkj.fw.area.entity.FwAreaDivideEntity" useGeneratedKeys="true" keyProperty="id">
        insert into ja_fw_area_divide (
            id,
            area_name,
            longitude,
            latitude,
            area_size,
            geom,
            area_type,
            trigger_condition,
            response_mechanism,
            control_level,
            police_station_id,
            device_ids,
            fly_date_start,
            fly_date_end,
            area_code,
            create_user,
            create_dept,
            create_time,
            update_user,
            update_time,
            status,
            is_deleted
        ) values (
            #{id},
            #{areaName},
            #{longitude},
            #{latitude},
            #{areaSize},
            <choose>
                <when test="geom != null and geom != ''">
                    case
                        when instr(#{geom}, '|') &gt; 0 then ST_GeomFromText(
                            trim(substring_index(#{geom}, '|', 1)),
                            cast(trim(substring_index(#{geom}, '|', -1)) as unsigned)
                        )
                        else ST_GeomFromText(trim(#{geom}))
                    end
                </when>
                <otherwise>null</otherwise>
            </choose>,
            #{areaType},
            #{triggerCondition},
            #{responseMechanism},
            #{controlLevel},
            #{policeStationId},
            #{deviceIds},
            #{flyDateStart},
            #{flyDateEnd},
            #{areaCode},
            #{createUser},
            #{createDept},
            #{createTime},
            #{updateUser},
            #{updateTime},
            IFNULL(#{status}, '0'),
            IFNULL(#{isDeleted}, 0)
        )
    </insert>
 
    <update id="updateWithGeomById" parameterType="org.sxkj.fw.area.entity.FwAreaDivideEntity">
        update ja_fw_area_divide
        <set>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="areaSize != null">area_size = #{areaSize},</if>
            <if test="geom != null and geom != ''">
                geom = case
                    when instr(#{geom}, '|') &gt; 0 then ST_GeomFromText(
                        trim(substring_index(#{geom}, '|', 1)),
                        cast(trim(substring_index(#{geom}, '|', -1)) as unsigned)
                    )
                    else ST_GeomFromText(trim(#{geom}))
                end,
            </if>
            <if test="areaType != null">area_type = #{areaType},</if>
            <if test="triggerCondition != null">trigger_condition = #{triggerCondition},</if>
            <if test="responseMechanism != null">response_mechanism = #{responseMechanism},</if>
            <if test="controlLevel != null">control_level = #{controlLevel},</if>
            <if test="policeStationId != null">police_station_id = #{policeStationId},</if>
            <if test="deviceIds != null">device_ids = #{deviceIds},</if>
            <if test="flyDateStart != null">fly_date_start = #{flyDateStart},</if>
            <if test="flyDateEnd != null">fly_date_end = #{flyDateEnd},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="createUser != null">create_user = #{createUser},</if>
            <if test="createDept != null">create_dept = #{createDept},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateUser != null">update_user = #{updateUser},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDeleted != null">is_deleted = #{isDeleted},</if>
        </set>
        where id = #{id}
    </update>
 
</mapper>