罗元桥
2021-06-17 a7b550f95172e29d71aa38dca45cacf7f31949b8
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
package com.panzhihua.service_community.dao;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.model.dtos.community.ComMngPopulationDTO;
import com.panzhihua.common.model.dtos.user.PageInputUserDTO;
import com.panzhihua.common.model.vos.area.AreaAddressVO;
import com.panzhihua.common.model.vos.community.ComActMessageVO;
import com.panzhihua.common.model.vos.community.ComMngPopulationTotalVO;
import com.panzhihua.common.model.vos.community.ComMngPopulationVO;
import com.panzhihua.common.model.vos.community.screen.civil.CivilPopulationStatisticsVO;
import com.panzhihua.common.model.vos.community.screen.civil.CivilVillageStatisticsVO;
import com.panzhihua.common.model.vos.community.screen.event.*;
import com.panzhihua.common.model.vos.community.screen.index.*;
import com.panzhihua.common.model.vos.grid.EventGridDataVO;
import com.panzhihua.common.model.vos.user.*;
import com.panzhihua.common.model.vos.community.PageComActMessageVO;
import com.panzhihua.common.model.vos.user.ComHouseMemberVo;
import com.panzhihua.common.model.vos.user.ComMngFamilyInfoVO;
import com.panzhihua.common.model.vos.user.InputUserInfoVO;
import com.panzhihua.common.model.vos.user.UserElectronicFileVO;
import com.panzhihua.service_community.model.dos.ComMngPopulationDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 实有人口Dao
 */
@Mapper
public interface ComMngPopulationDAO extends BaseMapper<ComMngPopulationDO> {
 
    @Select("<script> " +
            "SELECT " +
            "cmp.`name`, " +
            "cmp.id, " +
            "cmp.street_id, " +
            "cmp.act_id, " +
            "cmp.village_id, " +
            "cmp.sex, " +
            "cmp.age, " +
            "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, " +
            "cmv.alley, " +
            "cmp.native_place, " +
            "cmp.nation  " +
            "FROM  " +
            "com_mng_population AS cmp " +
            "LEFT JOIN com_mng_village AS cmv ON cmv.village_id = cmp.village_id " +
            "<where>" +
            "<if test='comMngPopulationVO.name != null and comMngPopulationVO.name.trim() != &quot;&quot;'>" +
            "AND cmp.`name` LIKE concat(#{comMngPopulationVO.name},'%') " +
            " </if> " +
            "<if test='comMngPopulationVO.road != null and comMngPopulationVO.road.trim() != &quot;&quot;'>" +
            "AND cmp.road LIKE concat(#{comMngPopulationVO.road},'%') " +
            " </if> " +
            "<if test='comMngPopulationVO.doorNo != null and comMngPopulationVO.doorNo.trim() != &quot;&quot;'>" +
            "AND cmp.door_no = #{comMngPopulationVO.doorNo} " +
            " </if> " +
            "<if test='comMngPopulationVO.alley != null and comMngPopulationVO.alley.trim() != &quot;&quot;'>" +
            "AND cmv.alley LIKE concat(#{comMngPopulationVO.alley},'%') " +
            " </if> " +
            "<if test='comMngPopulationVO.sex != null and comMngPopulationVO.sex.trim() != &quot;&quot;'>" +
            "AND cmp.sex = #{comMngPopulationVO.sex} " +
            " </if> " +
            "<if test='comMngPopulationVO.ageStart != null'>" +
            "AND cmp.age <![CDATA[ >= ]]> #{comMngPopulationVO.ageStart} " +
            " </if> " +
            "<if test='comMngPopulationVO.ageEnd != null'>" +
            "AND cmp.age <![CDATA[ <= ]]> #{comMngPopulationVO.ageEnd} " +
            " </if> " +
            "<if test='comMngPopulationVO.nativePlace != null and comMngPopulationVO.nativePlace.trim() != &quot;&quot;'>" +
            "AND cmp.native_place LIKE concat(#{comMngPopulationVO.nativePlace},'%') " +
            " </if> " +
            "<if test='comMngPopulationVO.nation != null and comMngPopulationVO.nation.trim() != &quot;&quot;'>" +
            "AND cmp.nation = #{comMngPopulationVO.nation} " +
            " </if> " +
            "<if test='comMngPopulationVO.politicalOutlook != null and comMngPopulationVO.politicalOutlook.trim() != &quot;&quot;'>" +
            "AND cmp.political_outlook = #{comMngPopulationVO.politicalOutlook} " +
            " </if> " +
            "<if test='comMngPopulationVO.cardNo != null and comMngPopulationVO.cardNo.trim() != &quot;&quot;'>" +
            "AND cmp.card_no = #{comMngPopulationVO.cardNo} " +
            " </if> " +
            "<if test='comMngPopulationVO.remark != null and comMngPopulationVO.remark.trim() != &quot;&quot;'>" +
            "AND cmp.remark = #{comMngPopulationVO.remark} " +
            " </if> " +
            " </where>" +
            " order by cmp.create_at desc " +
            "</script>")
    List<ComMngPopulationVO> listPopulation(ComMngPopulationDTO populationVO);
 
 
    @Select("select id,user_id,relationship,`name`,id_card,phone,age,health,job,create_at,update_at,card_photo_front,card_photo_back,family_book from com_mng_family_info where user_id=#{userId} order by create_at desc ")
    List<ComMngFamilyInfoVO> listFamilyByUserId(Long userId);
 
