WorkstationDictMapper.xml 7.24 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.WorkstationDictMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.laowu.model.WorkstationDictDO">
        <id column="id" property="id"/>
        <result column="create_date" property="createDate"/>
        <result column="update_date" property="updateDate"/>
        <result column="delete_date" property="deleteDate"/>
        <result column="workstation_name" property="workstationName"/>
        <result column="province" property="province"/>
        <result column="city" property="city"/>
        <result column="county" property="county"/>
        <result column="comment" property="comment"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, workstation_name, province, city, county, administer_id, comment
    </sql>

    <select id="stations" resultType="com.laowu.vo.station.StationsVO">
        SELECT
        t.id,
        t.workstation_name,
        t.province,
        t.city,
        t.county,
        t.`comment`
        FROM
        workstation_dict t
        WHERE
        t.delete_date IS NULL
        <if test="province != null and province !=''">
            AND t.province = #{province}
        </if>
        <if test="city != null and city != ''">
            AND t.city = #{city}
        </if>
        <if test="county != null and county != ''">
            AND t.county = #{county}
        </if>
        <if test="workstationName != null and workstationName != ''">
            and t.workstation_name LIKE concat('%', #{workstationName}, '%')
        </if>
    </select>

    <select id="stationAccount" parameterType="string" resultType="com.laowu.vo.station.StationAccountVO">
        SELECT
        t1.id,
        GROUP_CONCAT( t3.workstation_name ) as stationName,
        t1.user_name,
        t1.account,
        t1.telephone,
        t1.`password`
        FROM
        administer t1
        LEFT JOIN workstation_administers t2 ON t1.id = t2.administer_id
        LEFT JOIN workstation_dict t3 ON t2.workstation_id = t3.id
        left join role_administer_mapping t4 on t1.id = t4.administer_id
        WHERE
        t1.delete_date IS NULL
        AND t2.delete_date IS NULL
        AND t3.delete_date IS NULL
        and t4.role_id != 1
        <if test=" workingstationName!= null and workingstationName != ''">
            AND t3.workstation_name LIKE concat('%', #{workingstationName}, '%')
        </if>
        GROUP BY
        t1.id
    </select>

    <select id="provinces" resultType="string">
        SELECT DISTINCT
            province
        FROM
            workstation_dict t
        WHERE
            t.delete_date IS NULL
    </select>


    <select id="homepage" parameterType="long" resultType="com.laowu.vo.station.HomepageVO">
      SELECT
        t1.workstation_name,
        t1.province,
        t1.city,
        t1.county,
        IFNULL( t4.ct1, 0 ) AS memberCnt,
        IFNULL( t5.ct2, 0 ) AS leaderCnt,
        IFNULL( t6.ct3, 0 ) AS teamCnt,
        IFNULL( t7.ct4, 0 ) AS companyCnt,
        IFNULL( t8.ct5, 0 ) AS requireCnt
      FROM
            workstation_dict t1
            LEFT JOIN (
            SELECT
                t9.id,
                sum( ct9 ) AS ct1
            FROM
                 (
                SELECT
                    t1.id,
                    count( DISTINCT t2.id ) AS ct9
                FROM
                    workstation_dict t1
                    LEFT JOIN workstation_member_mapping t2 ON t1.id = t2.station_id
                    LEFT JOIN member_dict t3 ON t2.member_id = t3.id
                WHERE
                    t2.delete_date IS NULL
                    AND t3.delete_date IS NULL
                    AND t1.id = #{stationId}
                ) t9
            ) t4 ON t1.id = t4.id
            LEFT JOIN (
            SELECT
                t1.id,
                count( DISTINCT t2.member_id ) AS ct2
            FROM
                workstation_dict t1
                LEFT JOIN team_dict t2 ON t1.id = t2.station_id
            WHERE
                t1.id = #{stationId}
                AND t1.delete_date IS NULL
                AND t2.delete_date IS NULL
            ) t5 ON t1.id = t5.id
            LEFT JOIN (
            SELECT
                t1.id,
                count( DISTINCT t2.id ) AS ct3
            FROM
                workstation_dict t1
                LEFT JOIN team_dict t2 ON t1.id = t2.station_id
            WHERE
                t1.id = #{stationId}
                AND t1.delete_date IS NULL
                AND t2.delete_date IS NULL
            GROUP BY
                t2.station_id
            ) t6 ON t1.id = t6.id
            LEFT JOIN (
            SELECT
                t1.id,
                count( t2.id ) AS ct4
            FROM
                workstation_dict t1
                LEFT JOIN company_relate_work t2 ON t1.id = t2.station_id
            WHERE
                t1.delete_date IS NULL
                AND t2.delete_date IS NULL
                AND t1.id = #{stationId}
            ) t7 ON t1.id = t7.id
            LEFT JOIN (
            SELECT
                t3.id,
                sum( t3.ct15 + t4.ct16 ) AS ct5
            FROM
                (
                SELECT
                    t1.id,
                    sum( t3.require_counts ) AS ct15
                FROM
                    workstation_dict t1
                    LEFT JOIN workstation_alone_mapping t2 ON t1.id = t2.station_id
                    LEFT JOIN position_alone_info t3 ON t2.alone_id = t3.id
                WHERE
                    t1.delete_date IS NULL
                    AND t2.delete_date IS NULL
                    AND t3.delete_date IS NULL
                    AND origin_id IS NOT NULL
                    AND t1.id = #{stationId}
                ) t3
                LEFT JOIN (
                SELECT
                    t1.id,
                    sum( t4.require_counts ) AS ct16
                FROM
                    workstation_dict t1
                    LEFT JOIN workstation_require_mapping t2 ON t1.id = t2.station_id
                    LEFT JOIN position_require_item t3 ON t2.require_id = t3.id
                    LEFT JOIN position_item_info t4 ON t3.id = t4.position_require_id
                WHERE
                    t1.id = #{stationId}
                    AND t1.delete_date IS NULL
                    AND t2.delete_date IS NULL
                    AND t3.delete_date IS NULL
                    AND t4.delete_date IS NULL
                GROUP BY
                    t1.id
                ) t4 ON t3.id = t4.id
            ) t8 ON t1.id = t8.id
        WHERE
            t1.id = #{stationId}
    </select>

    <select id="administerProvinceStations" resultType="com.laowu.model.WorkstationDictDO">
        SELECT
            t.id,
            t.workstation_name
        FROM
            workstation_dict t
            LEFT JOIN workstation_administers t2 ON t.id = t2.workstation_id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            and t2.administer_id = #{administerId}
            and t.province = #{province}
    </select>
</mapper>