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
<?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.ComFmsTeamMemberDAO">
 
    <resultMap type="com.panzhihua.service_community.entity.ComFmsTeamMember" id="ComFmsTeamMemberMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="idCard" column="id_card" jdbcType="VARCHAR"/>
        <result property="communityId" column="community_id" jdbcType="INTEGER"/>
        <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
        <result property="createdBy" column="created_by" jdbcType="INTEGER"/>
        <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
        <result property="updatedBy" column="updated_by" jdbcType="INTEGER"/>
        <result property="cascadeIds" column="cascade_ids" jdbcType="VARCHAR"/>
        <result property="gender" column="gender" jdbcType="INTEGER"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_fms_team_member(name, phone, id_card, community_id, created_at, created_by, updated_at, updated_by, cascade_ids, gender)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.name}, #{entity.phone}, #{entity.idCard}, #{entity.communityId}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt}, #{entity.updatedBy}, #{entity.cascadeIds}, #{entity.gender})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_fms_team_member(name, phone, id_card, community_id, created_at, created_by, updated_at, updated_by, cascade_ids, gender)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.phone}, #{entity.idCard}, #{entity.communityId}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt}, #{entity.updatedBy}, #{entity.cascadeIds}, #{entity.gender})
        </foreach>
        on duplicate key update
         name = values(name) , phone = values(phone) , id_card = values(id_card) , community_id = values(community_id) , created_at = values(created_at) , created_by = values(created_by) , updated_at = values(updated_at) , updated_by = values(updated_by) , cascade_ids = values(cascade_ids) , gender = values(gender)     </insert>
 
    <select id="pageFmsTeamMember"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsTeamMemberVO">
        SELECT t2.id, t2.`name`, t2.phone, t2.id_card, t2.gender, t2.cascade_ids, t3.team_type, t4.`name` AS teamTypeName, t3.`name` AS teamName
        FROM com_fms_team_member_relation t1
        INNER JOIN com_fms_team_member t2 ON t1.member_id = t2.id
        LEFT JOIN com_fms_team t3 ON t1.team_id = t3.id
        LEFT JOIN com_fms_team_type t4 ON t3.team_type = t4.id
        WHERE t2.community_id = #{pageTeamMemberDTO.communityId}
        <if test="pageTeamMemberDTO.teamType != null">
            AND t3.team_type = #{pageTeamMemberDTO.teamType}
        </if>
        <if test="pageTeamMemberDTO.teamId != null">
            AND t1.team_id = #{pageTeamMemberDTO.teamId}
        </if>
        <if test="pageTeamMemberDTO.gender != null">
            AND t2.gender = #{pageTeamMemberDTO.gender}
        </if>
        <if test="pageTeamMemberDTO.keyword != null and pageTeamMemberDTO.keyword != &quot;&quot;">
            AND (t3.`name` LIKE CONCAT('%',#{pageTeamMemberDTO.keyword},'%')
            OR t2.`name` LIKE CONCAT('%',#{pageTeamMemberDTO.keyword},'%')
            OR t2.phone LIKE CONCAT('%',#{pageTeamMemberDTO.keyword},'%'))
        </if>
        ORDER BY t2.created_at DESC
    </select>
    <select id="countMember" resultType="java.lang.Integer">
        SELECT COUNT(id) FROM com_fms_team_member
        WHERE community_id = #{communityId} AND (phone = #{phone}
        <if test="idCard != null and idCard != &quot;&quot;">
            OR id_card = #{idCard}
        </if>
        )
    </select>
    <select id="statisticsFmsTeamMember"
            resultType="com.panzhihua.common.model.vos.community.fms.TeamMemberTopStatisticsVO">
        SELECT
        (SELECT COUNT(id) FROM com_fms_team where community_id = #{communityId}) AS teamCount,
        (SELECT COUNT(id) FROM com_fms_team_member where community_id = #{communityId}) AS memberCount
    </select>
    <select id="exportTeamMember"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsTeamMemberExportExcelVO">
        SELECT t4.`name` AS teamType, t3.`name` AS teamName, t2.`name` AS teamMember, t2.id_card, t2.phone,
        CASE
        WHEN t2.gender = 1 THEN
        '男'
        WHEN t2.gender = 2 THEN
        '女'
        ELSE '未知'
        END gender
        FROM com_fms_team_member_relation t1
        INNER JOIN com_fms_team_member t2 ON t1.member_id = t2.id
        LEFT JOIN com_fms_team t3 ON t1.team_id = t3.id
        LEFT JOIN com_fms_team_type t4 ON t3.team_type = t4.id
        WHERE t2.community_id = #{pageTeamMemberDTO.communityId}
        <if test="pageTeamMemberDTO.teamType != null">
            AND t3.team_type = #{pageTeamMemberDTO.teamType}
        </if>
        <if test="pageTeamMemberDTO.teamId != null">
            AND t1.team_id = #{pageTeamMemberDTO.teamId}
        </if>
        <if test="pageTeamMemberDTO.gender != null">
            AND t2.gender = #{pageTeamMemberDTO.gender}
        </if>
        <if test="pageTeamMemberDTO.keyword != null and pageTeamMemberDTO.keyword != &quot;&quot;">
            AND (t3.`name` LIKE CONCAT('%',#{pageTeamMemberDTO.keyword},'%')
            OR t2.`name` LIKE CONCAT('%',#{pageTeamMemberDTO.keyword},'%')
            OR t2.phone LIKE CONCAT('%',#{pageTeamMemberDTO.keyword},'%'))
        </if>
        ORDER BY t2.created_at DESC
    </select>
    <select id="selectListByCommunityId"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsTeamMemberVO">
        SELECT t2.id, t1.team_id, t2.`name`
        FROM com_fms_team_member_relation t1
        INNER JOIN com_fms_team_member t2 ON t1.member_id = t2.id
        WHERE t2.community_id = #{communityId}
    </select>
    <select id="selectVOListByTeamId"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsTeamMemberVO">
        SELECT id, t2.`name`, t2.gender
        FROM com_fms_team_member_relation t1
        INNER JOIN com_fms_team_member t2 ON t1.member_id = t2.id
        WHERE t1.team_id = #{teamId}
    </select>
 
</mapper>