    @Select("select cmphu.popul_id,cmp.name,cmp.relation,cmp.age,cmp.phone,cmp.healthy,cmp.card_no,cmp.work_company from com_mng_population_house_user cmphu " +
            " left join com_mng_population cmp on cmp.id = cmphu.popul_id " +
            " where cmphu.house_id = #{houseId} and cmphu.popul_id != #{populId}")
    List<ComHouseMemberVo> listHouseMermberByUserId(@Param("houseId") Long houseId, @Param("populId") Long populId);
 
    @Select("<script> " +
            "SELECT " +
            "cmp.`name`, " +
            "cmp.id, " +
            "cmp.street_id, " +
            "cmp.act_id, " +
            "cmp.village_id, " +
            "cmp.sex, " +
            "cmp.age, " +
            "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, " +
            "cmv.alley, " +
            "cmp.native_place, " +
            "cmp.nation,  " +
            "cmp.label,  " +
            "cmp.relation,  " +
            "cmp.marriage,  " +
            "cmp.culture_level,  " +
            "cmp.out_or_local,  " +
            "cmp.census_register,  " +
            "cmp.healthy,  " +
            "cmp.birthday,  " +
            "cmp.update_at,  " +
            "cmp.is_rent  " +
            "FROM  " +
            "com_mng_population AS cmp " +
            "LEFT JOIN com_mng_village AS cmv ON cmv.village_id = cmp.village_id " +
            "<where>" +
            "<if test='comMngPopulationVO.name != null and comMngPopulationVO.name != &quot;&quot;'>" +
            "AND cmp.`name` LIKE concat(#{comMngPopulationVO.name},'%') " +
            " </if> " +
            "<if test='comMngPopulationVO.actId != null'>" +
            " and cmp.act_id = #{comMngPopulationVO.actId} " +
            " </if> " +
            "<if test='comMngPopulationVO.outOrLocal != null'>" +
            " and cmp.out_or_local = #{comMngPopulationVO.outOrLocal} " +
            " </if> " +
            "<if test='comMngPopulationVO.villageId != null'>" +
            " 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.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.alley != null and comMngPopulationVO.alley != &quot;&quot;'>" +
            "AND cmv.alley LIKE concat(#{comMngPopulationVO.alley},'%') " +
            " </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 date_format(cmp.birthday,'%Y-%m-%d') <![CDATA[ <= ]]> #{comMngPopulationVO.ageStartTime} " +
            " </if> " +
            "<if test='comMngPopulationVO.ageEndTime != null and comMngPopulationVO.ageEndTime != &quot;&quot;'>" +
            "AND date_format(cmp.birthday,'%Y-%m-%d') <![CDATA[ >= ]]> #{comMngPopulationVO.ageEndTime} " +
            " </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> " +
            " </where>" +
            " order by cmp.create_at desc" +
            "</script>")
    IPage<ComMngPopulationVO> pagePopulation(Page page, @Param("comMngPopulationVO") ComMngPopulationDTO comMngPopulationVO);
 
