Blame view

TeamDictMapper.xml 6.39 KB
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
<?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.laowu.mapper.TeamDictMapper">
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, station_id, team_name, comment, administer_id
    </sql>

    <select id="teams" resultType="com.laowu.vo.team.TeamsVO">
        SELECT
        t3.id,
        t3.team_name,
        t3.ct,
        t4.user_name,
        t3.`comment`
        FROM
        (
        SELECT
        t1.id,
        t1.team_name,
        IF
        (
        t2.id IS NULL,
        0,
        count(*)) AS ct,
        t1.member_id,
        t1.`comment`
        FROM
        team_dict t1
        LEFT JOIN member_team_mapping t5 ON t1.id = t5.team_id and t5.delete_date is null
        LEFT JOIN member_dict t2 ON t2.id = t5.member_id
        WHERE
        t1.delete_date IS NULL
        and t1.station_id = #{stationId}
        <if test="teamName != null and teamName != ''">
            and t1.team_name like concat('%', #{teamName}, '%')
        </if>
        GROUP BY
        t1.id
        ) t3
        LEFT JOIN member_dict t4 ON t3.member_id = t4.id and t4.delete_date IS NULL
    </select>

    <select id="leaderMemberCounts" parameterType="long" resultType="integer">
        SELECT
            count(
            DISTINCT ( t.member_id ))
        FROM
            team_dict t
        WHERE
            t.delete_date IS NULL
            AND t.station_id = #{stationId}
            AND t.member_id IS NOT NULL
    </select>

    <select id="leaderMembers" resultType="com.laowu.vo.team.LeaderMembersVO">
        SELECT
            t7.mi AS id,
            t7.user_name,
            t7.telephone,
            t7.id_card_type,
            t7.id_card,
            t7.tct as teamCnt,
            t8.pct as teamTotalCnt
        FROM
            (
            SELECT
                t1.id AS mi,
                t1.user_name,
                t1.telephone,
                t1.id_card_type,
                t1.id_card,
                count(*) AS tct
            FROM
                member_dict t1
                LEFT JOIN team_dict t2 ON t1.id = t2.member_id
            WHERE
                t2.member_id IS NOT NULL
                AND t1.delete_date IS NULL
                AND t2.delete_date IS NULL
                AND t2.station_id = #{stationId}
            GROUP BY
                t1.id
            ) t7
            LEFT JOIN (
            SELECT
                mi1,
                ct1 - rpt AS pct
            FROM
                (
                SELECT
                    t1.id AS mi1,
                    COUNT(*) AS ct1
                FROM
                    member_dict t1
                    LEFT JOIN team_dict t2 ON t1.id = t2.member_id
                    LEFT JOIN member_team_mapping t3 ON t2.id = t3.team_id
                WHERE
                    t2.member_id IS NOT NULL
                    AND t1.delete_date IS NULL
                    AND t2.delete_date IS NULL
                    and t3.delete_date IS NULL
                    AND t2.station_id = #{stationId}
                GROUP BY
                    t1.id
                ) t4
                LEFT JOIN ( SELECT t6.member_id AS mi2, COUNT(*)- 1 AS rpt FROM member_team_mapping t6 WHERE t6.delete_date IS NULL GROUP BY t6.member_id ) t5 ON t4.mi1 = t5.mi2
            ) t8 ON t7.mi = t8.mi1
        WHERE
            t7.user_name LIKE concat('%', #{userName}, '%')
    </select>

    <select id="memberManagement" resultType="com.laowu.vo.team.MemberManagementVO">
        SELECT DISTINCT
            t1.id,
            t1.user_name,
            t1.job_status,
            t1.telephone,
            t1.id_card_type,
            t1.id_card,
            t1.province,
            t1.city,
            t1.address,
            t1.start_date,
            t1.end_date,
            t1.is_poor,
            t1.is_migration,
            t1.is_party
        FROM
            member_dict t1
            LEFT JOIN member_team_mapping t2 ON t1.id = t2.member_id AND t2.delete_date IS NULL
            LEFT JOIN team_dict t3 ON t2.team_id = t3.id AND t3.delete_date IS NULL
            LEFT JOIN workstation_dict t4 ON t3.station_id = t4.id AND t4.delete_date IS NULL
        WHERE
            t1.delete_date IS NULL
            <if test="jobStatus != null and jobStatus != ''">
                AND t1.job_status = #{jobStatus}
            </if>
            <if test="teamId != null and teamId != ''">
                AND t3.id = #{teamId}
            </if>
            <if test="province != null and province != ''">
                AND t1.province = #{province}
            </if>
            <if test="stationId != null and stationId != ''">
                AND t4.id = #{stationId}
            </if>
            <if test="userName != null and userName != ''">
                and t1.user_name LIKE concat('%', #{userName}, '%')
            </if>

    </select>

    <select id="memberManagementCount" resultType="integer">
        SELECT count(DISTINCT
        t1.id,
        t1.user_name,
        t1.job_status,
        t1.telephone,
        t1.id_card_type,
        t1.id_card,
        t1.province,
        t1.city,
        t1.address,
        t1.start_date,
        t1.end_date,
        t1.is_poor,
        t1.is_migration,
        t1.is_party)
        FROM
        member_dict t1
        LEFT JOIN member_team_mapping t2 ON t1.id = t2.member_id
        LEFT JOIN team_dict t3 ON t2.team_id = t3.id
        LEFT JOIN workstation_dict t4 ON t3.station_id = t4.id
        WHERE
        t1.delete_date IS NULL
        AND t2.delete_date IS NULL
        AND t3.delete_date IS NULL
        AND t4.delete_date IS NULL
        <if test="jobStatus != null and jobStatus != ''">
            AND t1.job_status = #{jobStatus}
        </if>
        <if test="teamId != null and teamId != ''">
            AND t3.id = #{teamId}
        </if>
        <if test="province != null and province != ''">
            AND t1.province = #{province}
        </if>
        <if test="stationId != null and stationId != ''">
            AND t4.id = #{stationId}
        </if>
        <if test="userName != null and userName != ''">
            and t1.user_name like LIKE concat('%', #{userName}, '%')
        </if>
    </select>

    <update id="noLeader" parameterType="long">
        update team_dict set member_id = null where id = #{id}
    </update>

</mapper>