shenyijian
2024-06-21 f20611265f7d34fd4fbcdfdaff6cb9cccd0b25fc
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
<?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="cn.gistack.sm.sjztmd.mapper.AttResBaseMapper">
 
 
    <select id="selectAttResBasePage" resultType="cn.gistack.sm.sjztmd.entity.AttResBase">
        SELECT * FROM "SJZT_MD"."att_res_base"
        WHERE "is_deleted"=0
        <if test="attResBase.name !=null and attResBase.name !=''">
            AND "name" LIKE CONCAT('%',#{attResBase.name},'%')
        </if>
    </select>
 
    <select id="selectAttResBaseGeneralInvestigation"
            resultType="cn.gistack.sm.sjztmd.vo.AttResBaseGeneralInvestigationVO">
 
SELECT base.* from (
        select
        a.*,
        b."check_state" AS tb_state,
        b."guid" as tbStateId,
        b."tb_year",
        b."tb_quarter",
        (CASE WHEN tmp.totalDangerNum>0 THEN 1 ELSE 2 END) as hasDanger,
        tmp.totalDangerNum,
        tmp.termiteNum,
        tmp.otherNum,
        ifnull(tmp.totalDanger,0) totalDanger,
        ifnull(tmp.totalDangerSr,0) totalDangerSr,
        ifnull(tmp.totalDangerCb,0) totalDangerCb,
        ifnull(tmp.totalDangerDw,0) totalDangerDw,
 
        case when town."ad_grad" = 4 THEN town."ad_code" ELSE NULL END AS townCode,
        case when town."ad_grad" = 4 THEN town."ad_name" ELSE NULL END AS townName,
        case when town."ad_grad" = 3 THEN town."ad_code"
        when county."ad_grad" = 3 THEN county."ad_code" END AS countyCode,
        case when town."ad_grad" = 3 THEN town."ad_name"
        when county."ad_grad" = 3 THEN county."ad_name" END AS countyName,
        case when town."ad_grad" = 2 THEN town."ad_code"
        when county."ad_grad" = 2 THEN county."ad_code"
        ELSE city."ad_code" END AS cityCode,
        case when town."ad_grad" = 2 THEN town."ad_name"
        when county."ad_grad" = 2 THEN county."ad_name"
        ELSE city."ad_name" END AS cityName,
        case when town."ad_grad" = 1 THEN town."ad_code"
        when county."ad_grad" = 1 THEN county."ad_code"
        when city."ad_grad" = 1 THEN city."ad_code"
        ELSE province."ad_code" END AS provinceCode,
        case when town."ad_grad" = 1 THEN town."ad_name"
        when county."ad_grad" = 1 THEN county."ad_name"
        when city."ad_grad" = 1 THEN city."ad_name"
        ELSE province."ad_name" END AS provinceName
 
        from sjzt_md."att_res_base" a
        left join ywxt."att_ad_base" town on town."guid" = a."interior_ad_guid"
        left join ywxt."att_ad_base" county on town."p_ad_code" = county."ad_code"
        left join ywxt."att_ad_base" city on county."p_ad_code" = city."ad_code"
        left join ywxt."att_ad_base" province on city."p_ad_code" = province."ad_code"
        left join "SJZT_MD"."tb_res_general_investigation_state" b on a."code" = b."res_guid"
 
        left join
 
        (
        SELECT TRGI."tb_state_id",TRGI."res_guid",
 
        SUM(CASE WHEN (trgi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS totalDangerNum,
        SUM(CASE WHEN (trgi."investigation_variety" = '白蚁' and trgi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS termiteNum,
        SUM(CASE WHEN (trgi."investigation_variety" != '白蚁' and trgi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS otherNum,
        SUM(CASE WHEN (trgi."is_danger" != '否') THEN 1 ELSE 0 END) AS totalDanger,
        SUM(CASE WHEN (json_value(trgi."danger_info", '$.sr') != '') THEN json_value(trgi."danger_info", '$.sr') ELSE 0 END) AS totalDangerSr,
        SUM(CASE WHEN (json_value(trgi."danger_info", '$.cb') != '') THEN json_value(trgi."danger_info", '$.cb') ELSE 0 END) AS totalDangerCb,
        SUM(CASE WHEN (json_value(trgi."danger_info", '$.dw') != '') THEN json_value(trgi."danger_info", '$.dw') ELSE 0 END) AS totalDangerDw
        from sjzt_md."tb_res_general_investigation" trgi
        where 1=1
        <if test="attResBase.tbYear !=null and attResBase.tbYear !=''">
            AND TRGI."tb_year" = #{attResBase.tbYear}
        </if>
        group by TRGI."tb_state_id",TRGI."res_guid"
 
        ) tmp on tmp."tb_state_id" = b."guid"
 
        where 1 = 1
        <if test="attResBase.tbQuarter !=null and attResBase.tbQuarter !=''">
            AND b."tb_quarter" = #{attResBase.tbQuarter}
        </if>
        <if test="attResBase.name !=null and attResBase.name !=''">
            AND a."name" LIKE CONCAT('%',#{attResBase.name},'%')
        </if>
        <if test="attResBase.code !=null and attResBase.code !=''">
            AND a."code" LIKE CONCAT('%',#{attResBase.code},'%')
        </if>
        <if test="attResBase.resRegCode !=null and attResBase.resRegCode !=''">
            AND a."res_reg_code" LIKE CONCAT('%',#{attResBase.resRegCode},'%')
        </if>
        <if test="attResBase.tbState != null and attResBase.tbState !=''">
            AND (
            <if test="attResBase.tbState == -1">
                b."check_state" IS NULL OR
            </if>
            b."check_state" = #{attResBase.tbState}
            )
        </if>
        <if test="attResBase.adCode != null and attResBase.adCode != '' ">
            and (province."ad_code" = #{attResBase.adCode} or city."ad_code" = #{attResBase.adCode} or county."ad_code" =
            #{attResBase.adCode} or town."ad_code" = #{attResBase.adCode})
        </if>
        <if test="attResBase.engScal != null and attResBase.engScal != ''">
            and a."eng_scal" = #{attResBase.engScal}
        </if>
        ) base where 1=1
        <if test="attResBase.hasDanger != null and attResBase.hasDanger != '' ">
            and base.hasDanger = #{attResBase.hasDanger}
        </if>
 
 
    </select>
 
 
    <sql id="resBase">
                   case when town."ad_grad" = 4 THEN town."ad_code" ELSE NULL END AS townCode,
                   case when town."ad_grad" = 4 THEN town."ad_name" ELSE NULL END AS townName,
                   case
                       when town."ad_grad" = 3 THEN town."ad_code"
                       when county."ad_grad" = 3 THEN county."ad_code" END AS countyCode,
                   case
                       when town."ad_grad" = 3 THEN town."ad_name"
                       when county."ad_grad" = 3 THEN county."ad_name" END  AS countyName,
                   case
                       when town."ad_grad" = 2 THEN town."ad_code"
                       when county."ad_grad" = 2 THEN county."ad_code"
                       ELSE city."ad_code" END  AS cityCode,
                   case
                       when town."ad_grad" = 2 THEN town."ad_name"
                       when county."ad_grad" = 2 THEN county."ad_name"
                       ELSE city."ad_name" END AS cityName,
                   case
                       when town."ad_grad" = 1 THEN town."ad_code"
                       when county."ad_grad" = 1 THEN county."ad_code"
                       when city."ad_grad" = 1 THEN city."ad_code"
                       ELSE province."ad_code" END   AS provinceCode,
                   case
                       when town."ad_grad" = 1 THEN town."ad_name"
                       when county."ad_grad" = 1 THEN county."ad_name"
                       when city."ad_grad" = 1 THEN city."ad_name"
                       ELSE province."ad_name" END  AS provinceName
    </sql>
 
    <select id="getListByRegion" resultType="cn.gistack.sm.sjztmd.vo.AttResBaseVO">
        SELECT
            arb."guid",
            arb."code",
            arb."name",
            arb."ad_guid",
            arb."eng_scal",
            arb."res_loc" ,
            arb."res_reg_code",
            <include refid="resBase"></include>
        FROM "att_res_base" arb
        left join "att_ad_base" town on town."guid" = arb."interior_ad_guid"
        left join "att_ad_base" county on town."p_ad_code" = county."ad_code"
        left join "att_ad_base" city on county."p_ad_code" = city."ad_code"
        left join "att_ad_base" province on city."p_ad_code" = province."ad_code"
        WHERE arb."is_deleted"=0
        <if test="obj.code != null and obj.code != '' ">
            and (town."ad_code" = #{obj.code} or county."ad_code" = #{obj.code} or city."ad_code" = #{obj.code} or province."ad_code"
            = #{obj.code})
        </if>
        <if test="obj.name !=null and obj.name !=''">
            AND "name" LIKE CONCAT('%',#{obj.name},'%')
        </if>
        <if test="obj.guid !=null and obj.guid !=''">
            AND "code" LIKE CONCAT('%',#{obj.guid},'%')
        </if>
        <if test="obj.engScal !=null and obj.engScal !=''">
            AND "eng_scal" = #{obj.engScal}
        </if>
 
    </select>
    <select id="getDetailByCode" resultType="cn.gistack.sm.sjztmd.entity.AttResBase">
        SELECT *
        FROM "att_res_base"
        WHERE "is_deleted" = 0
          and "code" = #{code}
    </select>
 
    <!--获取水库对应责任人分页数据-->
    <select id="getAttResBaseUserPage" resultType="cn.gistack.sm.sjztmd.dto.AttResBaseUserDTO">
        select
        arb."guid", arb."name", arb."res_loc" as place, arb."res_reg_code" as resRegCode, arb."eng_scal" as engScal,arb."center_long" as lon,arb."center_lat" as lat,
        dri."city_nm" cityName,dri."county_nm" countyName,dri."town_nm" townName,
        aab."ad_name" as adName,
        trmp1."user_unit" areaUnitName,trmp1."user_name" areaUsername,trmp1."user_phone" areaPhone,trmp1."position"
        areaPosition,trmp1."guid" areaUserGuid,
 
        trmp2."user_unit" customsUnitName,trmp2."user_name" customsUsername,trmp2."user_phone"
        customsPhone,trmp2."position" customsPosition,trmp2."guid" customsUserGuid,
 
        trmp3."user_unit" manageUnitUnitName,trmp3."user_name" manageUnitUsername,trmp3."user_phone"
        manageUnitPhone,trmp3."position" manageUnitPosition,trmp3."guid" manageUnitUserGuid,
 
        trmp4."user_unit" technologyUnitName,trmp4."user_name" technologyUsername,trmp4."user_phone"
        technologyPhone,trmp4."position" technologyPosition,trmp4."guid" technologyUserGuid,
 
        trmp5."user_unit" patrolUnitName,trmp5."user_name" patrolUsername,trmp5."user_phone"
        patrolPhone,trmp5."position" patrolPosition,trmp5."guid" patrolUserGuid
        from SJZT_MD."att_res_base" arb
        left join "SJZT_DW"."dim_res_info_a" dri on arb."guid" = dri."guid"
        left join "SJZT_MD"."att_ad_base" aab on aab."guid" = arb."interior_ad_guid"
        left join "SJZT_MD"."att_ad_base" aa on aab."p_ad_code" = aa."ad_code"
        left join "SJZT_MD"."att_ad_base" ab on aa."p_ad_code" = ab."ad_code"
        left join "SJZT_MD"."att_ad_base" ac on ab."p_ad_code" = ac."ad_code"
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=1 GROUP BY "res_guid"
        ) trmp1 on arb."guid" = trmp1."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=2 GROUP BY "res_guid"
        ) trmp2 on arb."guid" = trmp2."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=3 GROUP BY "res_guid"
        ) trmp3 on arb."guid" = trmp3."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=4 GROUP BY "res_guid"
        ) trmp4 on arb."guid" = trmp4."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=5 GROUP BY "res_guid"
        ) trmp5 on arb."guid" = trmp5."res_guid"
        where 1=1
        <if test="params.name !=null and params.name !=''">
            AND arb."name" LIKE CONCAT('%',#{params.name},'%')
        </if>
        <if test="params.resRegCode !=null and params.resRegCode !=''">
            AND arb."res_reg_code" LIKE CONCAT('%',#{params.resRegCode},'%')
        </if>
        <if test="params.engScal !=null and params.engScal !=''">
            AND arb."eng_scal" LIKE CONCAT('%',#{params.engScal},'%')
        </if>
        <if test="params.isWorkable==1">
            AND (
            (
            (arb."eng_scal" = '大(1)型' or arb."eng_scal" = '大(2)型' or arb."eng_scal" = '中型')
            and
            trmp1."user_unit" is not null and trmp2."user_unit" is not null and trmp3."user_unit" is not null
            )
            or
            (
            (arb."eng_scal" = '小(1)型' or arb."eng_scal" = '小(2)型')
            and
            trmp1."user_unit" is not null and trmp2."user_unit" is not null and trmp3."user_unit" is not null and
            trmp4."user_unit" is not null and trmp5."user_unit" is not null
            )
            )
        </if>
        <if test="params.isWorkable==2">
            AND (
            (arb."eng_scal" = '大(1)型' or arb."eng_scal" = '大(2)型' or arb."eng_scal" = '中型')
            and
            (trmp1."user_unit" is null or trmp2."user_unit" is null or trmp3."user_unit" is null)
            or
            (
            (arb."eng_scal" = '小(1)型' or arb."eng_scal" = '小(2)型')
            and
            (trmp1."user_unit" is null or trmp2."user_unit" is null or trmp3."user_unit" is null or trmp4."user_unit" is
            null or trmp5."user_unit" is null)
            )
            )
        </if>
 
        <if test="params.adCode != null and params.adCode != '' ">
            and (aab."ad_code" = #{params.adCode} or aa."ad_code" = #{params.adCode} or ab."ad_code" = #{params.adCode}
            or ac."ad_code" = #{params.adCode})
        </if>
 
        <if test="params.userName !=null and params.userName != ''">
            AND CONCAT(trmp1."user_name",trmp2."user_name",trmp3."user_name",trmp4."user_name",trmp5."user_name") LIKE CONCAT('%',#{params.userName},'%')
        </if>
        <if test="params.userPhone != null and params.userPhone !=''">
            AND CONCAT(trmp1."user_phone",trmp2."user_phone",trmp3."user_phone",trmp4."user_phone",trmp5."user_phone") LIKE CONCAT('%',#{params.userPhone},'%')
        </if>
 
    </select>
 
    <!--查询各类型责任人-->
    <select id="getUserByResBaseGuid" resultType="cn.gistack.sm.sjztmd.vo.ManagePersonVO">
        select trmp."type",
               trmp."user_name"  as username,
               trmp."user_unit"  as unitName,
               trmp."position",
               trmp."user_phone" as phone
        from "SJZT_MD"."att_res_manage_person" trmp
        where trmp."res_guid" = #{guid}
    </select>
 
    <update id="updateResBaseByGuid">
        UPDATE "att_res_base" SET
        <if test="attResBase.interiorAdGuid !=null and attResBase.interiorAdGuid != ''">
            "interior_ad_guid" = #{attResBase.interiorAdGuid},
        </if>
        <if test="attResBase.label !=null and attResBase.label != ''">
            "label" = #{attResBase.label},
        </if>
        <if test="attResBase.label ==null or attResBase.label == ''">
            "label" = '',
        </if>
            "height_base_std_tp" = #{attResBase.heightBaseStdTp},
        "is_gate" = #{attResBase.isGate},
        "update_time" = #{attResBase.updateTime}
        WHERE "guid" = #{attResBase.guid}
    </update>
 
 
    <update id="updateRsvr">
        UPDATE SJZT_ODS."yg_rsvr_b" SET
        "tb_height_base_std_tp" = #{attResBase.tbHeightBaseStdTp}
        WHERE "guid" = #{attResBase.guid}
    </update>
 
 
    <!--查询当前水库对应的市级编号和县区编号-->
    <select id="getCityCountyCodeByResGuid" resultType="cn.gistack.sm.sjztmd.vo.AttResBaseVO">
        SELECT case
                   when b."ad_grad" = 3 THEN b."ad_code"
                   when c."ad_grad" = 3 THEN c."ad_code" END AS countyCode,
               case
                   when b."ad_grad" = 2 THEN b."ad_code"
                   when c."ad_grad" = 2 THEN c."ad_code"
                   ELSE d."ad_code" END                      AS cityCode
        FROM sjzt_md."att_res_base" a
                 LEFT JOIN sjzt_md."att_ad_base" b ON a."interior_ad_guid" = b."guid"
                 LEFT JOIN sjzt_md."att_ad_base" c ON b."p_ad_code" = c."guid"
                 LEFT JOIN sjzt_md."att_ad_base" d ON c."p_ad_code" = d."guid"
        where a."guid" = #{guid}
    </select>
 
    <!--查询当前水库对应的市级编号和县区编号-->
    <select id="getWaterRegionInfoByResGuid" resultType="cn.gistack.sm.sjztmd.vo.AttResAdVO">
        SELECT a."guid"                                                 as resGuid,
               case when b."ad_grad" = 4 THEN b."ad_code" ELSE NULL END AS townCode,
               case when b."ad_grad" = 4 THEN b."ad_name" ELSE NULL END AS townName,
               case
                   when b."ad_grad" = 3 THEN b."ad_code"
                   when c."ad_grad" = 3 THEN c."ad_code" END            AS countyCode,
               case
                   when b."ad_grad" = 3 THEN b."ad_name"
                   when c."ad_grad" = 3 THEN C."ad_name" END            AS countyName,
               case
                   when b."ad_grad" = 2 THEN b."ad_code"
                   when c."ad_grad" = 2 THEN c."ad_code"
                   ELSE d."ad_code" END                                 AS cityCode,
               case
                   when b."ad_grad" = 2 THEN b."ad_name"
                   when c."ad_grad" = 2 THEN c."ad_name"
                   ELSE d."ad_name" END                                 AS cityName
        FROM sjzt_md."att_res_base" a
                 LEFT JOIN sjzt_md."att_ad_base" b ON a."interior_ad_guid" = b."guid"
                 LEFT JOIN sjzt_md."att_ad_base" c ON b."p_ad_code" = c."guid"
                 LEFT JOIN sjzt_md."att_ad_base" d ON c."p_ad_code" = d."guid"
        where a."guid" = #{guid}
    </select>
 
    <select id="getDimResInfoACount" resultType="java.lang.Integer">
        select count(*)
        from sjzt_dw."dim_res_info_a"
    </select>
 
 
    <update id="updateIsShowStatus">
        UPDATE SJZT_MD."att_res_base" SET "is_show" = #{isShow}
        WHERE
        "guid" IN
        <foreach collection="ids.split(',')" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
 
    </update>
    <update id="updateRelResUpdateLoc">
        UPDATE SJZT_MD."rel_res_update_loc"
        SET "update_by" = #{updateLog}
        WHERE "res_code" = #{resGuid}
    </update>
 
 
    <!--根据水库名称、所在区域查询改水库的数量-->
    <select id="getWaterCountByResNameAndCountyName" resultType="java.lang.Integer">
        SELECT count(1)
        FROM sjzt_md."att_res_base" a
                 LEFT JOIN sjzt_md."att_ad_base" b ON a."interior_ad_guid" = b."guid"
                 LEFT JOIN sjzt_md."att_ad_base" c ON b."p_ad_code" = c."guid"
                 LEFT JOIN sjzt_md."att_ad_base" d ON c."p_ad_code" = d."guid"
        where a."name" = #{resName}
          and (
                (b."ad_grad" = 3 and b."ad_code" = #{countyCode})
                or
                (c."ad_grad" = 3 and c."ad_code" = #{countyCode})
            )
    </select>
    <select id="getResAd"  resultType="cn.gistack.sm.sjztmd.vo.AttResAdVO">
        SELECT
            arb."name" resName,
            arb."guid" resGuid,
            arb."interior_ad_guid",
            arb."eng_scal" engScal,
            arb."res_reg_code" resRegCode,
            arb."center_long" resLon,
            arb."center_lat" resLat,
            case when town."ad_grad" = 4 THEN town."ad_code" ELSE NULL END AS townCode,
            case when town."ad_grad" = 4 THEN town."ad_name" ELSE NULL END AS townName,
            case when town."ad_grad" = 3 THEN town."ad_code"
                 when county."ad_grad" = 3 THEN county."ad_code" END AS countyCode,
            case when town."ad_grad" = 3 THEN town."ad_name"
                 when county."ad_grad" = 3 THEN county."ad_name" END AS countyName,
            case when town."ad_grad" = 2 THEN town."ad_code"
                 when county."ad_grad" = 2 THEN county."ad_code"
                 ELSE city."ad_code" END AS cityCode,
            case when town."ad_grad" = 2 THEN town."ad_name"
                 when county."ad_grad" = 2 THEN county."ad_name"
                 ELSE city."ad_name" END AS cityName,
            case when town."ad_grad" = 1 THEN town."ad_code"
                 when county."ad_grad" = 1 THEN county."ad_code"
                 when city."ad_grad" = 1 THEN city."ad_code"
                 ELSE province."ad_code" END AS provinceCode,
            case when town."ad_grad" = 1 THEN town."ad_name"
                 when county."ad_grad" = 1 THEN county."ad_name"
                 when city."ad_grad" = 1 THEN city."ad_name"
                 ELSE province."ad_name" END AS provinceName
        FROM SJZT_MD."att_res_base" arb
                 LEFT JOIN SJZT_MD."att_ad_base" town ON town."guid" = arb."interior_ad_guid"
                 LEFT JOIN SJZT_MD."att_ad_base" county ON county."guid" = town."p_ad_code"
                 LEFT JOIN SJZT_MD."att_ad_base" city ON city."guid" = county."p_ad_code"
                 LEFT JOIN SJZT_MD."att_ad_base" province ON province."guid" = city."p_ad_code"
        where arb."guid" = #{resId}
 
    </select>
    <select id="getYwxtResInfo" resultType="cn.gistack.sm.sjztmd.entity.AttAdBase">
        SELECT
            *
        FROM YWXT."att_ad_base" aab
        where
            aab."p_ad_name" = #{cityName}
          and aab."ad_name" = #{countyName}
    </select>
    <select id="getAttResBaseUserExcel" resultType="cn.gistack.sm.sjztmd.excel.AttResBaseUserExcel">
        select
        arb."guid", arb."name", arb."res_loc" as place, arb."res_reg_code" as resRegCode, arb."eng_scal" as engScal,
        REGEXP_SUBSTR (arb."res_loc",'[^-]+',1,2) as cityName,
        REGEXP_SUBSTR (arb."res_loc",'[^-]+',1,3) as countyName,
        REGEXP_SUBSTR (arb."res_loc",'[^-]+',1,4) as townName,
        aab."ad_name" as adName,
        trmp1."user_unit" areaUnitName,trmp1."user_name" areaUsername,trmp1."user_phone" areaPhone,trmp1."position"
        areaPosition,trmp1."guid" areaUserGuid,
 
        trmp2."user_unit" customsUnitName,trmp2."user_name" customsUsername,trmp2."user_phone"
        customsPhone,trmp2."position" customsPosition,trmp2."guid" customsUserGuid,
 
        trmp3."user_unit" manageUnitUnitName,trmp3."user_name" manageUnitUsername,trmp3."user_phone"
        manageUnitPhone,trmp3."position" manageUnitPosition,trmp3."guid" manageUnitUserGuid,
 
        trmp4."user_unit" technologyUnitName,trmp4."user_name" technologyUsername,trmp4."user_phone"
        technologyPhone,trmp4."position" technologyPosition,trmp4."guid" technologyUserGuid,
 
        trmp5."user_unit" patrolUnitName,trmp5."user_name" patrolUsername,trmp5."user_phone"
        patrolPhone,trmp5."position" patrolPosition,trmp5."guid" patrolUserGuid
        from SJZT_MD."att_res_base" arb
        left join "SJZT_MD"."att_ad_base" aab on aab."guid" = arb."interior_ad_guid"
        left join "SJZT_MD"."att_ad_base" aa on aab."p_ad_code" = aa."ad_code"
        left join "SJZT_MD"."att_ad_base" ab on aa."p_ad_code" = ab."ad_code"
        left join "SJZT_MD"."att_ad_base" ac on ab."p_ad_code" = ac."ad_code"
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=1 GROUP BY "res_guid"
        ) trmp1 on arb."guid" = trmp1."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=2 GROUP BY "res_guid"
        ) trmp2 on arb."guid" = trmp2."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=3 GROUP BY "res_guid"
        ) trmp3 on arb."guid" = trmp3."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=4 GROUP BY "res_guid"
        ) trmp4 on arb."guid" = trmp4."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name")
        "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where "type"=5 GROUP BY "res_guid"
        ) trmp5 on arb."guid" = trmp5."res_guid"
        where 1=1
        <if test="params.name !=null and params.name !=''">
            AND arb."name" LIKE CONCAT('%',#{params.name},'%')
        </if>
        <if test="params.resRegCode !=null and params.resRegCode !=''">
            AND arb."res_reg_code" LIKE CONCAT('%',#{params.resRegCode},'%')
        </if>
        <if test="params.engScal !=null and params.engScal !=''">
            AND arb."eng_scal" LIKE CONCAT('%',#{params.engScal},'%')
        </if>
        <if test="params.isWorkable==1">
            AND (
            (
            (arb."eng_scal" = '大(1)型' or arb."eng_scal" = '大(2)型' or arb."eng_scal" = '中型')
            and
            trmp1."user_unit" is not null and trmp2."user_unit" is not null and trmp3."user_unit" is not null
            )
            or
            (
            (arb."eng_scal" = '小(1)型' or arb."eng_scal" = '小(2)型')
            and
            trmp1."user_unit" is not null and trmp2."user_unit" is not null and trmp3."user_unit" is not null and
            trmp4."user_unit" is not null and trmp5."user_unit" is not null
            )
            )
        </if>
        <if test="params.isWorkable==2">
            AND (
            (arb."eng_scal" = '大(1)型' or arb."eng_scal" = '大(2)型' or arb."eng_scal" = '中型')
            and
            (trmp1."user_unit" is null or trmp2."user_unit" is null or trmp3."user_unit" is null)
            or
            (
            (arb."eng_scal" = '小(1)型' or arb."eng_scal" = '小(2)型')
            and
            (trmp1."user_unit" is null or trmp2."user_unit" is null or trmp3."user_unit" is null or trmp4."user_unit" is
            null or trmp5."user_unit" is null)
            )
            )
        </if>
 
        <if test="params.adCode != null and params.adCode != '' ">
            and (aab."ad_code" = #{params.adCode} or aa."ad_code" = #{params.adCode} or ab."ad_code" = #{params.adCode}
            or ac."ad_code" = #{params.adCode})
        </if>
 
        <if test="params.userName !=null and params.userName != ''">
            AND CONCAT(trmp1."user_name",trmp2."user_name",trmp3."user_name",trmp4."user_name",trmp5."user_name") LIKE CONCAT('%',#{params.userName},'%')
        </if>
        <if test="params.userPhone != null and params.userPhone !=''">
            AND CONCAT(trmp1."user_phone",trmp2."user_phone",trmp3."user_phone",trmp4."user_phone",trmp5."user_phone") LIKE CONCAT('%',#{params.userPhone},'%')
        </if>
    </select>
    <select id="getUpdateLog" resultType="java.lang.String">
        SELECT "update_by" FROM  SJZT_MD."rel_res_update_loc" WHERE "res_code" = #{resGuid}
    </select>
 
 
</mapper>