    @Select("<script> " +
            "select cmp.id,cmv.`alley` as areaName,cmp.`name`,cmp.phone,cmp.label as tags,cmp.create_at from com_mng_population as cmp " +
            "left join com_mng_village as cmv on cmv.village_id = cmp.village_id where cmp.act_id = #{pageInputUserDTO.communityId} and cmp.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 cmp.label like concat('%',#{pageInputUserDTO.tags},'%') " +
            " </if> " +
            " order by cmp.create_at desc " +
            "</script>")
    IPage<InputUserInfoVO> specialInputUser(Page page, @Param("pageInputUserDTO") PageInputUserDTO pageInputUserDTO);
 
    @Select("select user_id,card_photo_front,card_photo_back,family_book from sys_user where id_card=#{idCard}")
    UserElectronicFileVO getSysUserElectronicFile(@Param("idCard") String idCard);
 
    @Select("select user_id,card_photo_front,card_photo_back,family_book from sys_user where user_id=#{userId}")
    UserElectronicFileVO getSysUserById(@Param("userId") Long userId);
 
    @Select("update sys_user set card_photo_front=#{vo.cardPhotoFront},card_photo_back=#{vo.cardPhotoBack},family_book=#{vo.familyBook} where user_id=#{vo.userId}")
    void updateSysUserElectronicFile(@Param("vo") UserElectronicFileVO vo);
 
    @Select("<script> " +
            "select (select province_name from com_mng_struct_area_province where province_adcode = #{provinceCode}) as province," +
            "(select city_name from com_mng_struct_area_city where city_adcode = #{cityCode}) as city," +
            "(select district_name from com_mng_struct_area_district where district_adcode = #{districtCode}) as district" +
            "</script>")
    AreaAddressVO getAreaAddress(@Param("provinceCode") String provinceCode,@Param("cityCode") String cityCode,@Param("districtCode") String districtCode);
 
    @Select("select count(id) as populationTotal " +
            ",(select count(id) from com_mng_population where act_id = #{communityId} and out_or_local = 1) as localTotal " +
            ",(select count(id) from com_mng_population where act_id = #{communityId} and out_or_local = 2) as outTotal " +
            ",(select count(id) from com_mng_population where act_id = #{communityId} and label is not null) as specialTotal " +
            " from com_mng_population as cmp where act_id = #{communityId}")
    ComMngPopulationTotalVO getPopulationTotalByAdmin(@Param("communityId") Long communityId);
 
