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
<?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.EldersAuthDAO">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.EldersAuthDO">
        <id column="id" property="id"/>
        <result column="create_by" property="createBy"/>
        <result column="create_at" property="createAt"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_at" property="updateAt"/>
        <result column="id_card" property="idCard"/>
        <result column="auth_user_name" property="authUserName"/>
        <result column="video_url" property="videoUrl"/>
        <result column="submit_user_id" property="sumitUserId"/>
        <result column="domicile" property="domicile"/>
        <result column="status" property="status"/>
        <result column="birth_day" property="birthDay"/>
        <result column="family_user_id" property="familyUserId"/>
        <result column="type" property="type" />
        <result column="verification_result" property="verificationResult" />
        <result column="age" property="age" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, create_by, create_at, update_by, update_at, id_card, auth_user_name, video_url, sumit_user_id, domicile, status, birth_day, family_user_id, type, verification_result, age
    </sql>
 
    <select id="getEldersAuthStatistics" resultType="Map">
        SELECT
            community_id,
            ( SELECT count( id ) FROM com_elders_auth_elderly WHERE community_id = ca.community_id AND is_exist = 1 AND is_big_age = 1 ) AS oldCount,
            (
            SELECT
                count( id )
            FROM
                com_elders_auth_history_record
            WHERE
                community_id = ca.community_id
                AND is_auth = 1
                AND create_at BETWEEN DATE_FORMAT( date_sub( date_format( now(), '%y-%m-%d 00:00:00' ), INTERVAL extract( DAY FROM now())- 1 DAY ), '%Y-%m-%d %H:%i:%s' )
                AND DATE_FORMAT( date_sub( date_format( now(), '%y-%m-%d 23:59:59' ), INTERVAL extract( DAY FROM now()) DAY ), '%Y-%m-%d %H:%i:%s' )
            ) AS yesCount,
            (
            SELECT
                count( id )
            FROM
                com_elders_auth_history_record
            WHERE
                community_id = ca.community_id
                AND is_auth = 2
                AND create_at BETWEEN DATE_FORMAT( date_sub( date_format( now(), '%y-%m-%d 00:00:00' ), INTERVAL extract( DAY FROM now())- 1 DAY ), '%Y-%m-%d %H:%i:%s' )
                AND DATE_FORMAT( date_sub( date_format( now(), '%y-%m-%d 23:59:59' ), INTERVAL extract( DAY FROM now()) DAY ), '%Y-%m-%d %H:%i:%s' )
            ) AS noCount
        FROM
            com_act AS ca
        WHERE
            community_id = ${communityId}
    </select>
 
    <select id="getEldersAuthRecords" resultType="com.panzhihua.common.model.vos.elders.ComEldersAuthHistoryVO">
        SELECT
            distinct
            cea.id,
            ceau.id as userId,
            ceau.`name`,
            ceae.id_card,
            ceae.birthday,
            ceae.domicile,
            cea.create_at
        FROM
            com_elders_auth AS cea
            LEFT JOIN com_elders_auth_user AS ceau ON ceau.id = cea.family_user_id
            LEFT JOIN com_elders_auth_elderly AS ceae ON ceae.id = ceau.big_age_id
        WHERE
            type = 1 and ceau.community_id = ${communityId}
            AND cea.create_at BETWEEN DATE_FORMAT( date_sub( date_format( now(), '%y-%m-%d 00:00:00' ), INTERVAL extract( DAY FROM now())- 1 DAY ), '%Y-%m-%d %H:%i:%s' )
                AND DATE_FORMAT( date_sub( date_format( now(), '%y-%m-%d 23:59:59' ), INTERVAL extract( DAY FROM now()) DAY ), '%Y-%m-%d %H:%i:%s' )
        order by cea.create_at desc
    </select>
 
    <select id="selectCommunityEldersRecordByPage" parameterType="com.panzhihua.common.model.dtos.community.PageEldersAuthRecordDTO"
            resultType="com.panzhihua.common.model.vos.community.ComEldersAuthRecordForCommunityVO">
        SELECT e.id,e.create_by,e.create_at, e.update_by, e.update_at, e.id_card, e.auth_user_name, e.video_url,
        e.sumit_user_id, e.domicile, e.status, e.birth_day, e.type, e.age, e.verification_result, u.name as
        sumitUserName, u.phone as sumitUserAccount
        FROM (          SELECT MAX(id) AS id , DATE_FORMAT(create_at, '%Y-%m') AS yearMonth
        FROM com_elders_auth           GROUP BY id_card, yearMonth          ) t
        left join com_elders_auth e on t.id = e.id LEFT JOIN sys_user u ON e.sumit_user_id = u.user_id
        <where>
           <if test='pageEldersAuthRecordDTO.name!=null'>
               AND e.auth_user_name like concat('%', #{pageEldersAuthRecordDTO.name}, '%')
           </if>
            <if test='pageEldersAuthRecordDTO.idCard!=null and pageEldersAuthRecordDTO.idCard!=&quot;&quot;'>
                AND e.id_card = #{pageEldersAuthRecordDTO.idCard}
            </if>
            <if test='pageEldersAuthRecordDTO.type!=null'>
               AND e.type = #{pageEldersAuthRecordDTO.type}
            </if>
            <if test='pageEldersAuthRecordDTO.month!=null'>
                AND month(e.create_at) = #{pageEldersAuthRecordDTO.month}
            </if>
            <if test='pageEldersAuthRecordDTO.year!=null'>
                AND year(e.create_at) = #{pageEldersAuthRecordDTO.year}
            </if>
        </where>
        <if test='pageEldersAuthRecordDTO.sortColumns!=null'>
            ORDER BY e.${pageEldersAuthRecordDTO.sortColumns} ${pageEldersAuthRecordDTO.sortType}
        </if>
    </select>
 
</mapper>