TeamDictMapper.xml 7.1 KB
<?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
        left join workstation_dict t3 on t1.station_id = t3.id
        WHERE
        t1.delete_date IS NULL
        <if test="stationId != null and stationId != ''">
            and t1.station_id = #{stationId}
        </if>
        <if test="teamName != null and teamName != ''">
            and t1.team_name like concat('%', #{teamName}, '%')
        </if>
        <if test=" province != null and province != ''">
            and t3.province = #{province}
        </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.county,
            t1.address,
            t1.start_date,
            t1.end_date,
            t1.is_poor,
            t1.is_migration,
            t1.is_party
        FROM
        member_dict t1
        LEFT JOIN workstation_member_mapping t5 ON t1.id = t5.member_id and t5.delete_date is null
        LEFT JOIN workstation_dict t4 ON t5.station_id = t4.id AND t4.delete_date IS NULL
        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
        WHERE
            t1.delete_date IS NULL
            <if test="jobStatus != null and jobStatus != ''">
                AND t1.job_status = #{jobStatus}
            </if>
            <if test="province != null and province != ''">
                AND t4.province = #{province}
            </if>
            <if test="stationId != null and stationId != '' and teamId == null and teamId == ''">
                AND t4.id = #{stationId}
            </if>
            <if test="stationId != null and stationId != '' and teamId != null and teamId != ''">
                AND t3.id = #{teamId}
            </if>
            <if test="userName != null and userName != ''">
                and t1.user_name LIKE concat('%', #{userName}, '%')
            </if>
            <if test="workstationIds.size >0">
                and t4.id in
                <foreach collection="workstationIds" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            order by t1.create_date
    </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>