    @Select("select count(id) as populationTotal," +
            "IFNULL((select count(id) from com_mng_population_house where community_id = cmp.act_id),0) as houseTotal, " +
            "IFNULL((select count(id) from com_mng_real_company where community_id = cmp.act_id),0) as companyTotal, " +
            "IFNULL((select count(village_id) from com_mng_village where community_id = cmp.act_id),0) as villageTotal " +
            " from com_mng_population as cmp " +
            " where act_id = #{communityId}")
    IndexBasicsStatisticsVO getScreenIndexByBasics(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " IFNULL( NULL, 1 ) AS type, " +
            " count( id ) AS sum  " +
            "FROM " +
            " com_mng_population  " +
            "WHERE " +
            " sex = 1  " +
            " AND act_id = #{communityId} UNION ALL " +
            "SELECT " +
            " IFNULL( NULL, 2 ) AS type, " +
            " count( id ) AS sum  " +
            "FROM " +
            " com_mng_population  " +
            "WHERE " +
            " sex = 2  " +
            " AND act_id = #{communityId}")
    List<IndexPopulationSexStatisticsVO> getScreenIndexByPopulationSex(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " e.happen_time as createAt, " +
            " e.event_des, " +
            " e.event_deal_status  " +
            "FROM " +
            " `event` AS e " +
            " LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id  " +
            "WHERE " +
            " egd.grid_community_id = #{communityId}  " +
            " AND e.event_deal_status IN ( 1, 4 )  " +
            "ORDER BY " +
            " e.happen_time DESC  " +
            " LIMIT 8")
    List<IndexEventListStatisticsVO> getScreenIndexByEventList(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " count( id ) AS microWishTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_act_easy_photo WHERE status = 4 AND community_id = camw.community_id ),0) AS easyPhotoTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_act_message WHERE STATUS = 2 AND community_id = camw.community_id ),0) AS replyTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_act_activity WHERE STATUS = 5 AND community_id = camw.community_id ),0) AS actTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_pb_activity WHERE STATUS = 5 AND community_id = camw.community_id ),0) AS pbTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_act_questnaire WHERE community_id = camw.community_id ),0) AS investigationTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_act_dyn WHERE community_id = camw.community_id AND STATUS = 1 ),0) AS propagandaTotal  " +
            "FROM " +
            " com_act_micro_wish AS camw  " +
            "WHERE " +
            " camw.STATUS = 6  " +
            " AND camw.community_id = #{communityId}")
    IndexDynamicStatisticsVO getScreenIndexByDynamic(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " count( e.id ) AS eventTFTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 1 AND event_status = 2  AND grid_id = egd.id ),0) AS eventZATotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 3 AND event_status = 2  AND grid_id = egd.id ),0) AS eventMDTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 6 AND event_status = 2  AND grid_id = egd.id ),0) AS eventTSTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 4 AND event_status = 2  AND grid_id = egd.id ),0) AS eventBWDTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 2 AND event_status = 2  AND grid_id = egd.id ),0) AS eventGGTotal  " +
            "FROM " +
            " `event` AS e " +
            " LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id  " +
            "WHERE " +
            " e.event_category = 1  " +
            " AND e.event_type = 5  " +
            " AND e.event_status = 2  " +
            " AND egd.grid_community_id = #{communityId}")
    IndexGridEventStatisticsVO getGridEventStatisticsList(@Param("communityId") Long communityId);
 
    @Select("select id,grid_name from event_grid_data where grid_community_id = #{communityId}")
    List<EventGridDataVO> getGridDataListByCommunityId(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " count( e.id ) AS eventTFTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 1 AND event_status = 2 AND grid_id = e.grid_id ),0) AS eventZATotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 3 AND event_status = 2 AND grid_id = e.grid_id) ,0) AS eventMDTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 6 AND event_status = 2 AND grid_id = e.grid_id ),0) AS eventTSTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 4 AND event_status = 2 AND grid_id = e.grid_id ),0) AS eventBWDTotal, " +
            " IFNULL(( SELECT count( id ) FROM `event` WHERE event_category = 1 AND event_type = 2 AND event_status = 2 AND grid_id = e.grid_id ),0) AS eventGGTotal  " +
            "FROM " +
            " `event` AS e " +
            "WHERE " +
            " e.event_category = 1  " +
            " AND e.event_type = 5  " +
            " AND e.event_status = 2  " +
            " AND e.grid_id = #{gridId}")
    IndexGridEventStatisticsVO getGridEventByGirdId(@Param("gridId") Long gridId);
 
