mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
<?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_dangjian.dao.ComPbMemberWestDAO">
 
    <resultMap type="com.panzhihua.service_dangjian.model.dos.ComPbMemberWestDO" id="ComPbMemberMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="orgId" column="org_id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="idCard" column="id_card" jdbcType="VARCHAR"/>
        <result property="photoPath" column="photo_path" jdbcType="VARCHAR"/>
        <result property="joinTime" column="join_time" jdbcType="TIMESTAMP"/>
        <result property="employmentTime" column="employment_time" jdbcType="TIMESTAMP"/>
        <result property="auditResult" column="audit_result" jdbcType="INTEGER"/>
        <result property="createAt" column="create_at" jdbcType="TIMESTAMP"/>
        <result property="updateAt" column="update_at" jdbcType="TIMESTAMP"/>
        <result property="communityId" column="community_id" jdbcType="INTEGER"/>
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
        <result property="refuseReason" column="refuse_reason" jdbcType="VARCHAR"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="position" column="position" jdbcType="VARCHAR"/>
        <result property="checkUnitId" column="check_unit_id" jdbcType="INTEGER"/>
        <result property="function" column="function" jdbcType="VARCHAR"/>
        <result property="specialtyCategory" column="specialty_category" jdbcType="INTEGER"/>
        <result property="specialtyName" column="specialty_name" jdbcType="VARCHAR"/>
        <result property="positionTwo" column="position_two" jdbcType="VARCHAR"/>
    </resultMap>
 
    <!--查询单个-->
    <select id="queryById" resultType="com.panzhihua.common.model.vos.partybuilding.west.PartyBuildingMemberVO">
        select
        m.id, m.org_id, m.name, m.id_card, m.photo_path, m.join_time, m.employment_time, m.audit_result, m.create_at, m.update_at,
        m.community_id, m.user_id, m.refuse_reason, m.phone, m.type, m.position, m.check_unit_id, m.function, m.specialty_category,
        m.specialty_name, m.position_two, o.`name` orgName,cpcu.name as checkUnitName,
        TIMESTAMPDIFF(
        YEAR,
        m.employment_time,
        DATE_FORMAT( NOW(), '%Y-%m-%d' )) as partyAge,
        CASE
 
        WHEN u.id_card IS NULL THEN
        '未注册' ELSE '已注册'
        END status
        from com_pb_member_west as m
        LEFT JOIN (
            SELECT su.* FROM sys_user su
            LEFT JOIN com_act act ON su.community_id = act.community_id
            WHERE act.area_code = #{areaCode}
        ) u ON m.id_card = u.id_card and u.`type` = 1
        LEFT JOIN com_pb_org o ON m.org_id = o.id
        LEFT JOIN com_pb_check_unit as cpcu ON m.check_unit_id = cpcu.id
        where m.id = #{id}
    </select>
 
    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultType="com.panzhihua.common.model.vos.partybuilding.west.PartyBuildingMemberVO">
        select
        m.id, m.org_id, m.name, m.id_card, m.photo_path, m.join_time, m.employment_time, m.audit_result, m.create_at, m.update_at,
        m.community_id, m.user_id, m.refuse_reason, m.phone, m.type, m.position, m.check_unit_id, m.function, m.specialty_category,
        m.specialty_name, m.position_two, o.`name` orgName,cpcu.name as checkUnitName,t2.partyTime,t2.partyInterval,
        TIMESTAMPDIFF(
        YEAR,
        m.employment_time,
        DATE_FORMAT( NOW(), '%Y-%m-%d' )) as partyAge,
        CASE     WHEN su.id_card IS NULL THEN
        '未注册' ELSE '已注册'
        END status
        from com_pb_member as m
        LEFT JOIN sys_user su on m.id_card = su.id_card     AND su.type = 1
        LEFT JOIN com_act act ON su.community_id = act.community_id
        LEFT JOIN com_pb_org o ON m.org_id = o.id
        LEFT JOIN com_pb_check_unit as cpcu ON m.check_unit_id = cpcu.id
        LEFT JOIN (select t1.user_id,sum(t.duration) as partyTime,sum(t1.award) as partyInterval  from com_act_activity t LEFT JOIN com_act_act_regist t1 on t.id = t1.activity_id where t1.sign_identity = 2
        <if test="dto.startTime !=null">
            and t.begin_at between #{dto.startTime} and #{dto.endTime}
        </if>
        GROUP BY t1.user_id ) t2 on su.user_id = t2.user_id
        <where>
            and m.audit_result = 1
            <if test='dto.orgName != null and dto.orgName != &quot;&quot;'>
                and o.name like concat(#{dto.orgName},'%')
            </if>
            <if test='dto.orgId != null'>
               and o.id = #{dto.orgId}
            </if>
            <if test='dto.account != null and dto.account != &quot;&quot;'>
                and su.account like concat (#{dto.account},'%')
            </if>
            <if test='dto.name != null and dto.name != &quot;&quot;'>
                and m.name like concat (#{dto.name},'%')
            </if>
            <if test="dto.orgId != null">
                and m.org_id = #{dto.orgId}
            </if>
            <if test="dto.communityIds != null and dto.communityIds.size() >0">
                and m.community_id IN
                <foreach collection="dto.communityIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="dto.keyWord != null and dto.keyWord != ''">
                and (m.name like concat (#{dto.keyWord},'%') or
                su.phone like concat (#{dto.keyWord},'%') or
                cpcu.name like concat (#{dto.keyWord},'%')
                )
            </if>
            <if test="dto.type != null">
                and m.type = #{dto.type}
            </if>
            <if test="dto.checkUnitId != null">
                and m.check_unit_id = #{dto.checkUnitId}
            </if>
            <if test="dto.specialtyCategory != null">
                and m.specialty_category = #{dto.specialtyCategory}
            </if>
        </where>
        order by m.create_at desc
    </select>
 
    <select id="exportPartyMemberList" resultType="com.panzhihua.common.model.vos.PartyMemberListExcelVO">
        select
        m.id, m.org_id, m.name, m.id_card, m.photo_path, m.join_time, m.employment_time, m.audit_result, m.create_at, m.update_at,
        m.community_id, m.user_id, m.refuse_reason, m.phone, m.type, m.position, m.check_unit_id, m.function, m.specialty_category,
        m.specialty_name, m.position_two, o.`name` orgName,cpcu.name as checkUnitName,t2.partyTime,t2.partyInterval,
        TIMESTAMPDIFF(
        YEAR,
        m.employment_time,
        DATE_FORMAT( NOW(), '%Y-%m-%d' )) as partyAge,
        CASE
 
        WHEN u.id_card IS NULL THEN
        '未注册' ELSE '已注册'
        END status
        from com_pb_member_west as m
        LEFT JOIN (
            SELECT su.* FROM sys_user su
            LEFT JOIN com_act act ON su.community_id = act.community_id
        ) u ON m.id_card = u.id_card and u.type = 1
        LEFT JOIN com_act act ON u.community_id = act.community_id
        LEFT JOIN com_pb_org o ON m.org_id = o.id
        LEFT JOIN com_pb_check_unit as cpcu ON m.check_unit_id = cpcu.id
        LEFT JOIN (select t1.user_id,sum(t.duration) as partyTime,sum(t1.award) as partyInterval  from com_act_activity t LEFT JOIN com_act_act_regist t1 on t.id = t1.activity_id where t1.sign_identity = 2
        <if test="dto.startTime !=null">
            and t.begin_at between #{dto.startTime} and #{dto.endTime}
        </if>
        GROUP BY t1.user_id ) t2 on u.user_id = t2.user_id
        <where>
            and m.audit_result = 1
            <if test='dto.orgName != null and dto.orgName != &quot;&quot;'>
                and o.name like concat(#{dto.orgName},'%')
            </if>
            <if test='dto.orgId != null'>
                and o.id = #{dto.orgId}
            </if>
            <if test='dto.account != null and dto.account != &quot;&quot;'>
                and u.phone like concat (#{dto.account},'%')
            </if>
            <if test='dto.name != null and dto.name != &quot;&quot;'>
                and m.name like concat (#{dto.name},'%')
            </if>
            <if test="dto.orgId != null">
                and m.org_id = #{dto.orgId}
            </if>
            <if test="dto.communityId != null">
                and m.community_id = ${dto.communityId}
            </if>
            <if test="dto.keyWord != null and dto.keyWord != ''">
                and (m.name like concat (#{dto.keyWord},'%') or
                u.phone like concat (#{dto.keyWord},'%') or
                cpcu.name like concat (#{dto.keyWord},'%')
                )
            </if>
            <if test="dto.type != null">
                and m.type = #{dto.type}
            </if>
            <if test="dto.checkUnitId != null">
                and m.check_unit_id = #{dto.checkUnitId}
            </if>
            <if test="dto.specialtyCategory != null">
                and m.specialty_category = #{dto.specialtyCategory}
            </if>
        </where>
        order by m.create_at desc
    </select>
 
    <select id="pagePartyBuildingMembersVO" resultType="com.panzhihua.common.model.vos.partybuilding.west.PartyBuildingMemberVO">
        select
        m.id, m.org_id, m.name, m.id_card, m.photo_path, m.join_time, m.employment_time, m.audit_result, m.create_at, m.update_at,
        m.community_id, m.user_id, m.refuse_reason, m.phone, m.type, m.position, m.check_unit_id, m.function, m.specialty_category,
        m.specialty_name, m.position_two, o.`name` orgName,cpcu.name as checkUnitName,
        TIMESTAMPDIFF(
        YEAR,
        m.employment_time,
        DATE_FORMAT( NOW(), '%Y-%m-%d' )) as partyAge,
        CASE
 
        WHEN u.id_card IS NULL THEN
        '未注册' ELSE '已注册'
        END status
        from com_pb_member_west as m
        LEFT JOIN (
            SELECT su.* FROM sys_user su
            LEFT JOIN com_act act ON su.community_id = act.community_id
        ) u ON m.id_card = u.id_card AND u.`type` = 1
        LEFT JOIN com_act act ON u.community_id = act.community_id
        LEFT JOIN com_pb_org o ON m.org_id = o.id
        LEFT JOIN com_pb_check_unit as cpcu on cpcu.id = m.check_unit_id
        WHERE
            m.audit_result IN ( 0, 3 )
        <if test='pagePartyBuildingMemberVO.phone != null and pagePartyBuildingMemberVO.phone != &quot;&quot;'>
            and u.phone LIKE CONCAT('%',#{pagePartyBuildingMemberVO.phone},'%')
        </if>
        <if test='pagePartyBuildingMemberVO.name != null and pagePartyBuildingMemberVO.name != &quot;&quot;'>
            and u.name like concat ('%',#{pagePartyBuildingMemberVO.name},'%')
        </if>
        <if test='pagePartyBuildingMemberVO.auditStatus != null'>
            and m.audit_result = #{pagePartyBuildingMemberVO.auditStatus}
        </if>
        <if test='pagePartyBuildingMemberVO.communityId != null'>
            and m.community_id = ${pagePartyBuildingMemberVO.communityId}
        </if>
    </select>
 
    <select id="pageDataStatisticsMember" resultType="com.panzhihua.common.model.vos.partybuilding.west.ComDataStatisticsMemberVo">
        SELECT
            cpm.id,
            cpm.`name`,
            cpm.photo_path,
            cpm.type,
            cpm.`function`,
            cpm.specialty_category,
            cpm.specialty_name,
            cpm.position,
            cpm.position_two,
            cpm.id_card,
            cpm.phone,
            cpm.check_unit_id,
            cpm.user_id,
            cpcu.`name` AS checkUnitName,
            cpm.org_id,
            cpm.community_id,
            cpo.`name` AS orgName,
            YEAR (
                from_days(
                datediff( now( ), cpm.join_time ))) AS partyAge,
            (select count(id) from com_pb_member_role where id_card = cpm.id_card) as isRole
        FROM
            com_pb_member_west AS cpm
            LEFT JOIN com_pb_check_unit AS cpcu ON cpcu.id = cpm.check_unit_id
            LEFT JOIN com_pb_org AS cpo ON cpo.id = cpm.org_id
            LEFT JOIN (
                SELECT su.* FROM sys_user su
                LEFT JOIN com_act act ON su.community_id = act.community_id
            ) t1 on cpm.id_card = t1.id_card and t1.type=1
            <where>
                and cpm.audit_result = 1
                <if test="dto.communityId != null">
                    and cpm.community_id = #{dto.communityId}
                </if>
 
                <if test="dto.keyWord != null and dto.keyWord !=''">
                    and (
                    cpm.`name` like concat (#{dto.keyWord},'%') or
                    cpm.`id_card` = #{dto.keyWord} or
                    cpm.`phone` like concat (#{dto.keyWord},'%') or
                    cpcu.`name` like concat (#{dto.keyWord},'%') or
                    cpo.`name` like concat (#{dto.keyWord},'%')
                    )
                </if>
                <if test="dto.month !=null and dto.month !=''">
                    and (cpm.create_at >= DATE_FORMAT(  CONCAT(#{dto.month},'-00-00'), '%Y-00-00 00:00:00') and DATE_FORMAT(  CONCAT(#{dto.month},'-12-31'), '%Y-12-31 23:59:59') >= cpm.create_at)
                </if>
            </where>
            order by cpm.create_at desc
    </select>
 
    <select id="getMemberStatistics" resultType="com.panzhihua.common.model.vos.partybuilding.west.ComDataStatisticsMemberVo">
        SELECT
            count( cpam.id ) AS partyActivityCount,
            IFNULL(( SELECT integral_available_party FROM com_act_integral_user WHERE user_id = #{userId} AND community_id = #{communityId} ), 0 ) AS partyActivityIntegral,
            IFNULL(( SELECT integral_available_volunteer FROM com_act_integral_user WHERE user_id = #{userId} AND community_id = #{communityId} ), 0 ) AS volunteerActivityIntegral,
            ( SELECT count( caas.id ) FROM com_act_act_sign AS caas
            LEFT JOIN com_act_activity AS caa ON caa.id = caas.activity_id
            WHERE caas.user_id = #{userId} and caas.status = 1 and caa.type = 1 and caa.community_id = #{communityId}
            ) AS volunteerActivityCount,
            IFNULL((
                SELECT
                    sum( caa.duration )
                FROM
                    com_act_act_sign AS caas
                    LEFT JOIN com_act_activity AS caa ON caa.id = caas.activity_id
                WHERE
                    caas.user_id = #{userId} and caas.status = 1 and caa.type = 1 and caa.community_id = #{communityId}
                    ),
                0
            ) AS volunteerActivityDuration,
            ( SELECT count( id ) FROM com_act_micro_wish WHERE sponsor_id = #{userId} AND `status` = 6 AND community_id = #{communityId} ) AS wishCount,
            ( SELECT count( id ) FROM com_act_easy_photo WHERE sponsor_id = #{userId} AND `status` = 4 AND community_id = #{communityId} ) AS easyCount
        FROM
            com_pb_activity_member AS cpam
            LEFT JOIN com_pb_member_west AS cpm ON cpm.id = cpam.member_id
        WHERE
            cpm.user_id = #{userId}
    </select>
 
    <select id="getOrgDataStatistics" resultType="com.panzhihua.common.model.vos.partybuilding.west.ComDataStatisticsOrgVo">
        SELECT
            count( id ) AS tyNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId} AND specialty_category = 2
                <if test="orgIds != null and orgIds.size > 0">
                    AND org_id in
                    <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            ) AS wdNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId} AND specialty_category = 3
                <if test="orgIds != null and orgIds.size > 0">
                    AND org_id in
                    <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            ) AS yyNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId} AND specialty_category = 4
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            ) AS msNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId} AND specialty_category = 5
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            ) AS qtNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId} AND specialty_category IS NULL
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            ) AS wuNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId} AND type = 1
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            ) AS preparePartyMemberNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId} AND type = 2
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            ) AS formalPartyMemberNum,
            ( SELECT count( id ) FROM com_pb_member_west WHERE audit_result = 1 AND community_id = #{communityId}
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            ) AS partyMemberNum
        FROM
            com_pb_member_west
        WHERE
            audit_result = 1
            AND community_id = #{communityId}
            AND specialty_category = 1
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>
 
    <select id="getOrgDataStatisticsLeftDown" resultType="com.panzhihua.common.model.vos.partybuilding.west.ComDataStatisticsOrgVo">
        SELECT
            count( caas1.id ) AS participateVolunteerActivityNum,
            (
            SELECT
                IFNULL( sum( caa.duration ), 0 )
            FROM
                com_act_act_sign AS caas
                LEFT JOIN com_act_activity AS caa ON caa.id = caas.activity_id
            WHERE
                caas.`status` = 1
                AND caa.type = 1
                AND caas.user_id IN ( SELECT t1.user_id FROM com_pb_member_west t LEFT JOIN (
                    SELECT su.* FROM sys_user su
                    LEFT JOIN com_act act ON su.community_id = act.community_id
                    ) t1 on t.id_card=t1.id_card WHERE audit_result = 1
                AND t.community_id = #{communityId} AND t1.type=1
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
                )
                AND caas.create_at BETWEEN #{startTime}
                AND #{endTime}
            ) AS participateVolunteerActivityDuration,
            (
            SELECT
                count( cpam.id )
            FROM
                com_pb_activity_member AS cpam
                LEFT JOIN com_pb_member_west AS cpm ON cpm.id = cpam.member_id
            WHERE
                cpm.audit_result = 1
                AND cpm.community_id = #{communityId}
                AND cpam.create_at BETWEEN #{startTime}
                AND #{endTime}
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            ) AS participatePartyActivityNum
        FROM
            com_act_act_sign as caas1
            left join com_act_activity as caa1 on caa1.id = caas1.activity_id
        WHERE
        caas1.`status` = 1 and caa1.type = 1
            AND caas1.user_id IN ( SELECT t1.user_id FROM com_pb_member_west t LEFT JOIN (
            SELECT su.* FROM sys_user su
            LEFT JOIN com_act act ON su.community_id = act.community_id
            WHERE act.area_code = #{areaCode}
            ) t1 on t.id_card=t1.id_card WHERE audit_result = 1
            AND t.community_id = #{communityId} AND t1.type=1
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            )
            AND caas1.create_at BETWEEN #{startTime}
            AND #{endTime}
    </select>
 
    <select id="getOrgDataStatisticsMember" resultType="com.panzhihua.common.model.vos.partybuilding.west.PartyBuildingMemberVO">
        select
        m.id, m.org_id, m.name, m.id_card, m.photo_path, m.join_time, m.employment_time, m.audit_result, m.create_at, m.update_at,
        m.community_id, m.user_id, m.refuse_reason, m.phone, m.type, m.position, m.check_unit_id, m.function, m.specialty_category,
        m.specialty_name, m.position_two, o.`name` orgName,cpcu.name as checkUnitName,
        TIMESTAMPDIFF(
        YEAR,
        m.employment_time,
        DATE_FORMAT( NOW(), '%Y-%m-%d' )) as partyAge,
        CASE
 
        WHEN u.id_card IS NULL THEN
        '未注册' ELSE '已注册'
        END status
        from com_pb_member_west as m
        LEFT JOIN (
        SELECT su.* FROM sys_user su
        LEFT JOIN com_act act ON su.community_id = act.community_id
        ) u ON m.id_card = u.id_card AND u.`type` = 1
        LEFT JOIN com_pb_org o ON m.org_id = o.id
        LEFT JOIN com_pb_check_unit as cpcu ON m.check_unit_id = cpcu.id
        <where>
            and m.audit_result = 1
            and m.community_id = #{communityId}
            <if test="orgIds != null and orgIds.size > 0">
                AND m.org_id in
                <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
 
    <select id="getOrgDataStatisticsRightDown" resultType="map">
        SELECT
            count( camw.id ) AS completeWishNum,(
            SELECT
                count( camw.id )
            FROM
                com_act_micro_wish AS camw
            WHERE
                camw.community_id = #{communityId}
                AND camw.`status` = 6
                AND camw.evaluate_at <![CDATA[ <= ]]> #{endDate}
                AND sponsor_id IN (
                SELECT
                    user_id
                FROM
                    com_pb_member_west
                WHERE
                    community_id = #{communityId}
                    AND audit_result = 1
                    AND user_id IS NOT NULL
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
                )) AS cumulativeWishNum,
            (SELECT
                count( caep.id )
            FROM
                com_act_easy_photo AS caep
            WHERE
                caep.community_id = #{communityId}
                AND caep.`status` >= 4
                AND caep.feedback_at <![CDATA[ <= ]]> #{endDate}
                AND caep.feedback_at <![CDATA[ >= ]]> #{startDate}
                AND caep.sponsor_id IN (
                SELECT
                    user_id
                FROM
                    com_pb_member_west
                WHERE
                    community_id = #{communityId}
                    AND audit_result = 1
                    AND user_id IS NOT NULL
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
                ) )    as completeEasyNum,
                (SELECT
                count( caep.id )
            FROM
                com_act_easy_photo AS caep
            WHERE
                caep.community_id = #{communityId}
                AND caep.`status` >= 4
                AND caep.feedback_at <![CDATA[ <= ]]> #{endDate}
                AND caep.sponsor_id IN (
                SELECT
                    user_id
                FROM
                    com_pb_member_west
                WHERE
                    community_id = #{communityId}
                    AND audit_result = 1
                    AND user_id IS NOT NULL
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
                ) ) as cumulativeEasyNum
        FROM
            com_act_micro_wish AS camw
        WHERE
            camw.community_id = #{communityId}
            AND camw.`status` = 6
            AND camw.evaluate_at <![CDATA[ <= ]]> #{endDate}
            AND camw.evaluate_at <![CDATA[ >= ]]> #{startDate}
            AND sponsor_id IN (
            SELECT
                user_id
            FROM
                com_pb_member_west
            WHERE
                community_id = #{communityId}
                AND audit_result = 1
            AND user_id IS NOT NULL
        <if test="orgIds != null and orgIds.size > 0">
            AND org_id in
            <foreach collection="orgIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
            )
    </select>
 
    <select id="getHeaderOrgDataStatistics" resultType="com.panzhihua.common.model.vos.partybuilding.west.ComDataStatisticsHeaderOrgVo">
        SELECT
            count( id ) AS orgNum,
            ( SELECT count(  distinct area_id ) FROM com_pb_org WHERE community_id = #{communityId} AND area_id IS NOT NULL ) AS areaNum,
            (select count(village_id) from com_mng_village where community_id = #{communityId}) as villageNum
        FROM
            com_pb_org
        WHERE
            community_id = #{communityId}
    </select>
 
    <select id="exportDataStatisticsMember" resultType="com.panzhihua.common.model.vos.partybuilding.excel.ComDataStatisticsMemberExcelVo">
        SELECT
        cpm.id,
        cpm.`name`,
        cpm.photo_path,
        cpm.type,
        cpm.`function`,
        cpm.specialty_category,
        cpm.specialty_name,
        cpm.position,
        cpm.position_two,
        cpm.id_card,
        cpm.phone,
        cpm.check_unit_id,
        cpm.user_id,
        cpcu.`name` AS checkUnitName,
        cpm.org_id,
        cpm.community_id,
        cpo.`name` AS orgName,
        YEAR (
        from_days(
        datediff( now( ), cpm.join_time ))) AS partyAge,
        (select count(id) from com_pb_member_role where id_card = cpm.id_card) as isRole
        FROM
        com_pb_member_west AS cpm
        LEFT JOIN com_pb_check_unit AS cpcu ON cpcu.id = cpm.check_unit_id
        LEFT JOIN com_pb_org AS cpo ON cpo.id = cpm.org_id
        <where>
            and cpm.audit_result = 1
            <if test="dto.communityId != null">
                and cpm.community_id = #{dto.communityId}
            </if>
 
            <if test="dto.keyWord != null and dto.keyWord !=''">
                and (
                cpm.`name` like concat (#{dto.keyWord},'%') or
                cpm.`id_card` = #{dto.keyWord} or
                cpm.`phone` like concat (#{dto.keyWord},'%') or
                cpcu.`name` like concat (#{dto.keyWord},'%') or
                cpo.`name` like concat (#{dto.keyWord},'%')
                )
            </if>
        </where>
        order by cpm.create_at desc
    </select>
</mapper>