<?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.pqs9300.mapper.report.GetFrequencyDataMapper">
    <select id="getFrequencyData" resultType="java.util.HashMap">
        select max(Freq_MAX) Freq_MAX,min(Freq_MIN) Freq_MIN,round(avg(Freq) ,2) Freq,
        max(CASE WHEN freqcp95 = #{condition.count}
        THEN Freq
        ELSE NULL END) Freq_CP95,
        max(Freq_dev_MAX) Freq_dev_MAX,min(Freq_dev_MIN) Freq_dev_MIN,round(avg(Freq_dev) ,2)
        Freq_dev,max(CASE WHEN freqdevcp95 = #{condition.count}
        THEN Freq_dev
        ELSE NULL END) Freq_dev_CP95
        FROM (SELECT
        t.*,
        row_number() over (partition BY phasic_type ORDER BY Freq DESC) freqcp95,
        row_number() over (partition BY phasic_type ORDER BY Freq_dev DESC) freqdevcp95
        FROM
        <choose>
            <when test="condition.b == true">
                Data_v
            </when>
            <otherwise>
                Day_v
            </otherwise>
        </choose>
        t
        where lineid=#{condition.pointIndex} and
        phasic_type='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
    </select>

    <select id="getHFrequencyData" resultType="java.util.HashMap">
        select Freq_DEV_MAX, Freq_DEV_MIN, Freq_DEV,Freq_DEV_CP95,timeid
        FROM day_v
        where lineid=#{condition.pointIndex} and
        phasic_type='T'
        and timeid between #{condition.start} and #{condition.end}
    </select>
</mapper>