    @Select("SELECT " +
            " tag_name, " +
            " sys_flag  " +
            "FROM " +
            " com_mng_user_tag  " +
            "WHERE " +
            " sys_flag = 1  " +
            " OR community_id = #{communityId}")
    List<ComMngUserTagVO> getUserTagListByCommunityId(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " count( id )  " +
            "FROM " +
            " com_mng_population  " +
            "WHERE " +
            " label like concat('%',#{label},'%')")
    Integer getSpecialStatisticsByLabel(@Param("label") String label);
 
    @Select("SELECT " +
            " count( egd.id ) AS gridTotal, " +
            " ( SELECT count( user_id ) FROM sys_user WHERE community_id = egd.grid_community_id AND type = 6 ) AS gridMemberTotal, " +
            " ( " +
            " SELECT " +
            "  count( e.id )  " +
            " FROM " +
            "  `event` AS e " +
            "  LEFT JOIN event_grid_data AS egd1 ON e.grid_id = egd1.id  " +
            " WHERE " +
            "  egd1.grid_community_id = egd.grid_community_id  " +
            "  AND event_status = 2  " +
            " ) AS eventTotal, " +
            " ( " +
            " SELECT " +
            "  count( e1.id )  " +
            " FROM " +
            "  `event` AS e1 " +
            "  LEFT JOIN event_grid_data AS egd2 ON e1.grid_id = egd2.id  " +
            " WHERE " +
            "  egd2.grid_community_id = egd.grid_community_id  " +
            "  AND event_status = 2  " +
            " AND event_deal_status IN ( 1, 2, 3 )) AS noSolveEventTotal, " +
            " ( " +
            " SELECT " +
            "  count( e1.id )  " +
            " FROM " +
            "  `event` AS e1 " +
            "  LEFT JOIN event_grid_data AS egd2 ON e1.grid_id = egd2.id  " +
            " WHERE " +
            "  egd2.grid_community_id = egd.grid_community_id  " +
            "  AND event_status = 2  " +
            "  AND event_deal_status = 4  " +
            " ) AS solveEventTotal  " +
            "FROM " +
            " event_grid_data AS egd  " +
            "WHERE " +
            " egd.grid_community_id = #{communityId}")
    EventLeftTopStatisticsVO getEventScreenLeftTop(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " DATE_FORMAT( e.create_at, '%m' ) months  " +
            "FROM " +
            " `event` AS e " +
            " LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id  " +
            "WHERE " +
            " e.create_at BETWEEN concat( YEAR ( now()), '-01-01 00:00:00' )  " +
            " AND concat( YEAR ( now()), '-12-31 23:59:59' )  " +
            " AND egd.grid_community_id = #{communityId}  " +
            "GROUP BY " +
            " months  " +
            "ORDER BY " +
            " count( e.id ) DESC  " +
            " LIMIT 3")
    List<Integer> getFrequentlyEventMonth(@Param("communityId") Long communityId);
 
