<?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.PoliticalReviewIndicatorMapper">

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


    <!-- 查询个人政审通过情况 -->
    <select id="queryPersonalPoliticalReviewStatus" resultType="String">
        SELECT political_review_situation
        FROM sys_user
        WHERE user_id = #{userId}
    </select>

    <!-- 查询组织政审通过情况统计 -->
    <select id="queryOrgPoliticalReviewStats"
            resultType="com.sundot.airport.system.domain.portrait.PoliticalReviewStats">
        SELECT
        SUM(CASE WHEN political_review_situation = '1' THEN 1 ELSE 0 END) AS passedCount,
        COUNT(*) AS totalCount,
        ROUND(SUM(CASE WHEN political_status = '1' THEN 1 ELSE 0 END) / COUNT(*), 4) AS passPercentage
        FROM sys_user
        WHERE user_id in
        <include refid="userIdsCondition"/>
        and del_flag='0' and status='0'
    </select>

</mapper>