<?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.sundot.airport.system.mapper.portrait.SecurityWorkPositionIndicatorMapper">

    <resultMap type="com.sundot.airport.system.domain.portrait.SecurityWorkPositionStats"
               id="SecurityWorkPositionStatsResult">
        <result property="teamLeaderCount" column="team_leader_count"/>
        <result property="totalCount" column="total_count"/>
    </resultMap>

    <sql id="userIdsCondition">
        <foreach collection="userIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </sql>

    <!-- 查询个人在安检工作中担任过的最高职务 -->
    <select id="queryPersonalSecurityWorkPosition" resultType="String">
        SELECT security_inspection_position
        FROM sys_user
        WHERE user_id = #{userId}
          AND del_flag = '0'
    </select>

    <!-- 查询组织担任过班组长的人数统计 -->
    <select id="queryOrgSecurityWorkPositionStats" resultMap="SecurityWorkPositionStatsResult">
        SELECT
        COALESCE(SUM(CASE WHEN security_inspection_position = '班组长' THEN 1 ELSE 0 END), 0) AS team_leader_count,
        COUNT(*) AS total_count
        FROM sys_user
        WHERE del_flag = '0'
        AND status = '0'
        AND user_id in
        <include refid="userIdsCondition"/>
    </select>

</mapper>