<?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.GetFlickerDataMapper">
    <select id="getFlickerData" resultType="java.util.HashMap">
        <choose>
            <when test="condition.b == true">
                SELECT PHASIC_TYPE PHASETYPE,MAX(PST) PST_MAX,MIN(PST) PST_MIN,ROUND(AVG(PST) ,2) PST,MAX(CASE WHEN
                PSTCP95
                =#{condition.pstCount} THEN PST ELSE NULL END) PST_CP95 FROM ( SELECT T.*
                ,ROW_NUMBER() OVER (PARTITION BY PHASIC_TYPE ORDER BY PST DESC) PSTCP95
                from
                Data_Flicker
            </when>
            <otherwise>
                SELECT PHASIC_TYPE PHASETYPE,MAX(PST_MAX) PST_MAX,MIN(PST_MIN) PST_MIN,ROUND(AVG(PST) ,2) PST,MAX(CASE
                WHEN PSTCP95
                =#{condition.pstCount} THEN PST ELSE NULL END) PST_CP95 FROM ( SELECT T.*
                ,ROW_NUMBER() OVER (PARTITION BY PHASIC_TYPE ORDER BY PST DESC) PSTCP95
                from
                Day_Flicker
            </otherwise>
        </choose>
        t where lineid=#{condition.pointIndex} and phasic_type in ('A','B','C') 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="getLFlickerData" resultType="java.util.HashMap">
        <choose>
            <when test="condition.b == true">
                SELECT PHASIC_TYPE PHASETYPE,MAX(PLT) PLT_MAX,MIN(PLT) PLT_MIN,ROUND(AVG(PLT) ,2) PLT,MAX(CASE WHEN
                PLTCP95
                =#{condition.pltCount} THEN PLT ELSE NULL END) PLT_CP95 FROM ( SELECT T.*
                ,ROW_NUMBER() OVER (PARTITION BY PHASIC_TYPE ORDER BY PLT DESC) PLTCP95
                from
                Data_plt
            </when>
            <otherwise>
                SELECT PHASIC_TYPE PHASETYPE,MAX(PLT_MAX) PLT_MAX,MIN(PLT_MIN) PLT_MIN,ROUND(AVG(PLT) ,2) PLT,MAX(CASE
                WHEN PLTCP95
                =#{condition.pltCount} THEN PLT ELSE NULL END) PLT_CP95 FROM ( SELECT T.*
                ,ROW_NUMBER() OVER (PARTITION BY PHASIC_TYPE ORDER BY PLT DESC) PLTCP95
                from
                Day_plt
            </otherwise>
        </choose>
        t where lineid=#{condition.pointIndex} and phasic_type in ('A','B','C') 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="getLLFlickerData" resultType="java.util.HashMap">
          SELECT PHASIC_TYPE PHASETYPE,PLT_MAX,PLT_MIN,PLT,PLT_CP95,TIMEID
        FROM DAY_PLT
        where lineid=#{condition.pointIndex} and phasic_type in ('A','B','C') and timeid between
        #{condition.start} and #{condition.end}
    </select>

</mapper>