101captain
2021-11-11 78d1c9ee9b0c49f77c29d0535cb93c6d62c42f3a
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.panzhihua.service_community.dao.ComMngPopulationDAO">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.ComMngPopulationDO">
        <id column="id" property="id" />
        <result column="street_id" property="streetId" />
        <result column="act_id" property="actId" />
        <result column="village_id" property="villageId" />
        <result column="name" property="name" />
        <result column="sex" property="sex" />
        <result column="certificate_type" property="certificateType" />
        <result column="card_no" property="cardNo" />
        <result column="card_no_expiration_date" property="cardNoExpirationDate" />
        <result column="card_no_str" property="cardNoStr" />
        <result column="road" property="road" />
        <result column="door_no" property="doorNo" />
        <result column="floor" property="floor" />
        <result column="unit_no" property="unitNo" />
        <result column="house_no" property="houseNo" />
        <result column="political_outlook" property="politicalOutlook" />
        <result column="work_company" property="workCompany" />
        <result column="special_situation" property="specialSituation" />
        <result column="phone" property="phone" />
        <result column="out_or_local" property="outOrLocal" />
        <result column="census_register" property="censusRegister" />
        <result column="person_type" property="personType" />
        <result column="country" property="country" />
        <result column="date_of_departure" property="dateOfDeparture" />
        <result column="native_place" property="nativePlace" />
        <result column="nation_code" property="nationCode" />
        <result column="nation" property="nation" />
        <result column="is_rent" property="isRent" />
        <result column="culture_level" property="cultureLevel" />
        <result column="marriage" property="marriage" />
        <result column="healthy" property="healthy" />
        <result column="blood_type" property="bloodType" />
        <result column="religion" property="religion" />
        <result column="profession" property="profession" />
        <result column="person_status" property="personStatus" />
        <result column="death" property="death" />
        <result column="head_portrait" property="headPortrait" />
        <result column="monthly_income" property="monthlyIncome" />
        <result column="family_status" property="familyStatus" />
        <result column="birthday" property="birthday" />
        <result column="goal_in_china" property="goalInChina" />
        <result column="date_of_arrival" property="dateOfArrival" />
        <result column="label" property="label" />
        <result column="card_photo_front" property="cardPhotoFront" />
        <result column="card_photo_back" property="cardPhotoBack" />
        <result column="family_book" property="familyBook" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="remark" property="remark" />
        <result column="create_at" property="createAt" />
        <result column="update_at" property="updateAt" />
        <result column="residence" property="residence" />
        <result column="address" property="address" />
        <result column="house_id" property="houseId" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, street_id, act_id, village_id, name, sex, certificate_type, card_no, card_no_expiration_date, card_no_str, road, door_no, floor, unit_no, house_no, political_outlook, work_company, special_situation, phone, out_or_local, census_register, person_type, country, date_of_departure, native_place, nation_code, nation, is_rent, culture_level, marriage, healthy, blood_type, religion, profession, person_status, death, head_portrait, monthly_income, family_status, birthday, goal_in_china, date_of_arrival, label, card_photo_front, card_photo_back, family_book, delete_flag, remark, create_at, update_at, residence, address, house_id
    </sql>
 
    <update id="updateAll" parameterType="java.util.List">
        <foreach collection="populationList" item="item" index="index" separator=";">
            update com_mng_population
            <set>
                <if test="item.streetId != null">
                    `street_id` = #{item.streetId},
                </if>
                <if test="item.actId != null">
                    `act_id` = #{item.actId},
                </if>
                <if test="item.villageId != null">
                    `village_id` = #{item.villageId},
                </if>
                <if test="item.name != null and item.name !=&quot;&quot;">
                    `name` = #{item.name},
                </if>
                <if test="item.sex != null">
                    `sex` = #{item.sex},
                </if>
                <if test="item.certificateType != null and item.certificateType !=&quot;&quot;">
                    `certificate_type` = #{item.certificateType},
                </if>
                <if test="item.cardNo != null and item.cardNo !=&quot;&quot;">
                    `card_no` = #{item.cardNo},
                </if>
                <if test="item.cardNoExpirationDate != null">
                    `card_no_expiration_date` = #{item.cardNoExpirationDate},
                </if>
                <if test="item.cardNoStr != null and item.cardNoStr !=&quot;&quot;">
                    `card_no_str` = #{item.cardNoStr},
                </if>
                <if test="item.road != null and item.road !=&quot;&quot;">
                    `road` = #{item.road},
                </if>
                <if test="item.doorNo != null and item.doorNo !=&quot;&quot;">
                    `door_no` = #{item.doorNo},
                </if>
                <if test="item.floor != null and item.floor !=&quot;&quot;">
                    `floor` = #{item.floor},
                </if>
                <if test="item.unitNo != null and item.unitNo !=&quot;&quot;">
                    `unit_no` = #{item.unitNo},
                </if>
                <if test="item.houseNo != null and item.houseNo !=&quot;&quot;">
                    `house_no` = #{item.houseNo},
                </if>
                <if test="item.politicalOutlook != null">
                    `political_outlook` = #{item.politicalOutlook},
                </if>
                <if test="item.workCompany != null and item.workCompany !=&quot;&quot;">
                    `work_company` = #{item.workCompany},
                </if>
                <if test="item.specialSituation != null and item.specialSituation !=&quot;&quot;">
                    `special_situation` = #{item.specialSituation},
                </if>
                <if test="item.phone != null and item.phone !=&quot;&quot;">
                    `phone` = #{item.phone},
                </if>
                <if test="item.outOrLocal != null">
                    `out_or_local` = #{item.outOrLocal},
                </if>
                <if test="item.censusRegister != null and item.censusRegister !=&quot;&quot;">
                    `census_register` = #{item.censusRegister},
                </if>
                <if test="item.personType != null and item.personType !=&quot;&quot;">
                    `person_type` = #{item.personType},
                </if>
                <if test="item.country != null and item.country !=&quot;&quot;">
                    `country` = #{item.country},
                </if>
                <if test="item.dateOfDeparture != null">
                    `date_of_departure` = #{item.dateOfDeparture},
                </if>
                <if test="item.nativePlace != null and item.nativePlace !=&quot;&quot;">
                    `native_place` = #{item.nativePlace},
                </if>
                <if test="item.nationCode != null and item.nationCode !=&quot;&quot;">
                    `nation_code` = #{item.nationCode},
                </if>
                <if test="item.nation != null and item.nation !=&quot;&quot;">
                    `nation` = #{item.nation},
                </if>
                <if test="item.isRent != null">
                    `is_rent` = #{item.isRent},
                </if>
                <if test="item.cultureLevel != null">
                    `culture_level` = #{item.cultureLevel},
                </if>
                <if test="item.marriage != null">
                    `marriage` = #{item.marriage},
                </if>
                <if test="item.healthy != null and item.healthy !=&quot;&quot;">
                    `healthy` = #{item.healthy},
                </if>
                <if test="item.bloodType != null and item.bloodType !=&quot;&quot;">
                    `blood_type` = #{item.bloodType},
                </if>
                <if test="item.religion != null and item.religion !=&quot;&quot;">
                    `religion` = #{item.religion},
                </if>
                <if test="item.profession != null and item.profession !=&quot;&quot;">
                    `profession` = #{item.profession},
                </if>
                <if test="item.personStatus != null and item.personStatus !=&quot;&quot;">
                    `person_status` = #{item.personStatus},
                </if>
                <if test="item.death != null and item.death !=&quot;&quot;">
                    `death` = #{item.death},
                </if>
                <if test="item.headPortrait != null and item.headPortrait !=&quot;&quot;">
                    `head_portrait` = #{item.headPortrait},
                </if>
                <if test="item.monthlyIncome != null and item.monthlyIncome !=&quot;&quot;">
                    `monthly_income` = #{item.monthlyIncome},
                </if>
                <if test="item.familyStatus != null and item.familyStatus !=&quot;&quot;">
                    `family_status` = #{item.familyStatus},
                </if>
                <if test="item.birthday != null and item.birthday !=&quot;&quot;">
                    `birthday` = #{item.birthday},
                </if>
                <if test="item.goalInChina != null and item.goalInChina !=&quot;&quot;">
                    `goal_in_china` = #{item.goalInChina},
                </if>
                <if test="item.label != null and item.label !=&quot;&quot;">
                    `label` = #{item.label},
                </if>
                <if test="item.dateOfArrival != null">
                    `date_of_arrival` = #{item.dateOfArrival},
                </if>
                <if test="item.cardPhotoFront != null and item.cardPhotoFront !=&quot;&quot;">
                    `card_photo_front` = #{item.cardPhotoFront},
                </if>
                <if test="item.cardPhotoBack != null and item.cardPhotoBack !=&quot;&quot;">
                    `card_photo_back` = #{item.cardPhotoBack},
                </if>
                <if test="item.familyBook != null and item.familyBook !=&quot;&quot;">
                    `family_book` = #{item.familyBook},
                </if>
                <if test="item.deleteFlag != null">
                    `delete_flag` = #{item.deleteFlag},
                </if>
                <if test="item.remark != null and item.remark !=&quot;&quot;">
                    `remark` = #{item.remark},
                </if>
                <if test="item.residence != null and item.residence !=&quot;&quot;">
                    `residence` = #{item.residence},
                </if>
                <if test="item.address != null and item.address !=&quot;&quot;">
                    `address` = #{item.address},
                </if>
                <if test="item.houseId != null">
                    `house_id` = #{item.houseId},
                </if>
                `update_at` = NOW()
            </set>
            WHERE `id` = #{item.id}
        </foreach>
        ;
    </update>
 
    <select id="pagePopulationListApp" resultType="com.panzhihua.common.model.vos.grid.PopulationListVO">
        SELECT
        cmp.id,
        cmp.`name`,
        cmp.phone,
        cmp.card_no,
        cmpct.label,
        cmp.address,
        cmp.nation,
        cmp.political_outlook,
        cmv.lng,
        cmv.lat,
        cmp.sex
        FROM
        com_mng_population AS cmp
        LEFT JOIN com_mng_village AS cmv ON cmv.village_id = cmp.village_id
        LEFT JOIN com_mng_population_community_tags AS cmpct ON cmp.id = cmpct.population_id
        WHERE
        cmpct.community_id = #{populationListDTO.communityId}
        <if test = 'populationListDTO.keyWord != null and populationListDTO.keyWord != &quot;&quot;' >
            AND (cmp.`name` LIKE concat (#{populationListDTO.keyWord},'%') or cmp.card_no_str like concat (#{populationListDTO.keyWord},'%'))
        </if>
        <if test = 'populationListDTO.label != null and populationListDTO.label != &quot;&quot;' >
            AND cmpct.label LIKE concat ('%',#{populationListDTO.label},'%')
        </if>
        <if test="populationListDTO.outOrLocal != null">
            AND cmp.out_or_local = #{populationListDTO.outOrLocal}
        </if>
    </select>
 
    <resultMap id="selectMap" type="com.panzhihua.common.model.vos.community.VillageVO">
        <result property="value" column="villageId"/>
        <result property="label" column="villageName"/>
        <collection property="children" ofType="com.panzhihua.common.model.vos.community.BuildingVO"
                    column="{village_id = village_id}"
                    javaType="java.util.ArrayList">
            <result property="value" column="id"/>
            <result property="label" column="name"/>
        </collection>
    </resultMap>
 
    <select id="getSecondHouseAddress" resultMap="selectMap">
        select t.village_id as villageId,concat(t.alley,t.house_num,'号') as villageName,t1.id,concat(t1.unit_no,'栋',t1.floor,'单元',t1.code,'号') as name  from com_mng_village t left join com_mng_population_house t1 on t.village_id = t1.village_id where t.community_id=#{communityId}
    </select>
 
    <select id="getSecondHouse" resultMap="selectMap">
        select t.village_id as villageId,concat(t.alley,t.house_num,'号') as villageName,t1.id,concat(t1.unit_no,'栋') as name  from com_mng_village t left join com_mng_population_house t1  on t.village_id = t1.village_id where t.community_id=#{communityId} GROUP BY t.village_id,t1.unit_no
    </select>
 
 
 
    <delete id="deletePopulaitonRelation">
        delete from com_mng_population_community_tags where population_id in
        <foreach item="item" collection="ids" separator="," open="(" close=")" index="">
            #{item}
        </foreach>
    </delete>
 
    <select id="pagePopulation" resultType="com.panzhihua.common.model.vos.community.ComMngPopulationVO">
        SELECT   cmp.`name`,   cmp.id,   cmp.street_id,   cmp.act_id,
        cmp.village_id,   cmp.sex,   cmp.card_no,   cmp.road,   cmp.door_no,   cmp.floor,
        cmp.unit_no,   cmp.house_no,   cmp.political_outlook,   cmp.work_company,
        cmp.special_situation,   cmp.phone,   cmp.remark,   cmp.native_place,   cmp.nation,
        cmpct.label,    cmp.marriage,    cmp.culture_level,    cmp.profession,    cmp.out_or_local,
        cmp.census_register,    cmp.healthy,    cmp.birthday,    cmp.update_at,    cmp.address,
        cmp.is_rent FROM com_mng_population_community_tags as cmpct
        LEFT JOIN com_mng_population AS cmp ON cmp.id = cmpct.population_id
        <where>
            <if test='comMngPopulationVO.name != null and comMngPopulationVO.name != &quot;&quot;'>
                AND cmp.`name` LIKE concat(#{comMngPopulationVO.name},'%')    </if>
            <if test='comMngPopulationVO.label != null and comMngPopulationVO.label != &quot;&quot;'>
                AND cmpct.label LIKE concat('%',#{comMngPopulationVO.label},'%')    </if>
            <if test='comMngPopulationVO.actId != null'>   and cmpct.community_id = #{comMngPopulationVO.actId}
            </if>   <if test='comMngPopulationVO.outOrLocal != null'>
            and cmp.out_or_local = #{comMngPopulationVO.outOrLocal}    </if>
            <if test='comMngPopulationVO.villageId != null and comMngPopulationVO.villageId != &quot;&quot;'>
                and cmp.village_id = #{comMngPopulationVO.villageId}    </if>
            <if test='comMngPopulationVO.road != null and comMngPopulationVO.road != &quot;&quot;'>
                AND cmp.road = #{comMngPopulationVO.road}    </if>
            <if test='comMngPopulationVO.doorNo != null and comMngPopulationVO.doorNo != &quot;&quot;'>
                AND cmp.door_no = #{comMngPopulationVO.doorNo}    </if>
            <if test='comMngPopulationVO.floor != null and comMngPopulationVO.floor != &quot;&quot;'>
                AND cmp.floor = #{comMngPopulationVO.floor}    </if>
            <if test='comMngPopulationVO.isDeath != null'>
                AND cmp.death = #{comMngPopulationVO.isDeath}    </if>
            <if test='comMngPopulationVO.unitNo != null and comMngPopulationVO.unitNo != &quot;&quot;'>
                AND cmp.unit_no = #{comMngPopulationVO.unitNo}    </if>
            <if test='comMngPopulationVO.houseNo != null and comMngPopulationVO.houseNo != &quot;&quot;'>
                AND cmp.house_no = #{comMngPopulationVO.houseNo}    </if>
            <if test='comMngPopulationVO.sex != null and comMngPopulationVO.sex != &quot;&quot;'>
                AND cmp.sex = #{comMngPopulationVO.sex}    </if>
            <if test='comMngPopulationVO.ageStartTime != null and comMngPopulationVO.ageStartTime != &quot;&quot; and comMngPopulationVO.ageEndTime == null'>
                AND date_format(cmp.birthday,'%Y-%m-%d') <![CDATA[ <= ]]> #{comMngPopulationVO.ageStartTime}    </if>
            <if test='comMngPopulationVO.ageEndTime != null and comMngPopulationVO.ageEndTime != &quot;&quot; and comMngPopulationVO.ageStartTime == null'>
                AND date_format(cmp.birthday,'%Y-%m-%d') <![CDATA[ >= ]]> #{comMngPopulationVO.ageEndTime}    </if>
            <if test='comMngPopulationVO.ageStartTime != null and comMngPopulationVO.ageEndTime != null and comMngPopulationVO.ageStartTime == comMngPopulationVO.ageEndTime'>
                AND cmp.birthday BETWEEN #{comMngPopulationVO.ageStartTimeEnd} and #{comMngPopulationVO.ageEndTime}
            </if>
            <if test='comMngPopulationVO.ageStartTime != null and comMngPopulationVO.ageEndTime != null and comMngPopulationVO.ageStartTime != comMngPopulationVO.ageEndTime'>
                AND cmp.birthday BETWEEN #{comMngPopulationVO.ageEndTimeEnd} and #{comMngPopulationVO.ageStartTime}
            </if>
            <if test='comMngPopulationVO.nativePlace != null and comMngPopulationVO.nativePlace != &quot;&quot;'>
                AND cmp.native_place LIKE concat(#{comMngPopulationVO.nativePlace},'%')    </if>
            <if test='comMngPopulationVO.nation != null and comMngPopulationVO.nation != &quot;&quot;'>
                AND cmp.nation = #{comMngPopulationVO.nation}    </if>
            <if test='comMngPopulationVO.politicalOutlook != null and comMngPopulationVO.politicalOutlook != &quot;&quot;'>
                AND cmp.political_outlook = #{comMngPopulationVO.politicalOutlook}    </if>
            <if test='comMngPopulationVO.cardNo != null and comMngPopulationVO.cardNo != &quot;&quot;'>
                AND cmp.card_no = #{comMngPopulationVO.cardNo}    </if>
            <if test='comMngPopulationVO.remark != null and comMngPopulationVO.remark != &quot;&quot;'>
                AND cmp.remark = #{comMngPopulationVO.remark}    </if>
            <if test='comMngPopulationVO.keyWord != null and comMngPopulationVO.keyWord != &quot;&quot;'>
                AND (cmp.`name` like concat (#{comMngPopulationVO.keyWord},'%') or
                cmp.card_no_str = #{comMngPopulationVO.keyWord} or cmpct.label like concat ('%',#{comMngPopulationVO.keyWord},'%')
                )
            </if>
        </where>
        order by cmp.create_at desc
    </select>
 
    <select id="specialInputUser" resultType="com.panzhihua.common.model.vos.user.InputUserInfoVO">
        SELECT
            cmp.id,
            cmv.`name` AS areaName,
            cmv.alley AS alley,
            cmv.house_num AS houseNum,
            cmp.`name`,
            cmp.phone,
            cmpct.label AS tags,
            cmp.create_at
        FROM
            com_mng_population_community_tags as cmpct
            LEFT JOIN com_mng_population AS cmp ON cmp.id = cmpct.population_id
            LEFT JOIN com_mng_village AS cmv ON cmv.village_id = cmp.village_id
        WHERE
            cmpct.community_id = #{pageInputUserDTO.communityId}
            AND cmpct.label IS NOT NULL
            <if test='pageInputUserDTO.name != null and pageInputUserDTO.name != &quot;&quot;'>
                AND cmp.`name` LIKE concat(#{pageInputUserDTO.name},'%')
            </if>
            <if test='pageInputUserDTO.areaName != null and pageInputUserDTO.areaName != &quot;&quot;'>
                AND cmv.`alley` LIKE concat(#{pageInputUserDTO.areaName},'%')
            </if>
            <if test='pageInputUserDTO.tags != null and pageInputUserDTO.tags != &quot;&quot;'>
                AND cmpct.label like concat('%',#{pageInputUserDTO.tags},'%')
            </if>
        ORDER BY
            cmp.create_at DESC
    </select>
 
    <select id="query" resultType="com.panzhihua.common.model.vos.community.ComMngPopulationNoSecretVO">
        select * from com_mng_population
        <where>
            1=1
            <if test="commonPage.name !=null and commonPage.name.trim() !=''">
                and name like concat('%',#{commonPage.name},'%')
            </if>
            <if test="commonPage.paramId !=null and commonPage.paramId !=''">
                and act_id = #{commonPage.paramId}
            </if>
        </where>
    </select>
 
    <resultMap id="selectMap2" type="com.panzhihua.common.model.vos.community.ComMngPopulationDetailVO">
        <id column="id" property="id" />
        <result column="street_id" property="streetId" />
        <result column="act_id" property="actId" />
        <result column="village_id" property="villageId" />
        <result column="name" property="name" />
        <result column="sex" property="sex" />
        <result column="card_no" property="cardNo" />
        <result column="card_no_str" property="cardNoStr" />
        <result column="road" property="road" />
        <result column="door_no" property="doorNo" />
        <result column="floor" property="floor" />
        <result column="unit_no" property="unitNo" />
        <result column="phone" property="phone"/>
        <result column="house_no" property="houseNo" />
        <result column="political_outlook" property="politicalOutlook" />
        <result column="work_company" property="workCompany" />
        <result column="special_situation" property="specialSituation" />
        <result column="remark" property="remark" />
        <result column="create_at" property="createAt" />
        <result column="update_at" property="updateAt" />
        <result column="address" property="address" />
        <collection property="houseList" column="{id = id}" ofType="com.panzhihua.common.model.vos.user.ComMngHouseVo"  javaType="java.util.ArrayList">
            <result column="house_address" property="address"/>
            <result column="house_house_id" property="houseId" />
            <result column="house_residence" property="residence" />
            <result column="popul_id" property="populId"/>
            <result column="status" property="status"/>
            <result column="s_relation" property="relation"/>
            <result column="s_srelation_id" property="relationId"/>
        </collection>
    </resultMap>
 
    <select id="getById" resultMap="selectMap2">
         select t.*,t2.address as house_address,t2.house_id as house_house_id ,t2.residence as  house_residence ,t2.status,t2.relation as s_relation,t2.relation_id as s_relation_id,t2.popul_id from com_mng_population t left join ( select t.address,t1.house_id,t1.popul_id,t1.relation,t1.relation_id,t.status,t1.residence from com_mng_population_house t left join com_mng_population_house_user t1 on t.id = t1.house_id) t2 on t.id = t2.popul_id where t.id =#{id}
    </select>
 
    <select id="getPopulationDetailApp" resultType="com.panzhihua.common.model.vos.grid.PopulationDetailVO">
        SELECT
            cmp.id,
            cmp.`name`,
            cmp.phone,
            cmp.card_no,
            cmp.address,
            cmp.culture_level,
            cmp.nation,
            cmp.political_outlook,
            cmp.sex,
            cmp.birthday,
            cmp.native_place,
            cmp.healthy,
            cmp.is_rent,
            cmv.alley AS road,
            cmv.house_num AS doorNo,
            cmp.floor,
            cmp.unit_no,
            cmp.house_no,
            cmp.work_company,
            cmp.census_register,
            cmp.out_or_local,
            cmp.remark,
            cmp.marriage
        FROM
            com_mng_population AS cmp
            LEFT JOIN com_mng_village AS cmv ON cmv.village_id = cmp.village_id
        WHERE
            cmp.id = #{populationId}
    </select>
 
    <select id="getCommunityTagList" resultType="com.panzhihua.common.model.vos.community.ComMngPopulationCommunityTagsVo">
        SELECT
            cmpct.population_id,
            cmpct.community_id,
            cmpct.label,
            ca.`name` AS communityName
        FROM
            com_mng_population_community_tags AS cmpct
            LEFT JOIN com_act AS ca ON ca.community_id = cmpct.community_id
        WHERE
            cmpct.population_id = #{populationId}
    </select>
 
    <select id="getGridPopulationAdminList" resultType="com.panzhihua.common.model.vos.grid.admin.ComMngPopulationListVO">
        SELECT  cmp.id,   cmp.`name` AS userName,
        cmpct.label,   cmp.card_no,   cmp.card_no_str,   cmp.sex,   cmp.address,
        cmp.political_outlook,   cmp.census_register,   cmp.house_id,   cmp.phone,
        IFNULL(cmp.house_id,0) as isHouse,
        ( SELECT event_status FROM event_visiting_tasks WHERE event_status in (1,2,3,5) AND visiter_id = cmp.id ORDER BY create_at DESC LIMIT 1 ) AS eventStatus,
        ( SELECT create_at FROM event_visiting_tasks WHERE event_status in (1,2,3,5) AND visiter_id = cmp.id ORDER BY create_at DESC LIMIT 1 ) AS createAt
        FROM
        com_mng_population AS cmp left join com_mng_population_community_tags as cmpct on cmp.id = cmpct.population_id where 1=1
        <if test='populationListDTO.keyWord != null and populationListDTO.keyWord != &quot;&quot;'>
            AND (cmp.name like concat (#{populationListDTO.keyWord},'%') or cmp.card_no = #{populationListDTO.cardNo} or cmp.address like concat (#{populationListDTO.keyWord},'%'))
        </if>  <if test='populationListDTO.label != null and populationListDTO.label != &quot;&quot;'>
        AND cmpct.label like concat ('%',#{populationListDTO.label},'%')  </if>
        <if test='populationListDTO.sex != null'> AND cmp.sex = #{populationListDTO.sex}  </if>
        <if test='populationListDTO.isHouse != null and populationListDTO.isHouse == 1'>
            AND cmp.house_id is not null  </if>
        <if test='populationListDTO.isHouse != null and populationListDTO.isHouse == 2'>
            AND cmp.house_id is null  </if>  <if test='populationListDTO.communityId != null'>
        AND cmpct.community_id = #{populationListDTO.communityId}  </if>
        <if test='populationListDTO.politicalOutlook != null'>
            AND cmp.political_outlook = #{populationListDTO.politicalOutlook}  </if>
    </select>
 
    <select id="getEventScreenLeftDown" resultType="com.panzhihua.common.model.vos.community.screen.event.EventLeftDownStatisticsVO">
        SELECT    count( e.id ) AS eventZATotal,    IFNULL((     SELECT
        count( e1.id )      FROM      `event` AS e1
        LEFT JOIN event_grid_data AS egd1 ON egd1.id = e1.grid_id      WHERE
        egd1.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 1       AND event_deal_status = 4
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e1.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e1.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS yesEventZATotal,    IFNULL((     SELECT      count( e2.id )      FROM
        `event` AS e2      LEFT JOIN event_grid_data AS egd2 ON egd2.id = e2.grid_id      WHERE
        egd2.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 5       AND event_status = 2
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e2.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e2.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS eventTFTotal,    IFNULL((     SELECT      count( e3.id )      FROM      `event` AS e3
        LEFT JOIN event_grid_data AS egd3 ON egd3.id = e3.grid_id      WHERE
        egd3.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 5       AND event_deal_status = 4
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e3.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e3.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS yesEventTFTotal,    IFNULL((     SELECT      count( e4.id )      FROM
        `event` AS e4      LEFT JOIN event_grid_data AS egd4 ON egd4.id = e4.grid_id      WHERE
        egd4.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 6       AND event_status = 2
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e4.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e4.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS eventTSTotal,    IFNULL((     SELECT      count( e5.id )      FROM      `event` AS e5
        LEFT JOIN event_grid_data AS egd5 ON egd5.id = e5.grid_id      WHERE
        egd5.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 6       AND event_deal_status = 4
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e5.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e5.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS yesEventTSTotal,    IFNULL((     SELECT      count( e6.id )      FROM
        `event` AS e6      LEFT JOIN event_grid_data AS egd6 ON egd6.id = e6.grid_id      WHERE
        egd6.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 3       AND event_status = 2
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e6.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e6.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS eventMDTotal,    IFNULL((     SELECT      count( e7.id )      FROM      `event` AS e7
        LEFT JOIN event_grid_data AS egd7 ON egd7.id = e7.grid_id      WHERE
        egd7.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 3       AND event_deal_status = 4
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e7.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e7.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS yesEventMDTotal,    IFNULL((     SELECT      count( e8.id )      FROM
        `event` AS e8      LEFT JOIN event_grid_data AS egd8 ON egd8.id = e8.grid_id      WHERE
        egd8.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 4       AND event_status = 2
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e8.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e8.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS eventBWDTotal,    IFNULL((     SELECT      count( e9.id )      FROM      `event` AS e9
        LEFT JOIN event_grid_data AS egd9 ON egd9.id = e9.grid_id      WHERE
        egd9.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 4       AND event_deal_status = 4
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e9.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e9.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS yesEventBWDTotal,    IFNULL((     SELECT      count( e10.id )      FROM
        `event` AS e10      LEFT JOIN event_grid_data AS egd10 ON egd10.id = e10.grid_id      WHERE
        egd10.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 2       AND event_status = 2
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e10.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e10.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS eventGGTotal,    IFNULL((     SELECT      count( e11.id )      FROM
        `event` AS e11      LEFT JOIN event_grid_data AS egd11 ON egd11.id = e11.grid_id      WHERE
        egd11.grid_community_id = #{screenEventDTO.communityId}       AND event_category = 1
        AND event_type = 2       AND event_deal_status = 4
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e11.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND e11.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>      ),     0
        ) AS yesEventGGTotal,
        IFNULL(( SELECT count( id ) FROM com_act_easy_photo WHERE del_tag = 0  AND community_id = #{screenEventDTO.communityId}
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>   ), 0 ) AS eventSSPTotal,
        IFNULL(( SELECT count( id ) FROM com_act_easy_photo WHERE del_tag = 0 AND `status` = 4 AND community_id = #{screenEventDTO.communityId}
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
            AND create_at <![CDATA[<=]]> #{screenEventDTO.endTime}    </if>   ), 0 ) AS yesEventSSPTotal
        FROM    `event` AS e    LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id    WHERE
        egd.grid_community_id = #{screenEventDTO.communityId}     AND event_status = 2 AND event_category = 1
        AND event_type = 1
        <if test='screenEventDTO.startTime != null and screenEventDTO.startTime != &quot;&quot;'>
            AND e.create_at <![CDATA[>=]]> #{screenEventDTO.startTime}    </if>
        <if test='screenEventDTO.endTime != null and screenEventDTO.endTime != &quot;&quot;'>
        AND e.create_at <![CDATA[<=]]> #{screenEventDTO.endTime}
        </if>
    </select>
 
    <update id="updatePopulationUnit">
        update com_mng_population set unit_no = #{newUnitNo} where village_id = #{villageId} and floor = #{floor} and unit_no = #{oldUnitNo}
    </update>
</mapper>