<?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.pqs9000.mapper.report.GetPowerDataMapper">
    <select id="getPowerP" resultType="ReportValue">
        SELECT PHASIC_TYPE PHASETYPE, MAX(P_MAX) FMAXVALUE,MIN(P_MIN) MINVALUE,ROUND(AVG(P) ,2)
        MEANVALUE,MAX(CASE WHEN PCP95 = #{condition.count} THEN P ELSE NULL END) CP95VALUE
        from ( select t.*,row_number() over (partition by phasic_type order by P desc) PCP95 from
        <choose>
            <when test="condition.b == true">
                Data_HarmPower_P
            </when>
            <otherwise>
                Day_HarmPower_P
            </otherwise>
        </choose>
        t
        where lineid=#{condition.pointIndex} and phasic_type in('A','B','C','T') and timeid between
        #{condition.start} and #{condition.end}
        <if test="condition.b == true">
            and QualityFlag = 0
        </if>
        <foreach collection="condition.exceptTime" index="index" item="item" open=" " separator=" " close="">
            and timeid not between #{item.start} and #{item.end}
        </foreach>) a
        group by phasic_type
    </select>

    <select id="getPowerQ" resultType="ReportValue">
        SELECT PHASIC_TYPE PHASETYPE, MAX(Q_MAX) FMAXVALUE,MIN(Q_MIN) MINVALUE,ROUND(AVG(Q) ,2)
        MEANVALUE,MAX(CASE WHEN QCP95 = #{condition.count} THEN Q ELSE NULL END) CP95VALUE
        from ( select t.*,row_number() over (partition by phasic_type order by Q desc) QCP95 from
        <choose>
            <when test="condition.b == true">
                Data_HarmPower_Q
            </when>
            <otherwise>
                Day_HarmPower_Q
            </otherwise>
        </choose>
        t
        where lineid=#{condition.pointIndex} and phasic_type in('A','B','C','T') and timeid between
        #{condition.start} and #{condition.end}
        <if test="condition.b == true">
            and QualityFlag = 0
        </if>
        <foreach collection="condition.exceptTime" index="index" item="item" open=" " separator=" " close="">
            and timeid not between #{item.start} and #{item.end}
        </foreach>) a
        group by phasic_type
    </select>


    <select id="getPowerS" resultType="ReportValue">
        SELECT PHASIC_TYPE PHASETYPE, MAX(S_MAX) FMAXVALUE,MIN(S_MIN) MINVALUE,ROUND(AVG(S) ,2)
        MEANVALUE,MAX(CASE WHEN SCP95 = #{condition.count} THEN S ELSE NULL END) CP95VALUE
        from ( select t.*,row_number() over (partition by phasic_type order by S desc) SCP95 from
        <choose>
            <when test="condition.b == true">
                Data_HarmPower_S
            </when>
            <otherwise>
                Day_HarmPower_S
            </otherwise>
        </choose>
        t
        where lineid=#{condition.pointIndex} and phasic_type in('A','B','C','T') and timeid between
        #{condition.start} and #{condition.end}
        <if test="condition.b == true">
            and QualityFlag = 0
        </if>
        <foreach collection="condition.exceptTime" index="index" item="item" open=" " separator=" " close="">
            and timeid not between #{item.start} and #{item.end}
        </foreach>) a
        group by phasic_type
    </select>
    
    <select id="getPF" resultType="ReportValue">
        SELECT PHASIC_TYPE PHASETYPE, MAX(PF_MAX) FMAXVALUE,MIN(PF_MIN) MINVALUE,ROUND(AVG(PF) ,2)
        MEANVALUE,MAX(CASE WHEN PFCP95 = #{condition.count} THEN PF ELSE NULL END) CP95VALUE
        from ( select t.*,row_number() over (partition by phasic_type order by PF desc) PFCP95 from
        <choose>
            <when test="condition.b == true">
                Data_HarmPower_P
            </when>
            <otherwise>
                Day_HarmPower_P
            </otherwise>
        </choose>
         t
        where lineid=#{condition.pointIndex} and phasic_type in('A','B','C','T') and timeid between
        #{condition.start} and #{condition.end}
        <if test="condition.b == true">
            and QualityFlag = 0
        </if>
        <foreach collection="condition.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>