    @Select("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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 1  " +
            "   AND event_deal_status = 4  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 5  " +
            "   AND event_status = 2  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 5  " +
            "   AND event_deal_status = 4  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 6  " +
            "   AND event_status = 2  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 6  " +
            "   AND event_deal_status = 4  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 3  " +
            "   AND event_status = 2  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 3  " +
            "   AND event_deal_status = 4  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 4  " +
            "   AND event_status = 2  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 4  " +
            "   AND event_deal_status = 4  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 2  " +
            "   AND event_status = 2  " +
            "   ), " +
            "  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 = #{communityId}  " +
            "   AND event_category = 1  " +
            "   AND event_type = 2  " +
            "   AND event_deal_status = 4  " +
            "   ), " +
            "  0  " +
            " ) AS yesEventGGTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_act_easy_photo WHERE del_tag = 0 AND handle_status IS NOT NULL AND community_id = #{communityId} ), 0 ) AS eventSSPTotal, " +
            " IFNULL(( SELECT count( id ) FROM com_act_easy_photo WHERE del_tag = 0 AND handle_status = 2 AND community_id = #{communityId} ), 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 = #{communityId}  " +
            " AND event_category = 1  " +
            " AND event_type = 1  " +
            " AND event_status = 2")
    EventLeftDownStatisticsVO getEventScreenLeftDown(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " su.nick_name AS userName, " +
            " su.image_url AS imageUrl, " +
            " e.happen_time as createAt, " +
            " e.event_des, " +
            " e.danger_level, " +
            " e.urgent, " +
            " e.major, " +
            " e.happen_address, " +
            " e.happent_lat_lng, " +
            " e.event_type, " +
            " e.id, " +
            " e.event_deal_status  " +
            "FROM " +
            " `event` AS e " +
            " LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id " +
            " LEFT JOIN sys_user AS su ON su.user_id = e.grid_member_id  " +
            "WHERE " +
            " egd.grid_community_id = #{communityId}  " +
            " AND e.event_status = 2  " +
            " AND e.event_deal_status = 1  " +
            " AND e.event_category = 1  " +
            "ORDER BY " +
            " e.happen_time DESC  " +
            " LIMIT 1")
    EventNewStatisticsVO getEventScreenRightTop(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " grid_name, " +
            " `data`, " +
            " line_color, " +
            " line_broadband, " +
            " id, " +
            " fill_color  " +
            "FROM " +
            " event_grid_data AS egd  " +
            "WHERE " +
            " egd.grid_community_id = #{communityId}")
    List<EventGridStatisticsVO> getEventScreenGridData(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " event_type AS type, " +
            " e.id AS eventId, " +
            " happent_lat_lng AS latLng  " +
            "FROM " +
            " `event` AS e " +
            " LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id  " +
            "WHERE " +
            " e.event_category = 1  " +
            " AND e.event_type IN ( 1, 2, 3, 4, 5, 6 )  " +
            " AND e.event_status = 2  " +
            " AND egd.grid_community_id = #{communityId}  " +
            " AND e.happen_time BETWEEN date_add( curdate(), INTERVAL - DAY ( curdate())+ 1 DAY )  " +
            " AND date_add( curdate()- DAY ( curdate())+ 1, INTERVAL 1 MONTH ) UNION ALL " +
            "SELECT " +
            " IFNULL( NULL, 7 ) AS type, " +
            " id AS eventId, " +
            " lng_lat AS latLng  " +
            "FROM " +
            " com_act_easy_photo  " +
            "WHERE " +
            " community_id = #{communityId}  " +
            " AND del_tag = 0  " +
            " AND lng_lat IS NOT NULL  " +
            " AND create_at BETWEEN date_add( curdate(), INTERVAL - DAY ( curdate())+ 1 DAY )  " +
            " AND date_add( curdate()- DAY ( curdate())+ 1, INTERVAL 1 MONTH )")
    List<EventGridIncidentStatisticsVO> getEventScreenEventList(@Param("communityId") Long communityId);
 
    @Select("SELECT " +
            " count( id ) AS specialTotal, " +
            " ( SELECT count( id ) FROM com_mng_population WHERE label IS NOT NULL AND act_id = #{communityId} AND create_at < #{lastMonth} ) AS toMonthSpecialTotal  " +
            "FROM " +
            " com_mng_population AS cmp  " +
            "WHERE " +
            " label IS NOT NULL  " +
            " AND act_id = #{communityId}")
    CivilPopulationStatisticsVO getCivilScreenPopulation(@Param("communityId") Long communityId,@Param("lastMonth") Date lastMonth);
 
