<?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.GetVoltageDataMapper">
    <select id="getVoltageData" resultType="ReportValueData">
        select phasic_type phaseType,
        <choose>
            <when test="conditionData.b == true">
                max(FLUC) fmaxValue,min(FLUC) minValue,round(avg(FLUC) ,2) meanValue
                ,max(case when FLUCCP95 =#{conditionData.count} then FLUC else null end) cp95Value
                from ( select t.*,
                row_number() over (partition by phasic_type order by FLUC desc) FLUCCP95
                from Data_fluc
            </when>
            <otherwise>
                max(FLUC_MAX) fmaxValue,min(FLUC_MIN) minValue,round(avg(FLUC) ,2) meanValue
                ,max(case when FLUCCP95 =#{conditionData.count} then FLUC else null end) cp95Value
                from ( select t.*,
                row_number() over (partition by phasic_type order by FLUC desc) FLUCCP95
                from Day_fluc
            </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>) a
        group by phasic_type
    </select>
</mapper>