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

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


    <!-- 查询个人身体健康状况 -->
    <select id="queryPersonalHealthStatus" resultType="String">
        SELECT physical_health_status
        FROM sys_user
        WHERE user_id = #{userId}
    </select>

    <!-- 查询组织身体健康状况统计 (身体情况为空或者空字符串的人数)-->
    <select id="queryOrgHealthStats" resultType="com.sundot.airport.system.domain.portrait.PhysicalHealthStats">
        SELECT
            SUM(CASE WHEN physical_health_status IS NULL  OR TRIM(physical_health_status) = '' THEN 1 ELSE 0 END) AS healthyCount,
            COUNT(*) AS totalCount,
            ROUND(SUM(CASE WHEN physical_health_status IS NULL  OR TRIM(physical_health_status) = '' THEN 1 ELSE 0 END) / COUNT(*), 4) AS healthyPercentage
        FROM sys_user
        WHERE user_id in <include refid="userIdsCondition" /> and   del_flag='0' and status='0'
    </select>

</mapper>