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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
<?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.house.mapper.HouseMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="houseResultMap" type="org.springblade.modules.house.entity.HouseEntity">
        <result column="id" property="id"/>
        <result column="house_code" property="houseCode"/>
        <result column="district_code" property="districtCode"/>
        <result column="district_name" property="districtName"/>
        <result column="house_name" property="houseName"/>
        <result column="phone" property="phone"/>
        <result column="area" property="area"/>
        <result column="property_price" property="propertyPrice"/>
        <result column="service_due" property="serviceDue"/>
        <result column="floor" property="floor"/>
        <result column="building" property="building"/>
        <result column="unit" property="unit"/>
        <result column="room" property="room"/>
        <result column="building_no" property="buildingNo"/>
        <result column="image_urls" property="imageUrls"/>
        <result column="create_user" property="createUser"/>
        <result column="created_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="remark" property="remark"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
 
    <!--过滤网格数据-->
    <sql id="filterHouseGrid">
        <if test="houseParam.roleName!=null and houseParam.roleName!=''">
            <if test="houseParam.roleName=='网格员'">
                <choose>
                    <when test="list != null and list.size()>0">
                        and house_code in
                        <foreach collection="list" item="houseCode" separator="," open="(" close=")">
                            #{houseCode}
                        </foreach>
                    </when>
                    <otherwise>
                        and house_code in ('')
                    </otherwise>
                </choose>
            </if>
        </if>
    </sql>
 
    <sql id="selectHouse">
        select
            id,
            house_code,
            district_code,
            district_name,
            house_name,
            phone,
            area,
            property_price,
            service_due,
            floor,
            building,
            unit,
            room,
            building_no,
            image_urls,
            create_user,
            create_time,
            update_user,
            update_time,
            remark,
            is_deleted
        from
            jczz_house
    </sql>
 
 
    <!--房屋详情-->
    <resultMap id="houseAndHouseLabelMap" type="org.springblade.modules.house.vo.HouseVO" autoMapping="true">
        <result column="id" property="id"/>
        <result column="house_code" property="houseCode"/>
        <result column="district_code" property="districtCode"/>
        <result column="district_name" property="districtName"/>
        <result column="house_name" property="houseName"/>
        <result column="phone" property="phone"/>
        <result column="area" property="area"/>
        <result column="property_price" property="propertyPrice"/>
        <result column="service_due" property="serviceDue"/>
        <result column="floor" property="floor"/>
        <result column="building" property="building"/>
        <result column="unit" property="unit"/>
        <result column="room" property="room"/>
        <result column="building_no" property="buildingNo"/>
        <result column="image_urls" property="imageUrls"/>
        <result column="create_user" property="createUser"/>
        <result column="created_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="remark" property="remark"/>
        <result column="is_deleted" property="isDeleted"/>
        <collection property="userHouseLabelVOList" javaType="java.util.List" select="selectHouseLabelPage"
                    column="house_code"
                    ofType="org.springblade.modules.house.vo.UserHouseLabelVO" autoMapping="true">
        </collection>
    </resultMap>
 
 
    <select id="selectHouseLabelPage" resultType="org.springblade.modules.house.vo.HouseholdLabelVO">
        select
            id,
            house_code,
            label_id,
            label_name,
            color,
            remark cremark,
            user_id,
            lable_type,
            household_id
        from
            jczz_user_house_label
        where house_code = #{houseCode} and lable_type = 2
    </select>
 
    <!--房屋详情-->
    <resultMap id="housePageAndHouseLabelMap" type="org.springblade.modules.house.vo.HouseVO" autoMapping="true">
        <id property="id" column="id"/>
        <collection property="userHouseLabelVOList" javaType="java.util.List"
                    ofType="org.springblade.modules.house.vo.UserHouseLabelVO" autoMapping="true">
            <id property="id" column="cid"/>
            <result property="remark" column="cremark"/>
        </collection>
    </resultMap>
 
    <!--自定义分页列表-->
    <select id="selectHousePage" resultMap="houseAndHouseLabelMap">
        select
        jh.*,
        concat(jh.building," ",jh.unit," ",jh.room) as address,
        br.town_name as townStreetName,br.name as neiName,
        jg.grid_name
        from jczz_house jh
        left join jczz_grid jg on jg.grid_code = jh.grid_code and jg.is_deleted = 0
        left join blade_region br on br.code = jg.community_code
        LEFT JOIN jczz_police_affairs_grid jpag on jh.jw_grid_code= jpag.jw_grid_code and jpag.is_deleted = 0
        <where>
            <if test="house.id != null ">and jh.id = #{house.id}</if>
            <if test="house.streetCode != null and house.streetCode != ''">
                and jda.town_street_code like concat('%',#{house.streetCode},'%')
            </if>
            <if test="house.houseCode != null  and house.houseCode != ''">and jh.house_code = #{house.houseCode}</if>
            <if test="house.districtCode != null  and house.districtCode != ''">and jh.district_code =
                #{house.districtCode}
            </if>
            <if test="house.districtName != null  and house.districtName != ''">
                and jh.district_name like concat('%',#{house.districtName},'%')
            </if>
            <if test="house.townStreetName!=null and house.townStreetName!=''">
                and br.town_name like concat('%',#{house.townStreetName},'%')
            </if>
            <if test="house.neiName!=null and house.neiName!=''">
                and br.name like concat('%',#{house.neiName},'%')
            </if>
            <if test="house.address!=null and house.address!=''">
                and jh.address like concat('%',#{house.address},'%')
            </if>
            <if test="house.houseName != null  and house.houseName != ''">and jh.house_name like
                concat('%',#{house.houseName},'%')
            </if>
            <if test="house.phone != null  and house.phone != ''">and jh.phone = #{house.phone}</if>
            <if test="house.area != null ">and jh.area = #{house.area}</if>
            <if test="house.propertyPrice != null ">and jh.property_price = #{house.propertyPrice}</if>
            <if test="house.serviceDue != null ">and jh.service_due = #{house.serviceDue}</if>
            <if test="house.floor != null ">and jh.floor = #{house.floor}</if>
            <if test="house.building != null  and house.building != ''">and jh.building = #{house.building}</if>
            <if test="house.unit != null  and house.unit != ''">and jh.unit = #{house.unit}</if>
            <if test="house.room != null  and house.room != ''">and jh.room = #{house.room}</if>
            <if test="house.buildingNo != null ">and jh.building_no = #{house.buildingNo}</if>
            <if test="isAdministrator==2">
                <choose>
                    <when test="house.roleName != null and house.roleName != ''">
                        <if test="house.roleName=='wgy'">
                            <choose>
                                <when test="gridCodeList !=null and gridCodeList.size()>0">
                                    and jh.grid_code in
                                    <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
                                        #{code}
                                    </foreach>
                                </when>
                                <otherwise>
                                    and jh.grid_code in ('')
                                </otherwise>
                            </choose>
                        </if>
                        <if test="house.roleName=='mj'">
                            <choose>
                                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                    and jpag.community_code in
                                    <foreach collection="regionChildCodesList" item="code" open="(" close=")"
                                             separator=",">
                                        #{code}
                                    </foreach>
                                </when>
                                <otherwise>
                                    and jpag.community_code in ('')
                                </otherwise>
                            </choose>
                        </if>
                    </when>
                    <otherwise>
                        <choose>
                            <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                and
                                (
                                jg.grid_code in
                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                                or
                                jpag.community_code in
                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                                )
                            </when>
                            <otherwise>
                                and
                                (
                                jg.grid_code in ('')
                                or
                                jpag.community_code in ('')
                                )
                            </otherwise>
                        </choose>
                    </otherwise>
                </choose>
            </if>
            <if test="house.parentId != null ">
                and jh.house_code in (
                SELECT DISTINCT
                juhl.house_code
                FROM
                jczz_user_house_label juhl
                LEFT JOIN jczz_label jl ON juhl.label_id = jl.id
                WHERE
                juhl.lable_type = 2
                <if test="house.labelId != null ">
                    AND jl.id = #{house.labelId}
                </if>
                <if test="house.parentId != null ">
                    AND jl.parent_id = #{house.parentId}
                </if>
                AND juhl.label_id IS NOT NULL
                )
            </if>
            and jh.is_deleted = 0
            ORDER BY
            jh.update_time desc,jh.id desc
        </where>
 
 
    </select>
 
    <!--房屋详情-->
    <resultMap id="houseAndHouseLabelDetailMap" type="org.springblade.modules.house.vo.HouseVO" autoMapping="true">
        <result column="id" property="id"/>
        <result column="house_code" property="houseCode"/>
        <result column="district_code" property="districtCode"/>
        <result column="district_name" property="districtName"/>
        <result column="house_name" property="houseName"/>
        <result column="phone" property="phone"/>
        <result column="area" property="area"/>
        <result column="property_price" property="propertyPrice"/>
        <result column="service_due" property="serviceDue"/>
        <result column="floor" property="floor"/>
        <result column="building" property="building"/>
        <result column="unit" property="unit"/>
        <result column="room" property="room"/>
        <result column="building_no" property="buildingNo"/>
        <result column="image_urls" property="imageUrls"/>
        <result column="create_user" property="createUser"/>
        <result column="created_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="remark" property="remark"/>
        <result column="is_deleted" property="isDeleted"/>
        <collection property="userHouseLabelVOList" javaType="java.util.List"
                    ofType="org.springblade.modules.house.vo.UserHouseLabelVO" autoMapping="true">
            <id property="id" column="cid"/>
            <result property="remark" column="cremark"/>
        </collection>
    </resultMap>
 
    <!--房屋自定义详情查询-->
    <select id="getHouseDetail" resultMap="houseAndHouseLabelDetailMap">
        select
        jh.*,
        jhl.id as cid,jhl.*,jhl.remark as cremark,
        br.code as neiCode,br.town_code as streetCode
        from jczz_house jh
        left join jczz_user_house_label jhl on jh.house_code = jhl.house_code and jhl.lable_type = 2
        left join jczz_grid jg on jg.grid_code = jh.grid_code and jg.is_deleted = 0
        left join blade_region br on br.code = jg.community_code
        where jh.is_deleted = 0
        <if test="house.houseCode!=null and house.houseCode!=''">
            and jh.house_code = #{house.houseCode}
        </if>
        <if test="house.id!=null">
            and jh.id = #{house.id}
        </if>
    </select>
 
    <!--房屋数据导出-->
    <select id="export" resultType="org.springblade.modules.house.excel.HouseExcel">
        select
        *,
        concat(building," ",unit," ",room) as address
        from jczz_house
        where is_deleted = 0
        <if test="house.id != null ">and id = #{house.id}</if>
        <if test="house.houseCode != null  and house.houseCode != ''">and house_code = #{house.houseCode}</if>
        <if test="house.districtCode != null  and house.districtCode != ''">and district_code = #{house.districtCode}
        </if>
        <if test="house.districtName != null  and house.districtName != ''">
            and district_name like concat('%',#{house.districtName},'%')
        </if>
        <if test="house.houseName != null  and house.houseName != ''">and house_name = #{house.houseName}</if>
        <if test="house.phone != null  and house.phone != ''">and phone = #{house.phone}</if>
        <if test="house.area != null ">and area = #{house.area}</if>
        <if test="house.propertyPrice != null ">and property_price = #{house.propertyPrice}</if>
        <if test="house.serviceDue != null ">and service_due = #{house.serviceDue}</if>
        <if test="house.floor != null ">and floor = #{house.floor}</if>
        <if test="house.building != null  and house.building != ''">and building = #{house.building}</if>
        <if test="house.unit != null  and house.unit != ''">and unit = #{house.unit}</if>
        <if test="house.room != null  and house.room != ''">and room = #{house.room}</if>
        <if test="house.buildingNo != null ">and building_no = #{house.buildingNo}</if>
    </select>
 
 
    <!--获取房屋树-->
    <select id="getHouseTree" resultType="org.springblade.modules.house.vo.HouseTree">
        SELECT
        district_code as code,
        district_name as name,
        jda.nei_code as parentCode
        FROM jczz_house jh
        left join
        (select nei_code,aoi_code from jczz_doorplate_address where nei_code = #{houseParam.code} group by
        nei_code,aoi_code) jda
        on jda.aoi_code = jh.district_code
        WHERE jda.nei_code = #{houseParam.code}
        <include refid="filterHouseGrid"/>
        GROUP BY district_code,district_name,nei_code
        union all
        (
        SELECT
        building as code,
        building as name,
        district_code as parentCode
        FROM jczz_house jh
        left join
        (select nei_code,aoi_code from jczz_doorplate_address where nei_code = #{houseParam.code} group by
        nei_code,aoi_code) jda
        on jda.aoi_code = jh.district_code
        WHERE jda.nei_code = #{houseParam.code}
        <include refid="filterHouseGrid"/>
        GROUP BY building,district_code
        )
        union all
        (
        select
        unit as code,
        unit name,
        building as parentCode
        FROM jczz_house jh
        left join
        (select nei_code,aoi_code from jczz_doorplate_address where nei_code = #{houseParam.code} group by
        nei_code,aoi_code) jda
        on jda.aoi_code = jh.district_code
        WHERE jda.nei_code = #{houseParam.code}
        <include refid="filterHouseGrid"/>
        group by unit,building
        )
        union all
        (
        select
        room as code,
        room name,
        unit as parentCode
        FROM jczz_house jh
        left join
        (select nei_code,aoi_code from jczz_doorplate_address where nei_code = #{houseParam.code} group by
        nei_code,aoi_code) jda
        on jda.aoi_code = jh.district_code
        WHERE jda.nei_code = #{houseParam.code}
        <include refid="filterHouseGrid"/>
        )
    </select>
 
 
    <select id="getHouseStatisticsOne" resultType="java.lang.Integer">
        SELECT
        count( 1 )
        FROM
        (
        SELECT DISTINCT
        jda.building_code
        FROM
        jczz_house jh
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jh.house_code
        WHERE
        jda.nei_code = #{code}
        AND jh.is_deleted = 0
        <if test="buildingCode != null  and buildingCode != ''">
            and jda.building_code=#{buildingCode}
        </if>
 
        <if test="unitCode != null  and unitCode != ''">
            and jda.unit_code=#{unitCode}
        </if>
 
        <if test="aoiCode != null  and aoiCode != ''">
            and jda.aoi_code=#{aoiCode}
        </if>
        <if test="userId != null and roleType == '1'">
            AND jda.address_code IN (
            SELECT DISTINCT
            jgr.house_code
            FROM
            jczz_grid jg
            LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
            LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
            WHERE
            jgm.user_id = #{userId}
            AND jg.is_deleted = 0
            )
        </if>
        <if test="userId != null and roleType == '3'">
            AND jda.address_code IN (SELECT
            jda.address_code
            FROM
            jczz_doorplate_address jda
            LEFT JOIN jczz_community jc ON jc.CODE = jda.nei_code
            WHERE
            jc.res_police_user_id like concat('%',#{userId},'%'))
            )
        </if>
        ) a
 
    </select>
 
 
    <select id="getHouseStatisticsTwo" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM
        jczz_doorplate_address jda
        LEFT JOIN jczz_house jh ON jda.address_code = jh.house_code AND jh.is_deleted = 0
        LEFT JOIN jczz_grid jg on jg.grid_code = jh.grid_code and jg.is_deleted = 0
        LEFT JOIN jczz_police_affairs_grid jpag on jh.jw_grid_code= jpag.jw_grid_code and jpag.is_deleted = 0
        WHERE
        jda.nei_code = #{code}
        and jda.doorplate_type = '户室牌'
        <choose>
            <when test="(buildingCode != null  and buildingCode != '') or
                (unitCode != null  and unitCode != '') or (aoiCode != null  and aoiCode != '')">
                <if test="buildingCode != null  and buildingCode != ''">
                    and jda.building_code=#{buildingCode}
                </if>
                <if test="unitCode != null  and unitCode != ''">
                    and jda.unit_code=#{unitCode}
                    AND jda.unit_code is not null
                </if>
                <if test="aoiCode != null  and aoiCode != ''">
                    and jda.aoi_code=#{aoiCode}
                </if>
            </when>
            <otherwise>
                <if test="isAdministrator==2">
                    <choose>
                        <when test="house.roleName != null and house.roleName != ''">
                            <if test="house.roleName=='wgy'">
                                <choose>
                                    <when test="gridCodeList !=null and gridCodeList.size()>0">
                                        and jh.grid_code in
                                        <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
                                            #{code}
                                        </foreach>
                                    </when>
                                    <otherwise>
                                        and jh.grid_code in ('')
                                    </otherwise>
                                </choose>
                            </if>
                            <if test="house.roleName=='mj'">
                                <choose>
                                    <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                        and jpag.community_code in
                                        <foreach collection="regionChildCodesList" item="code" open="(" close=")"
                                                 separator=",">
                                            #{code}
                                        </foreach>
                                    </when>
                                    <otherwise>
                                        and jpag.community_code in ('')
                                    </otherwise>
                                </choose>
                            </if>
                        </when>
                        <otherwise>
                            <choose>
                                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                    and
                                    (
                                    jg.grid_code in
                                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                        #{code}
                                    </foreach>
                                    or
                                    jpag.community_code in
                                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                        #{code}
                                    </foreach>
                                    )
                                </when>
                                <otherwise>
                                    and
                                    (
                                    jg.grid_code in ('')
                                    or
                                    jpag.community_code in ('')
                                    )
                                </otherwise>
                            </choose>
                        </otherwise>
                    </choose>
                </if>
            </otherwise>
        </choose>
    </select>
 
 
    <select id="getHouseStatisticsThree" resultType="java.lang.Integer">
        SELECT
        count( 1 )
        FROM
        jczz_household jhh
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jhh.house_code
        WHERE
        jda.nei_code = #{code}
        AND jhh.is_deleted = 0
        and jda.doorplate_type = '户室牌'
        <if test="buildingCode != null  and buildingCode != ''">
            and jda.building_code=#{buildingCode}
        </if>
 
        <if test="unitCode != null  and unitCode != ''">
            and jda.unit_code=#{unitCode}
            AND jda.unit_code is not null
        </if>
 
        <if test="aoiCode != null  and aoiCode != ''">
            and jda.aoi_code=#{aoiCode}
        </if>
        <if test="userId != null and roleType == '1'">
            AND jda.address_code IN (
            SELECT DISTINCT
            jgr.house_code
            FROM
            jczz_grid jg
            LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
            LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
            WHERE
            jgm.user_id = #{userId}
            AND jg.is_deleted = 0
            )
        </if>
        <if test="userId != null and roleType == '3'">
            AND jda.address_code IN (SELECT
            jda.address_code
            FROM
            jczz_doorplate_address jda
            LEFT JOIN jczz_community jc ON jc.CODE = jda.nei_code
            WHERE
            jc.res_police_user_id like concat('%',#{userId},'%'))
            )
        </if>
    </select>
 
 
    <select id="getHouseStatisticsFour" resultType="java.lang.Integer">
        SELECT
        count( 1 )
        FROM
        (
        SELECT DISTINCT
        jda.unit_code
        FROM
        jczz_house jh
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jh.house_code
        WHERE
        jda.nei_code = #{code}
        AND jh.is_deleted = 0
        AND jda.unit_code is not null
        <if test="buildingCode != null  and buildingCode != ''">
            and jda.building_code=#{buildingCode}
        </if>
 
        <if test="unitCode != null  and unitCode != ''">
            and jda.unit_code=#{unitCode}
        </if>
 
        <if test="aoiCode != null  and aoiCode != ''">
            and jda.aoi_code=#{aoiCode}
        </if>
        <if test="userId != null and roleType == '1'">
            AND jda.address_code IN (
            SELECT DISTINCT
            jgr.house_code
            FROM
            jczz_grid jg
            LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
            LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
            WHERE
            jgm.user_id = #{userId}
            AND jg.is_deleted = 0
            )
        </if>
        <if test="userId != null and roleType == '3'">
            AND jda.address_code IN (SELECT
            jda.address_code
            FROM
            jczz_doorplate_address jda
            LEFT JOIN jczz_community jc ON jc.CODE = jda.nei_code
            WHERE
            jc.res_police_user_id like concat('%',#{userId},'%'))
            )
        </if>
        ) a
 
 
    </select>
 
    <select id="getHouseBuilding" resultType="java.lang.String">
        SELECT DISTINCT
            jh.building
        FROM
            jczz_house jh
            LEFT JOIN jczz_district jd ON jd.aoi_code = jh.district_code
        WHERE
            jd.id = #{districtCode}
            and jh.building is not null
    </select>
 
    <select id="getHouseUnit" resultType="java.lang.String">
         SELECT DISTINCT
            jh.unit
        FROM
            jczz_house jh
            LEFT JOIN jczz_district jd ON jd.aoi_code = jh.district_code
        WHERE
            jd.id = #{districtCode}
            and jd.building = #{building}
            and jh.building is not null
 
    </select>
 
    <select id="labelStatistics" resultType="java.util.Map">
        SELECT
        jl.id AS id,
        jl.parent_id AS parentId,
        jl.label_name AS name,
        jl.sort,
        (SELECT
        count( DISTINCT jhl.house_code )
        FROM
        jczz_user_house_label jhl
        LEFT JOIN jczz_house jh ON jhl.house_code = jh.house_code
        LEFT JOIN jczz_grid jg ON jg.grid_code = jh.grid_code
        AND jg.is_deleted = 0
        LEFT JOIN blade_region br ON br.CODE = jg.community_code
        <where>
            <if test="house.id != null ">and jh.id = #{house.id}</if>
            <if test="house.streetCode != null and house.streetCode != ''">
                and jda.town_street_code like concat('%',#{house.streetCode},'%')
            </if>
            <if test="house.houseCode != null  and house.houseCode != ''">and jh.house_code = #{house.houseCode}</if>
            <if test="house.districtCode != null  and house.districtCode != ''">and jh.district_code =
                #{house.districtCode}
            </if>
            <if test="house.districtName != null  and house.districtName != ''">
                and jh.district_name like concat('%',#{house.districtName},'%')
            </if>
            <if test="house.townStreetName!=null and house.townStreetName!=''">
                and br.town_name like concat('%',#{house.townStreetName},'%')
            </if>
            <if test="house.neiName!=null and house.neiName!=''">
                and br.name like concat('%',#{house.neiName},'%')
            </if>
            <if test="house.address!=null and house.address!=''">
                and jh.address like concat('%',#{house.address},'%')
            </if>
            <if test="house.houseName != null  and house.houseName != ''">and jh.house_name like
                concat('%',#{house.houseName},'%')
            </if>
            <if test="house.phone != null  and house.phone != ''">and jh.phone = #{house.phone}</if>
            <if test="house.area != null ">and jh.area = #{house.area}</if>
            <if test="house.propertyPrice != null ">and jh.property_price = #{house.propertyPrice}</if>
            <if test="house.serviceDue != null ">and jh.service_due = #{house.serviceDue}</if>
            <if test="house.floor != null ">and jh.floor = #{house.floor}</if>
            <if test="house.building != null  and house.building != ''">and jh.building = #{house.building}</if>
            <if test="house.unit != null  and house.unit != ''">and jh.unit = #{house.unit}</if>
            <if test="house.room != null  and house.room != ''">and jh.room = #{house.room}</if>
            <if test="house.buildingNo != null ">and jh.building_no = #{house.buildingNo}</if>
            <if test="isAdministrator==2">
                <choose>
                    <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                        and jg.community_code in
                        <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                            #{code}
                        </foreach>
                    </when>
                </choose>
            </if>
            <if test="house.parentId != null ">
                <if test="house.labelId != null ">
                    AND jl.id = #{house.labelId}
                </if>
                <if test="house.parentId != null ">
                    AND jl.parent_id = #{house.parentId}
                </if>
                and jhl.label_id=jl.id
                AND jhl.lable_type = 2
                AND jhl.label_id IS NOT NULL
            </if>
            and jh.is_deleted = 0
        </where>
        ) count
        FROM
        jczz_label jl where is_deleted = 0
        <if test="house.parentId != null ">
            AND jl.parent_id = #{house.parentId}
        </if>
        and jl.id != '1002'
 
 
    </select>
 
 
    <select id="labelCommunityStatistics" resultType="java.util.Map">
        SELECT
        br.code,
        br.name,
        br.id
        FROM
        blade_region br
        <where>
            <if test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                br.code IN
                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                    #{code}
                </foreach>
            </if>
            and br.parent_code = '361102'
        </where>
    </select>
 
    <select id="getlabelCount" resultType="org.springblade.modules.label.vo.LabelVO">
 
        SELECT
        jl.label_name,
        (    SELECT
        count( DISTINCT jhl.house_code )
        FROM
        jczz_user_house_label jhl
        LEFT JOIN jczz_house jh ON jhl.house_code = jh.house_code
        LEFT JOIN jczz_grid jg ON jg.grid_code = jh.grid_code
        AND jg.is_deleted = 0
        LEFT JOIN jczz_community jc ON jc.CODE = jg.community_code
        LEFT JOIN blade_region br ON br.CODE = jg.community_code
        WHERE
        jhl.lable_type = 2
        AND jl.id = jhl.label_id
        AND jc.street_code = #{streetCode}
        <if test="house.townStreetName!=null and house.townStreetName!=''">
            and br.town_name like concat('%',#{house.townStreetName},'%')
        </if>
        <if test="house.neiName!=null and house.neiName!=''">
            and br.name like concat('%',#{house.neiName},'%')
        </if>
        <if test="house.neiName!=null and house.neiName!=''">
            and br.name like concat('%',#{house.neiName},'%')
        </if>
        <if test="house.address!=null and house.address!=''">
            and jh.address like concat('%',#{house.address},'%')
        </if>
        <if test="isAdministrator==2">
            <choose>
                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                    and jg.community_code in
                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                        #{code}
                    </foreach>
                </when>
            </choose>
        </if>
        <if test="house.parentId != null ">
            and jh.house_code in (
            SELECT DISTINCT
            juhl.house_code
            FROM
            jczz_user_house_label juhl
            LEFT JOIN jczz_label jl ON juhl.label_id = jl.id
            WHERE
            juhl.lable_type = 2
            <if test="house.labelId != null ">
                AND jl.id = #{house.labelId}
            </if>
            <if test="house.parentId != null ">
                AND jl.parent_id = #{house.parentId}
            </if>
            AND juhl.label_id IS NOT NULL
            )
        </if>
        ) num
        FROM
        jczz_label jl
        WHERE
        jl.parent_id = '1001'
        ORDER BY
        jl.sort DESC
 
    </select>
 
    <!--查询未绑定网格或警格的数据-->
    <select id="getNotBindGridOrJwGridList" resultType="org.springblade.modules.house.entity.HouseEntity">
        select id,lng,lat from jczz_house where is_deleted = 0 and lng != ''
        <if test="type == 1">
            and grid_code is null
        </if>
        <if test="type == 2">
            and jw_grid_code is null
        </if>
    </select>
 
    <!--按房屋标签统计-->
    <select id="getHouseLabelStatistic" resultType="java.util.Map">
        select a.label_name as labelName,ifnull(b.numbers,0) numbers from
        (
        select label_name from jczz_label where parent_id = 1001 and is_deleted = 0
        union all
        select '未知' as label_name
        ) a
        left join (
            select
            ifnull(juhl.label_name,'未知') labelName,
            count(*) as numbers
            from jczz_doorplate_address jda
            LEFT JOIN jczz_house jh on jda.address_code = jh.house_code and jh.is_deleted = 0
            LEFT JOIN jczz_grid jg on jg.grid_code = jh.grid_code and jg.is_deleted = 0
            LEFT JOIN blade_region br on br.code = jg.community_code
            LEFT JOIN jczz_police_affairs_grid jpag on jh.jw_grid_code= jpag.jw_grid_code and jpag.is_deleted = 0
            LEFT JOIN jczz_user_house_label juhl ON juhl.house_code = jh.house_code and juhl.lable_type = 2
            where jda.doorplate_type = '户室牌'
            <if test="house.communityCode != null  and house.communityCode != ''">
                and jda.nei_code = #{house.communityCode}
            </if>
            <if test="isAdministrator==2">
                <choose>
                    <when test="house.roleName != null and house.roleName != ''">
                        <if test="house.roleName=='wgy'">
                            <choose>
                                <when test="gridCodeList !=null and gridCodeList.size()>0">
                                    and jh.grid_code in
                                    <foreach collection="gridCodeList" item="code" open="(" close=")" separator=",">
                                        #{code}
                                    </foreach>
                                </when>
                                <otherwise>
                                    and jh.grid_code in ('')
                                </otherwise>
                            </choose>
                        </if>
                        <if test="house.roleName=='mj'">
                            <choose>
                                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                    and jpag.community_code in
                                    <foreach collection="regionChildCodesList" item="code" open="(" close=")"
                                             separator=",">
                                        #{code}
                                    </foreach>
                                </when>
                                <otherwise>
                                    and jpag.community_code in ('')
                                </otherwise>
                            </choose>
                        </if>
                    </when>
                    <otherwise>
                        <choose>
                            <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                                and
                                (
                                jg.grid_code in
                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                                or
                                jpag.community_code in
                                <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                    #{code}
                                </foreach>
                                )
                            </when>
                            <otherwise>
                                and
                                (
                                jg.grid_code in ('')
                                or
                                jpag.community_code in ('')
                                )
                            </otherwise>
                        </choose>
                    </otherwise>
                </choose>
            </if>
            group by juhl.label_name
        ) b on a.label_name =b.labelName
    </select>
 
    <!--查询对应的社区编号-->
    <select id="getCommunityCode" resultType="java.lang.String">
        SELECT
        jpag.community_code
        FROM
        jczz_house jh
        LEFT JOIN jczz_police_affairs_grid jpag on jh.jw_grid_code= jpag.jw_grid_code and jpag.is_deleted = 0
        where jh.is_deleted = 0
        and jh.id = #{id}
    </select>
 
    <!--查询所有房屋总数-->
    <select id="getAllListTotal" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM
        jczz_house jh
        where jh.is_deleted = 0
    </select>
 
    <!--查询所有的房屋-->
    <select id="getAllList" resultType="org.springblade.modules.house.vo.HouseVO">
        SELECT
        jh.*,
        jpag.community_code
        FROM
        jczz_house jh
        LEFT JOIN jczz_police_affairs_grid jpag on jh.jw_grid_code= jpag.jw_grid_code and jpag.is_deleted = 0
        where jh.is_deleted = 0
        limit #{i},#{size}
    </select>
 
    <!--查询无房屋状态的房屋数量-->
    <select id="getNotBindLabelHouseNum" resultType="java.lang.Integer">
        select count(*) from (
            SELECT
            jh.house_code,
            case when c.house_code is not null then 1
            when a.house_code is not null and b.house_code is null then 2
            when b.house_code is not null then 3
            end as status
            FROM
            jczz_house jh
            left join
            (
            select house_code from jczz_household where is_deleted = 0 and relationship = 1 and house_code is not null and house_code != '' GROUP BY house_code
            ) a on a.house_code = jh.house_code
            left join
            (
            select house_code from jczz_household where is_deleted = 0 and relationship = 18 and house_code is not null and house_code != '' GROUP BY house_code
            ) b on b.house_code = jh.house_code
            left join
            (
            select house_code from jczz_household where is_deleted = 0 and relationship is null or (relationship!=1 and relationship!=18) and house_code is not null and house_code != '' GROUP BY house_code
            ) c on c.house_code = jh.house_code
        ) d left join jczz_user_house_label juhl on d.house_code = juhl.house_code and lable_type = 2
        where juhl.id is null and status is not null
    </select>
 
    <!--查询无房屋状态的房屋列表集合-->
    <select id="getNotBindLabelHouseList" resultType="org.springblade.modules.house.vo.HouseVO">
        select d.* from (
            SELECT
            jh.house_code,
            case when c.house_code is not null then 1
            when a.house_code is not null and b.house_code is null then 2
            when b.house_code is not null then 3
            end as status
            FROM
            jczz_house jh
            left join
            (
            select house_code from jczz_household where is_deleted = 0 and relationship = 1 and house_code is not null and house_code != '' GROUP BY house_code
            ) a on a.house_code = jh.house_code
            left join
            (
            select house_code from jczz_household where is_deleted = 0 and relationship = 18 and house_code is not null and house_code != '' GROUP BY house_code
            ) b on b.house_code = jh.house_code
            left join
            (
            select house_code from jczz_household where is_deleted = 0 and relationship is null or (relationship!=1 and relationship!=18) and house_code is not null and house_code != '' GROUP BY house_code
            ) c on c.house_code = jh.house_code
        ) d left join jczz_user_house_label juhl on d.house_code = juhl.house_code and lable_type = 2
        where juhl.id is null and status is not null
        limit #{i},#{size}
    </select>
 
 
</mapper>