    @Select("SELECT `NAME`, " +
            " user_sum, " +
            " lng, " +
            " lat, " +
            " village_images, " +
            " village_id  " +
            "FROM " +
            " com_mng_village AS cmv  " +
            "WHERE " +
            " community_id = #{communityId}")
    List<CivilVillageStatisticsVO> getCivilScreenVillageList(@Param("communityId") Long communityId);
 
 
    @Select("SELECT COUNT(id) AS man,(SELECT COUNT(id) FROM com_mng_population WHERE sex = 2 AND act_id = #{communityId}) AS woman FROM com_mng_population WHERE sex = 1 AND act_id = #{communityId}")
    Map<String, Long> countBySex(@Param("communityId") Long communityId);
 
    @Select(
            "SELECT " +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) as aa where aa.age<= 16) as age16," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 16 and aa.age<= 25) AS age25," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 25 and aa.age<= 35) AS age35," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 35 and aa.age<= 45) AS age45," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 45 and aa.age<= 55) AS age55," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 55) AS age55over")
    Map<String, Long> countByAge(@Param("communityId")Long communityId);
 
    @Select("SELECT COUNT(id)AS xx," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 2 AND act_id = #{communityId}) as cz," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 3 AND act_id = #{communityId}) as gz," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 4 AND act_id = #{communityId}) as zz," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 5 AND act_id = #{communityId}) as dz," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 6 AND act_id = #{communityId}) as bk," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 7 AND act_id = #{communityId}) as ss," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 8 AND act_id = #{communityId}) as bs," +
            "(SELECT COUNT(id) FROM com_mng_population WHERE culture_level = 9 AND act_id = #{communityId}) as qt" +
            " FROM com_mng_population WHERE culture_level = 1 AND act_id = #{communityId}")
    Map<String, Long> countByCulture(@Param("communityId")Long communityId);
 
    @Select("select count(user_id) from sys_user where community_id = #{communityId} and type = 1")
    Long countUsedCommunityPopulation(@Param("communityId")Long communityId);
 
    @Select(
            "SELECT " +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) as aa where aa.age<= 16) as age16," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 16 and aa.age<= 27) AS age27," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 27 and aa.age<= 35) AS age35," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 35 and aa.age<= 45) AS age45," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 45 and aa.age<= 55) AS age55," +
                    "(SELECT COUNT(aa.age) FROM " +
                    "(SELECT (SELECT  TIMESTAMPDIFF(YEAR, birthday, CURDATE()) ) AS age FROM com_mng_population WHERE act_id = #{communityId}) AS aa WHERE aa.age > 55) AS age55over")
    Map<String, Long> indexCountByAge(@Param("communityId")Long communityId);
 
 
    @Select("SELECT " +
            " id, " +
            " su.nick_name AS userName, " +
            " su.image_url, " +
            " caep.create_at, " +
            " caep.detail AS eventDes, " +
            " caep.happen_addr AS happenAddress, " +
            " caep.lng_lat AS happentLatLng, " +
            " caep.photo_path_list, " +
            " IFNULL( NULL, 7 ) AS eventType, " +
            " caep.handle_status AS eventDealStatus  " +
            "FROM " +
            " com_act_easy_photo AS caep " +
            " LEFT JOIN sys_user AS su ON su.user_id = caep.sponsor_id  " +
            "WHERE " +
            " id = #{eventId}")
    EventNewStatisticsVO getEventScreenSSPDateil(@Param("eventId")Long eventId);
 
    @Select("SELECT " +
            " su.nick_name AS userName, " +
            " su.image_url AS imageUrl, " +
            " e.happen_time as createAt, " +
            " e.event_des, " +
            " e.danger_level, " +
            " e.urgent, " +
            " e.major, " +
            " e.happen_address, " +
            " e.happent_lat_lng, " +
            " e.event_type, " +
            " e.id, " +
            " e.event_deal_status  " +
            "FROM " +
            " `event` AS e " +
            " LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id " +
            " LEFT JOIN sys_user AS su ON su.user_id = e.grid_member_id  " +
            "WHERE " +
            " e.id = #{eventId}")
    EventNewStatisticsVO getEventScreenEventDetail(@Param("eventId") Long eventId);
 
}