<?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.GetFpyMapper">
    <select id="getFpy" resultType="java.util.HashMap">
        select phasic_type PHASETYPE,
        <choose>
            <when test="flag != 2">
                SUM(UHARM_2_OVERTIME) UHARM_2_OVERTIME,SUM(IHARM_2_OVERTIME) IHARM_2_OVERTIME,
                SUM(UHARM_3_OVERTIME) UHARM_3_OVERTIME,SUM(IHARM_3_OVERTIME) IHARM_3_OVERTIME,
                SUM(UHARM_4_OVERTIME) UHARM_4_OVERTIME,SUM(IHARM_4_OVERTIME) IHARM_4_OVERTIME,
                SUM(UHARM_5_OVERTIME) UHARM_5_OVERTIME,SUM(IHARM_5_OVERTIME) IHARM_5_OVERTIME,
                SUM(UHARM_6_OVERTIME) UHARM_6_OVERTIME,SUM(IHARM_6_OVERTIME) IHARM_6_OVERTIME,
                SUM(UHARM_7_OVERTIME) UHARM_7_OVERTIME,SUM(IHARM_7_OVERTIME) IHARM_7_OVERTIME,
                SUM(UHARM_8_OVERTIME) UHARM_8_OVERTIME,SUM(IHARM_8_OVERTIME) IHARM_8_OVERTIME,
                SUM(UHARM_9_OVERTIME) UHARM_9_OVERTIME,SUM(IHARM_9_OVERTIME) IHARM_9_OVERTIME,
                SUM(UHARM_10_OVERTIME) UHARM_10_OVERTIME,SUM(IHARM_10_OVERTIME) IHARM_10_OVERTIME,
                SUM(UHARM_11_OVERTIME) UHARM_11_OVERTIME,SUM(IHARM_11_OVERTIME) IHARM_11_OVERTIME,
                SUM(UHARM_12_OVERTIME) UHARM_12_OVERTIME,SUM(IHARM_12_OVERTIME) IHARM_12_OVERTIME,
                SUM(UHARM_13_OVERTIME) UHARM_13_OVERTIME,SUM(IHARM_13_OVERTIME) IHARM_13_OVERTIME,
                SUM(UHARM_14_OVERTIME) UHARM_14_OVERTIME,SUM(IHARM_14_OVERTIME) IHARM_14_OVERTIME,
                SUM(UHARM_15_OVERTIME) UHARM_15_OVERTIME,SUM(IHARM_15_OVERTIME) IHARM_15_OVERTIME,
                SUM(UHARM_16_OVERTIME) UHARM_16_OVERTIME,SUM(IHARM_16_OVERTIME) IHARM_16_OVERTIME,
                SUM(UHARM_17_OVERTIME) UHARM_17_OVERTIME,SUM(IHARM_17_OVERTIME) IHARM_17_OVERTIME,
                SUM(UHARM_18_OVERTIME) UHARM_18_OVERTIME,SUM(IHARM_18_OVERTIME) IHARM_18_OVERTIME,
                SUM(UHARM_19_OVERTIME) UHARM_19_OVERTIME,SUM(IHARM_19_OVERTIME) IHARM_19_OVERTIME,
                SUM(UHARM_20_OVERTIME) UHARM_20_OVERTIME,SUM(IHARM_20_OVERTIME) IHARM_20_OVERTIME,
                SUM(UHARM_21_OVERTIME) UHARM_21_OVERTIME,SUM(IHARM_21_OVERTIME) IHARM_21_OVERTIME,
                SUM(UHARM_22_OVERTIME) UHARM_22_OVERTIME,SUM(IHARM_22_OVERTIME) IHARM_22_OVERTIME,
                SUM(UHARM_23_OVERTIME) UHARM_23_OVERTIME,SUM(IHARM_23_OVERTIME) IHARM_23_OVERTIME,
                SUM(UHARM_24_OVERTIME) UHARM_24_OVERTIME,SUM(IHARM_24_OVERTIME) IHARM_24_OVERTIME,
                SUM(UHARM_25_OVERTIME) UHARM_25_OVERTIME,SUM(IHARM_25_OVERTIME) IHARM_25_OVERTIME,
                SUM(VOLTAGE_DEV_OVERTIME) VOLTAGE_DEV_OVERTIME,
                SUM(UABERRANCE_OVERTIME) UABERRANCE_OVERTIME,
                SUM(FLICKER_OVERTIME) FLICKER_OVERTIME,
                SUM(ALLTIME) ALLTIME,
                SUM(FLICKET_ALLTIME) FLICKET_ALLTIME
                FROM LIMIT_RATE
                where timeid between #{condition.start} and #{condition.end} and myindex = #{condition.pointIndex} and
                Phasic_Type in('A','B','C','T')
                <foreach collection="condition.exceptTime" index="index" item="item" open=" " separator=" " close="">
                    and timeid not between #{item.start} and #{item.end}
                </foreach>
            </when>
            <otherwise>
                sum(UBalance_OverTime) UBALANCE_OVERTIME,
                sum(Freq_Dev_OverTime) FREQ_DEV_OVERTIME,
                sum(AllTime) ALLTIME
                from limit_rate
                where timeid between #{condition.start} and #{condition.end}
                and myindex = #{condition.pointIndex}
                and Phasic_Type = 'T'
                <foreach collection="condition.exceptTime" index="index" item="item" open=" " separator=" " close="">
                    and timeid not between #{item.start} and #{item.end}
                </foreach>
            </otherwise>
        </choose>
        group by phasic_type
    </select>
</mapper>
