<?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.njcn.mapper.excelreport.GetInICurrentDataMapper">
    <select id="getICurrent" resultType="java.util.HashMap">
        select phasic_type PHASETYPE,
        <foreach collection="listValue" item="item" separator=",">
            max(I_${item}_MAX) I_${item}_MAX,min(I_${item}_MIN) I_${item}_MIN,round(avg(I_${item}) ,2) I_${item}
            ,max(case when I${item}CP95 =#{conditionData.count} then I_${item} else null end) I_${item}_CP95
        </foreach>
        from ( select t.*,
        <foreach collection="listValue" item="item" separator=",">
            row_number() over (partition by phasic_type order by I_${item} desc) I${item}CP95
        </foreach>
        from
        <choose>
            <when test="conditionData.b == true">
                Data_InHarm_i
            </when>
            <otherwise>
                Day_InHarm_i
            </otherwise>
        </choose>
        t where lineid=#{conditionData.pointIndex} and phasic_type in ('A','B','C') and timeid between
        #{conditionData.start}
        and #{conditionData.end}
        <if test="conditionData.b == true">
            and QualityFlag = 0
        </if>
        <foreach collection="conditionData.exceptTime" index="index" item="item" open=" " separator=" " close="">
            and timeid not between #{item.start} and #{item.end}
        </foreach>)
        group by phasic_type
    </select>
</mapper>