linwe
2024-05-29 c10d6358b9f014375a13821465bc978d0c0da22e
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
<?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.springblade.modules.doorplateAddress.mapper.DoorplateAddressMapper">
 
    <!--过滤网格数据-->
    <sql id="filterHouseGrid">
        <if test="houseParam.roleName!=null and houseParam.roleName!=''">
            <if test="houseParam.roleName=='wgy' and houseParam.userId!='1726859808689696770'">
                <choose>
                    <when test="list != null and list.size()>0">
                        and address_code in
                        <foreach collection="list" item="houseCode" separator ="," open="("  close=")">
                            #{houseCode}
                        </foreach>
                    </when>
                    <otherwise>
                        and address_code in ('')
                    </otherwise>
                </choose>
            </if>
        </if>
    </sql>
 
 
 
    <!--过滤社区数据-->
    <sql id="filterCommunity">
        <if test="houseParam.roleName!=null and houseParam.roleName!=''">
            <if test="houseParam.roleName=='mj' and houseParam.userId!='1726859808689696770'">
                <choose>
                    <when test="communityList != null and communityList.size()>0">
                        and nei_code in
                        <foreach collection="communityList" item="neiCode" separator ="," open="("  close=")">
                            #{neiCode}
                        </foreach>
                    </when>
                    <otherwise>
                        and nei_code in ('')
                    </otherwise>
                </choose>
            </if>
        </if>
    </sql>
 
 
    <!--门牌地址详情查询-->
    <resultMap id="doorplateAddressDetailMap" type="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO"
               autoMapping="true">
        <id property="id" column="id"/>
        <association property="place" javaType="org.springblade.modules.place.vo.PlaceVO"
                    autoMapping="true">
            <id property="id" column="cid"/>
            <result property="createTime" column="pcreateTime"/>
            <result property="createUserName" column="createUserName"/>
        </association>
    </resultMap>
 
    <!--自定义分页查询-->
    <select id="selectDoorplateAddressPage" resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO">
        SELECT
        jda.*
        FROM
        jczz_doorplate_address jda LEFT JOIN jczz_district jd on jda.aoi_code=jd.aoi_code
        where 1=1
        <if test="doorplateAddress.aoiName!=null and doorplateAddress.aoiName!=''">
            and jda.aoi_name like concat('%',#{doorplateAddress.aoiName},'%')
        </if>
        <if test="doorplateAddress.addressName!=null and doorplateAddress.addressName!=''">
            and jda.address_name like concat('%',#{doorplateAddress.addressName},'%')
        </if>
        <if test="doorplateAddress.townStreetCode != null and doorplateAddress.townStreetCode != ''">
            and jda.town_street_code like concat('%',#{doorplateAddress.townStreetCode},'%')
        </if>
 
        <if test="doorplateAddress.houseName != null and doorplateAddress.houseName != ''">
            and jda.house_name like concat('%',#{doorplateAddress.houseName},'%')
        </if>
 
        <if test="doorplateAddress.buildingName != null and doorplateAddress.buildingName != ''">
            and jda.building_name like concat('%',#{doorplateAddress.buildingName},'%')
        </if>
 
        <if test="doorplateAddress.unitName != null and doorplateAddress.unitName != ''">
            and jda.unit_name like concat('%',#{doorplateAddress.unitName},'%')
        </if>
 
        <if test="doorplateAddress.districtIds != null ">
            and jd.id in
        <foreach collection="doorplateAddress.districtIds" item="districtId" separator ="," open="("  close=")">
            #{districtId}
        </foreach>
        </if>
    </select>
 
 
    <!--查询区域数据-街道-->
<!--    <select id="getRegionListByGroupTwon" resultType="org.springblade.common.node.TreeStringNode" >-->
<!--        select town_street_code as id,town_street_name as name from jczz_doorplate_address-->
<!--        where 1=1-->
<!--        <if test="houseParam.userId!=null and houseParam.userId!='' and houseParam.userId=='1726859808689696770'">-->
<!--            and nei_name = '万达社区居民委员会'-->
<!--        </if>-->
<!--        <include refid="filterHouseGrid"/>-->
<!--        <include refid="filterCommunity"/>-->
<!--        group by town_street_code,town_street_name-->
<!--    </select>-->
 
    <!--过滤网格数据-->
    <sql id="filterHouseGridByTownOrCommunity">
        <if test="houseParam.roleName!=null and houseParam.roleName!='' and houseParam.roleName!='admin'">
            <choose>
                <when test="(houseParam.roleName=='wgy' or houseParam.roleName=='wzcj') and houseParam.userId!='1726859808689696770'">
                    <choose>
                        <when test="list != null and list.size()>0">
                            and jg.grid_code in
                            <foreach collection="list" item="gridCode" separator ="," open="("  close=")">
                                #{gridCode}
                            </foreach>
                        </when>
                        <otherwise>
                            and jg.grid_code in ('')
                        </otherwise>
                    </choose>
                </when>
                <otherwise>
                    and jg.grid_code in ('')
                </otherwise>
            </choose>
        </if>
    </sql>
 
    <!--查询区域数据-街道-->
    <select id="getRegionListByGroupTwon" resultType="org.springblade.common.node.TreeStringNode" >
        select br.town_code as id,br.town_name as name from jczz_grid jg
        left join blade_region br on jg.community_code = br.code
        where jg.is_deleted = 0
        <if test="houseParam.userId!=null and houseParam.userId!='' and houseParam.userId=='1726859808689696770'">
            and br.name = '万达社区居民委员会'
        </if>
        <include refid="filterHouseGridByTownOrCommunity"/>
        group by br.town_code,br.town_name
        union
        select br.town_code as id,br.town_name as name from jczz_police_affairs_grid jpag
        left join blade_region br on jpag.community_code = br.code
        where jpag.is_deleted = 0 and br.town_code is not null
        <include refid="filterCommunityByTownOrCommunity"/>
        group by br.town_code,br.town_name
    </select>
 
    <!--过滤社区数据-->
    <sql id="filterCommunityByTownOrCommunity">
        <if test="houseParam.roleName!=null and houseParam.roleName!=''">
            <choose>
                <when test="houseParam.roleName=='mj'">
                    <choose>
                        <when test="communityList != null and communityList.size()>0">
                            and jpag.jw_grid_code in
                            <foreach collection="communityList" item="code" separator ="," open="("  close=")">
                                #{code}
                            </foreach>
                        </when>
                        <otherwise>
                            and jpag.jw_grid_code in ('')
                        </otherwise>
                    </choose>
                </when>
                <otherwise>
                    and jpag.jw_grid_code in ('')
                </otherwise>
            </choose>
        </if>
    </sql>
 
    <!--查询区域数据-社区-->
    <select id="getRegionListByGroupNei" resultType="org.springblade.common.node.TreeStringNode" >
        select br.village_code as id,br.village_name as name,br.town_code as parentId from jczz_grid jg
        left join blade_region br on jg.community_code = br.code
        where jg.is_deleted = 0
        <if test="houseParam.userId!=null and houseParam.userId!='' and houseParam.userId=='1726859808689696770'">
            and nei_name = '万达社区居民委员会'
        </if>
        <include refid="filterHouseGridByTownOrCommunity"/>
        union
        select br.village_code as id,br.village_name as name,br.town_code as parentId from jczz_police_affairs_grid jpag
        left join blade_region br on jpag.community_code = br.code
        where jpag.is_deleted = 0 and br.village_code is not null
        <include refid="filterCommunityByTownOrCommunity"/>
    </select>
 
    <!--根据社区名称查询小区集合-->
    <select id="getDistrictList" resultType="org.springblade.common.node.TreeStringNode" >
        select aoi_code as id,aoi_name as name,1 as addressType from jczz_doorplate_address
        where 1=1
        and aoi_name !=''
        and aoi_code !=''
        <if test="houseParam.name != null and houseParam.name!=''">
            and nei_name = #{houseParam.name}
        </if>
        <if test="houseParam.code != null and houseParam.code!=''">
            and nei_code = #{houseParam.code}
        </if>
        <include refid="filterHouseGrid"/>
        <include refid="filterCommunity"/>
        group by aoi_code,aoi_name
        union all
        (
        select aoi_code as id,sub_aoi as name,1 as addressType from jczz_doorplate_address
        where 1=1
        and aoi_code !=''
        and aoi_name is null
        and sub_aoi != ''
        <if test="houseParam.name != null and houseParam.name!=''">
            and nei_name = #{houseParam.name}
        </if>
        <if test="houseParam.code != null and houseParam.code!=''">
            and nei_code = #{houseParam.code}
        </if>
        <include refid="filterHouseGrid"/>
        <include refid="filterCommunity"/>
        group by aoi_code,sub_aoi
        )
        union all
        (
        select nei_code as id,'自建房/商铺' as name,2 as addressType from jczz_doorplate_address
        where 1=1
        and aoi_code is null
        <if test="houseParam.name != null and houseParam.name!=''">
            and nei_name = #{houseParam.name}
        </if>
        <if test="houseParam.code != null and houseParam.code!=''">
            and nei_code = #{houseParam.code}
        </if>
        <include refid="filterHouseGrid"/>
        <include refid="filterCommunity"/>
        group by nei_code
        )
        union all
        (
        select '企业商超' as id,'企业商超' as name,4 as addressType from jczz_place_rel jpl
        join jczz_place jp on jpl.place_id = jp.id and jp.is_deleted = 0
        where jpl.is_deleted = 0
        <if test="houseParam.communityName!=null and houseParam.communityName!=''">
            and community_name like concat('%',#{houseParam.communityName},'%')
        </if>
        <if test="houseParam.code != null and houseParam.code!=''">
            and community_code = #{houseParam.code}
        </if>
        limit 1
        )
    </select>
 
    <!--根据小区名称查询楼栋/商铺集合-->
    <select id="getBuildingList" resultType="org.springblade.common.node.TreeStringNode" >
        (
            select building_code as id,ifnull(building_name,'1栋') as name,1 as addressType from jczz_doorplate_address
            where 1=1
            and aoi_code = #{houseParam.code}
            and building_code !=''
            and doorplate_type = '户室牌'
            <include refid="filterHouseGrid"/>
            group by building_code,building_name
            order by building_name
        )
        union all
        (
            select address_code as id,doorplate_name as name,2 as addressType from jczz_doorplate_address
            where 1=1
            and aoi_code = #{houseParam.code}
            and building_name is null
            and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
            <include refid="filterHouseGrid"/>
        )
    </select>
 
    <!--户室map-->
    <resultMap id="houseFuncNodeMap" type="org.springblade.modules.doorplateAddress.vo.FuncNode" autoMapping="true" >
        <id column="id" property="id"/>
        <collection property="householdLabelList" javaType="java.util.List"
                    ofType="org.springblade.modules.house.vo.HouseholdLabelVO" autoMapping="true">
            <id property="id" column="cid"/>
        </collection>
    </resultMap>
 
    <!--查询户室及住户相关信息,单元中包含住户-->
    <select id="getUnitHouseholdList" resultMap="houseFuncNodeMap" >
        (
            select
            jda.id,ifnull(jda.unit_name,"未知单元") unitName,jda.unit_code unitCode,jda.floor,jda.house_name as houseNo,
            jda.address_code addressCode,
            jh.name as realName,jh.relationship as roleType,1 as addressType,
            juhl.id as cid,juhl.house_code,juhl.label_id,juhl.label_name,juhl.color,juhl.household_id,
            juhlh.color as houseColor
            from jczz_doorplate_address jda
            left join
            (
                SELECT house_code, NAME, relationship FROM jczz_household WHERE id in(
                    SELECT max(id) FROM jczz_household where is_deleted =0 and relationship = 1 GROUP BY house_code
                )
            ) jh
            on jda.address_code = jh.house_code
            left join jczz_user_house_label juhl on juhl.house_code = jda.address_code and juhl.lable_type=1
            left join jczz_user_house_label juhlh on juhlh.house_code = jda.address_code and juhlh.lable_type=2
            where 1=1
            and floor != ''
            and house_name != ''
            and doorplate_type = '户室牌'
            and building_code = #{houseParam.code}
            <if test="houseParam.searchKey!=null and houseParam.searchKey!=''">
                and jh.name like concat('%',#{houseParam.searchKey},'%')
            </if>
            <include refid="filterHouseGrid"/>
        )
        union all
        (
            select jda2.id,'' as unitName,address_code as unitCode,doorplate_name as floor,'' as houseNo,address_code as addressCode,
            '' as realName,'' as roleType,2 as addressType,
            juhl.id as cid,juhl.house_code,juhl.label_id,juhl.label_name,juhl.color,juhl.household_id,
            juhlh.color as houseColor
            from jczz_doorplate_address jda2
            left join jczz_user_house_label juhl on juhl.house_code = jda2.address_code and juhl.lable_type=1
            left join jczz_user_house_label juhlh on juhlh.house_code = jda2.address_code and juhlh.lable_type=2
            where 1=1
            and building_code = #{houseParam.code}
            and building_name != ''
            and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
            <include refid="filterHouseGrid"/>
        )
    </select>
 
    <!--先查询门牌信息-->
    <select id="getDoorplateAddressDetailByCode" resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO">
        select * from jczz_doorplate_address where address_code = #{code}
    </select>
 
    <select id="getTownStreetVOTreeList"
            resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVOTree">
        SELECT town_street_code as code,town_street_name as name FROM jczz_doorplate_address group by town_street_code , town_street_name
    </select>
 
    <select id="getNeiVOTreeList" resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVOTree">
        SELECT nei_code as code,nei_name as name FROM jczz_doorplate_address WHERE town_street_code =#{code} GROUP BY nei_code,nei_name
    </select>
    <select id="getStreetRuVOTreeList"
            resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVOTree">
        SELECT street_ru_code as code,street_ru_name as name
        FROM jczz_doorplate_address
        WHERE nei_code =#{code}
        and street_ru_code is not null and street_ru_code !=''
        and street_ru_name is not null and street_ru_name !=''
        GROUP BY street_ru_code,street_ru_name
    </select>
 
    <select id="getDistrictVOTreeList"
            resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVOTree">
        SELECT aoi_code as code,aoi_name as name
        FROM jczz_doorplate_address
        WHERE street_ru_code =#{code}
        and aoi_code is not null and aoi_code !=''
        and aoi_name is not null and aoi_name !=''
       GROUP BY aoi_code,aoi_name
    </select>
 
    <select id="getBuildingVOTreeList"
            resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVOTree">
        SELECT building_code as code,building_name as name
        FROM jczz_doorplate_address
        WHERE aoi_code =#{code}
          and building_code is not null and building_code !=''
        and building_name is not null and building_name !=''
        GROUP BY building_code,building_name
    </select>
 
    <!--根据社区查询街路巷集合-->
    <select id="getStreetRuList" resultType="org.springblade.common.node.TreeStringNode" >
        select street_ru_code as id,street_ru_name as name,3 as addressType from jczz_doorplate_address
        where 1=1
        and aoi_code is null
        <if test="houseParam.name != null and houseParam.name!=''">
            and nei_name = #{houseParam.name}
        </if>
        <if test="houseParam.code != null and houseParam.code!=''">
            and nei_code = #{houseParam.code}
        </if>
        <include refid="filterHouseGrid"/>
        group by street_ru_code,street_ru_name
    </select>
 
    <!--根据街路巷编号查询街路巷门牌名称集合-->
    <select id="getDoorplateNameList" resultType="org.springblade.modules.doorplateAddress.vo.FuncNode">
      select address_code as addressCode,
      IFNULL(CONCAT(doorplate_num,sub_door_plate_no), IF(doorplate_num IS NULL, sub_door_plate_no, doorplate_num)) as floor,
      3 as addressType
      from jczz_doorplate_address
      where 1=1
      and street_ru_code = #{houseParam.code}
      and nei_code = #{houseParam.name}
      and aoi_code is null
      and doorplate_type = '中门牌'
      <include refid="filterHouseGrid"/>
      order by doorplate_num,sub_door_plate_no
    </select>
 
    <select id="getDoorplateAddressDetail"
            resultMap="doorplateAddressDetailMap">
        SELECT
            jda.*,
            jp.id as cid,jp.*,jp.create_time as pcreateTime,
            bu.real_name as createUserName
        FROM jczz_doorplate_address jda
        left join jczz_place jp on jda.address_code = jp.house_code= and jp.is_deleted = 0
        left join blade_user bu on bu.id = jp.create_user and bu.is_deleted = 0
        WHERE 1=1
        <if test="vo.stdId != null and vo.stdId != ''">
            AND address_code = #{vo.stdId}
        </if>
        <if test="vo.buildingCode != null and vo.buildingCode !='' ">
            AND building_code = #{vo.buildingCode}
        </if>
    </select>
 
    <select id="getDoorplateAddressList"
            resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO">
        SELECT * FROM jczz_doorplate_address
        WHERE 1=1
        <if test="vo.stdId != null and vo.stdId != ''">
            AND address_code = #{vo.stdId}
        </if>
        <if test="vo.buildingCode != null and vo.buildingCode !='' ">
            AND building_code = #{vo.buildingCode}
        </if>
    </select>
 
    <!--查询社区信息-->
    <select id="getAllDoorplateAddress" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        select
        jda.id,
        jda.address_code,
        jda.aoi_code,
        jda.aoi_name,
        jda.x,
        jda.y
        from jczz_doorplate_address jda
        left join jczz_grid_range jgr on jda.address_code = jgr.house_code
        where 1=1 and jgr.id is null
        <if test="doorplateAddressEntity.neiName!=null and doorplateAddressEntity.neiName!=''">
            and jda.nei_name = #{doorplateAddressEntity.neiName}
        </if>
        <if test="doorplateAddressEntity.townStreetName!=null and doorplateAddressEntity.townStreetName!=''">
            and jda.town_street_name = #{doorplateAddressEntity.townStreetName}
        </if>
    </select>
 
    <!--获取房屋树-->
    <select id="getHouseTree" resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVOTree">
        SELECT
        aoi_code as code,
        aoi_name as name,
        nei_code as parentCode
        FROM jczz_doorplate_address
        WHERE nei_code = #{houseParam.code}
        and aoi_code is not null and aoi_code !=''
        and aoi_name is not null and aoi_name !=''
        GROUP BY aoi_code,aoi_name,nei_code
        <include refid="filterHouseGrid"/>
        union all
        (
        SELECT
        building_code as code,
        building_name as name,
        aoi_code as parentCode
        FROM jczz_doorplate_address
        WHERE nei_code = #{houseParam.code}
          and building_code is not null and building_code !=''
          and building_name is not null and building_name !=''
          GROUP BY building_code,building_name,aoi_code
        <include refid="filterHouseGrid"/>
        )
        union all
        (
        select
        jda.unit_code as code,
        ifnull(jda.unit_name,"一单元") name,
        jda.building_code as parentCode
        from jczz_doorplate_address jda
        where 1=1
        and floor != ''
        and house_name != ''
        and doorplate_type = '户室牌'
        and nei_code = #{houseParam.code}
        <include refid="filterHouseGrid"/>
        group by unit_name,unit_code,building_code
        )
        union all
        (
        select
        jda.address_code as code,
        jda.house_name as name,
        jda.unit_code as parentCode
        from jczz_doorplate_address jda
        where 1=1
        and floor != ''
        and house_name != ''
        and doorplate_type = '户室牌'
        and nei_code = #{houseParam.code}
        <include refid="filterHouseGrid"/>
        )
    </select>
 
    <!--查询所有户室数据-->
    <select id="getHouseList" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        select jda.* from jczz_doorplate_address jda
        left join jczz_house jh on jh.house_code = jda.address_code
        where 1=1
        and jh.house_code is null
        and doorplate_type = '户室牌'
        <if test="townName!=null and townName!=''">
            and jda.town_street_name like concat('%',#{townName},'%')
        </if>
        limit 0,1000
    </select>
 
    <!--查询商超-->
    <select id="getPlaceRelList" resultType="org.springblade.common.node.TreeStringNode">
        select building_name as id,building_name as name,4 as addressType from jczz_place_rel jpl
        join jczz_place jp on jpl.place_id = jp.id and jp.is_deleted = 0
        where jpl.is_deleted = 0
        <if test="houseParam.communityName!=null and houseParam.communityName!=''">
            and community_name like concat('%',#{houseParam.communityName},'%')
        </if>
        group by building_name
    </select>
 
    <!--查询商超详情集合-->
    <select id="getPlaceRelDetailList" resultType="org.springblade.modules.doorplateAddress.vo.FuncNode">
        select jp.id as addressCode,
        jpl.grid_name as unitName,
        jpl.community_code as unitCode,
        doorplate_num as floor,
        4 as addressType
        from jczz_place_rel jpl
        join jczz_place jp on jpl.place_id = jp.id and jp.is_deleted = 0
        where jpl.is_deleted = 0
        and doorplate_num!=''
        <if test="houseParam.communityName!=null and houseParam.communityName!=''">
            and community_name like concat('%',#{houseParam.communityName},'%')
        </if>
        <if test="houseParam.buildingName!=null and houseParam.buildingName!=''">
            and building_name = #{houseParam.buildingName}
        </if>
    </select>
 
    <!--查询小区集合-->
    <select id="getAoiList" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        select nei_code,aoi_code,ifnull(aoi_name,sub_aoi) as aoi_name,x,y,address_name from  jczz_doorplate_address
        where 1=1
        <choose>
            <when test="list != null and list.size()>0">
                and id in
                <foreach collection="list" item="id" separator ="," open="("  close=")">
                    #{id}
                </foreach>
            </when>
            <otherwise>
                and id in ('')
            </otherwise>
        </choose>
    </select>
 
    <!--查询所有的地址表id集合-->
    <select id="getAoiCodeList" resultType="java.lang.Long">
        select
        min(id)
        from jczz_doorplate_address
        where aoi_code != "" and aoi_name !=""
                and doorplate_type = '大门牌'
        GROUP BY aoi_code
        union all
        (
        select
        min(id)
        from jczz_doorplate_address
        where aoi_code != "" and sub_aoi != ""
                and doorplate_type = '大门牌'
        group by aoi_code
        )
    </select>
 
    <!--查询所有的地址表和场所表差集集合(小区和非小区的)-->
    <select id="getNotInPlaceList" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        select jda.* from jczz_doorplate_address jda
        left join jczz_place jp on jda.address_code=jp.house_code and jp.is_deleted = 0
        where 1=1
        and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
        and jp.id is null
        <if test="townName!=null and townName!=''">
            and jda.town_street_name like concat('%',#{townName},'%')
        </if>
        limit 0,1000
    </select>
 
    <!--查询未入库的场所-->
    <select id="getNotPlaceListCount" resultType="java.lang.Integer">
        select count(*) from jczz_doorplate_address jda
        left join jczz_place jp on jda.address_code=jp.house_code and jp.is_deleted = 0
        where 1=1
        and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
        and jp.id is null
        <if test="townName!=null and townName!=''">
            and jda.town_street_name like concat('%',#{townName},'%')
        </if>
    </select>
 
    <!--查询场所标准地址数据-->
    <select id="getPlaceList" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        select jda.*
        from jczz_doorplate_address jda
        left join jczz_grid_range jgr on jda.address_code = jgr.house_code
        where 1=1
--         and (doorplate_type = '小门牌' or (doorplate_type = '中门牌' and address_level = 1))
        <if test="doorplateAddress.addressName!=null and doorplateAddress.addressName!=''">
            and jda.address_name like concat('%',#{doorplateAddress.addressName},'%')
        </if>
        <if test="doorplateAddress.poi!=null and doorplateAddress.poi!=''">
            and jda.poi like concat('%',#{doorplateAddress.poi},'%')
        </if>
        <if test="doorplateAddress.addressCode!=null and doorplateAddress.addressCode!=''">
            and jda.address_code in
            <foreach collection="addressCode.split(',')" item="addressCode" open="(" close=")" separator=",">
                #{addressCode}
            </foreach>
        </if>
        <if test="isAdministrator==2">
            <choose>
                <when test="doorplateAddress.roleName != null and doorplateAddress.roleName != ''">
                    <if test="doorplateAddress.roleName=='wgy'">
                        <choose>
                            <when test="gridCodeList !=null and gridCodeList.size()>0">
                                and jgr.grid_code in
                                <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                            </when>
                            <otherwise>
                                and jgr.grid_code in ('')
                            </otherwise>
                        </choose>
                    </if>
                    <if test="doorplateAddress.roleName=='mj'">
                        <choose>
                            <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                and jda.nei_code in
                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                            </when>
                            <otherwise>
                                and jda.nei_code in ('')
                            </otherwise>
                        </choose>
                    </if>
                </when>
                <otherwise>
                    <choose>
                        <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                            and
                            (
                            jgr.grid_code in
                            <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                #{code}
                            </foreach>
                            or
                            jda.nei_code in
                            <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                #{code}
                            </foreach>
                            )
                        </when>
                        <otherwise>
                            and
                            (
                            jgr.grid_code in ('') or jda.nei_code in ('')
                            )
                        </otherwise>
                    </choose>
                </otherwise>
            </choose>
        </if>
        limit 0,#{size}
    </select>
 
    <!--查询地址表详情-->
    <select id="getDoorplateAddressVODetail" resultMap="detailMap">
        select
        jda.*,
        jh.id as hid,
        jh.name as hname,
        jh.phone_number,
        jh.card_no,
        jh.occupation,
        jh.current_address,
        jp.id as pid,
        jp.principal,
        jp.principal_phone,
        jp.principal_id_card,
        case
        when jh.id is not null then 1
        when jp.id is not null then 2
        when jp.id is not null and jh.id is not null then 3
        when jp.id is null and jh.id is null then 4
        end as addType
        from jczz_doorplate_address jda
        left join jczz_place jp on jp.house_code = jda.address_code and jp.is_deleted = 0
        left join jczz_household jh on jh.house_code = jda.address_code and jh.is_deleted = 0 and jh.relationship = 1
        where address_code = #{doorplateAddress.addressCode}
    </select>
 
    <!--门牌地址详情查询-->
    <resultMap id="detailMap" type="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO"
               autoMapping="true">
        <id property="id" column="id"/>
        <association property="place" javaType="org.springblade.modules.place.vo.PlaceVO">
            <id property="id" column="pid"/>
            <result property="principal" column="principal"/>
            <result property="principalPhone" column="principal_phone"/>
            <result property="principalIdCard" column="principal_id_card"/>
        </association>
        <collection property="householdList" javaType="java.util.List"
                    ofType="org.springblade.modules.house.vo.HouseholdVO">
            <id property="id" column="hid"/>
            <result property="name" column="hname"/>
            <result property="phoneNumber" column="phone_number"/>
            <result property="cardNo" column="card_no"/>
            <result property="occupation" column="occupation"/>
            <result property="currentAddress" column="current_address"/>
        </collection>
    </resultMap>
 
    <!--查询所有的社区集合信息-->
    <select id="getAllCommunityList" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        SELECT
            jda.nei_code,
            jda.nei_name,
            jda.town_street_code
        FROM
            jczz_doorplate_address jda
        WHERE
            1 = 1
        GROUP BY
            jda.nei_code,
            jda.nei_name,
            jda.town_street_code
    </select>
 
 
    <select id="getHouseBuildingCode"
            resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO">
 
        SELECT DISTINCT
            jda.building_code,
            jda.building_name
        FROM
            jczz_doorplate_address jda
                LEFT JOIN jczz_district jd ON jd.aoi_code = jda.aoi_code
        WHERE
            jd.id = #{districtId}
          and jda.building_code is not null
 
    </select>
 
 
    <!--查询所有户室数据-->
    <select id="getNotHouseListCount" resultType="java.lang.Integer">
        select count(*) from jczz_doorplate_address jda
        left join jczz_house jh on jh.house_code = jda.address_code
        where 1=1
        and jh.house_code is null
        and doorplate_type = '户室牌'
        <if test="townName!=null and townName!=''">
            and jda.town_street_name like concat('%',#{townName},'%')
        </if>
        limit 0,1000
    </select>
 
    <!--查询网格范围表未绑定的地址表信息数量-->
    <select id="getNotBindGridRangeDoorListCount" resultType="java.lang.Integer">
        select count(*) from jczz_doorplate_address jda
        left join jczz_grid_range jgr on jgr.house_code = jda.address_code
        where 1=1
        and jgr.house_code is null
        <if test="townName!=null and townName!=''">
            and jda.town_street_name like concat('%',#{townName},'%')
        </if>
        <if test="communityName!=null and communityName!=''">
            and jda.nei_name like concat('%',#{communityName},'%')
        </if>
        limit 0,1000
    </select>
 
    <!--查询所有未匹配的网格范围地址数据-->
    <select id="getNotBindGridRangeDoorList" resultType="org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity">
        select
        jda.address_code,
        jda.aoi_code,
        jda.building_code,
        jda.x,
        jda.y
        from jczz_doorplate_address jda
        left join jczz_grid_range jgr on jgr.house_code = jda.address_code
        where 1=1
        and jgr.house_code is null
        <if test="townName!=null and townName!=''">
            and jda.town_street_name like concat('%',#{townName},'%')
        </if>
        <if test="communityName!=null and communityName!=''">
            and jda.nei_name like concat('%',#{communityName},'%')
        </if>
        limit 0,1000
    </select>
 
    <!--查询所有未匹配的网格范围地址数据-->
    <select id="getDoorplateAddressDetailByHouseId" resultType="org.springblade.modules.doorplateAddress.vo.DoorplateAddressVO">
        select
        jda.*
        from jczz_doorplate_address jda
        left join jczz_house jh on jh.house_code = jda.address_code and jh.is_deleted = 0
        where 1=1
        and jh.id = #{houseId}
    </select>
</mapper>