<?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.harmonic.mapper.RStatLimitRateDMapper">

    <select id="getSumPassRate" resultType="com.njcn.harmonic.pojo.vo.RStatLimitRateDVO">
        SELECT
            SUM( all_time ) AS alltime,
            SUM( freq_dev_overtime ) AS frequency,
            SUM( ubalance_overtime ) AS uBalance,
            SUM( i_neg_overtime ) AS iNeg,
            SUM( iharm_13_overtime ) AS harmElec,
            SUM( uharm_4_overtime ) AS harmVoltage,
            SUM( flicker_overtime ) AS flicker,
            SUM( flicker_all_time ) AS allFlicker,
            SUM( voltage_dev_overtime ) AS voltageDeviation,
            SUM( inuharm_9_overtime ) AS inUharm
        FROM
            r_stat_limit_rate_d
        <where>
            <if test=" ids != null and ids.size > 0">
                AND my_index IN
                <foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test=" statTime != null and statTime !=''">
                AND  time_id >= #{statTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND  time_id &lt;= #{endTime}
            </if>
        </where>
    </select>
    <select id="getSumLimitRateByLineIndexes" resultType="com.njcn.harmonic.pojo.vo.MonitorOverLimitVO">
        SELECT
        my_index AS id,
        SUM(all_time) AS overDay,
        SUM(freq_dev_overtime) AS freqOverDay,
        SUM(voltage_dev_overtime ) AS volDevOverDay,
        SUM(flicker_overtime) AS flickerOverDay,
        SUM(i_neg_overtime) AS negativeOverDay,
        SUM(ubalance_overtime) AS threeUnbalance,
        SUM(uaberrance_overtime) AS volDisOverDay,
        SUM(uharm_3_overtime) AS overVolThreeTimes,
        SUM(uharm_5_overtime) AS overVolFiveTimes,
        SUM(uharm_7_overtime) AS overVolSevenTimes,
        SUM(uharm_11_overtime) AS overVolElevenTimes,
        SUM(uharm_13_overtime) AS overVolThirteenTimes,
        SUM(uharm_23_overtime) AS overVolTwentyThreeTimes,
        SUM(uharm_25_overtime) AS overVolTwentyFiveTimes,
        SUM(uharm_2_overtime)
        + SUM(uharm_4_overtime)
        + SUM(uharm_6_overtime)
        + SUM(uharm_8_overtime)
        + SUM(uharm_9_overtime)
        + SUM(uharm_10_overtime)
        + SUM(uharm_12_overtime)
        + SUM(uharm_14_overtime)
        + SUM(uharm_15_overtime)
        + SUM(uharm_16_overtime)
        + SUM(uharm_17_overtime)
        + SUM(uharm_18_overtime)
        + SUM(uharm_19_overtime)
        + SUM(uharm_20_overtime)
        + SUM(uharm_21_overtime)
        + SUM(uharm_22_overtime)
        + SUM(uharm_24_overtime) AS overVolOtherTimes,
        SUM(iharm_3_overtime) AS overCurThreeTimes,
        SUM(iharm_5_overtime) AS overCurFiveTimes,
        SUM(iharm_7_overtime) AS overCurSevenTimes,
        SUM(iharm_11_overtime) AS overCurElevenTimes,
        SUM(iharm_13_overtime) AS overCurThirteenTimes,
        SUM(iharm_23_overtime) AS overCurTwentyThreeTimes,
        SUM(iharm_25_overtime) AS overCurTwentyFiveTimes,
        SUM(iharm_2_overtime)
        + SUM(iharm_4_overtime)
        + SUM(iharm_6_overtime)
        + SUM(iharm_8_overtime)
        + SUM(iharm_9_overtime)
        + SUM(iharm_10_overtime)
        + SUM(iharm_12_overtime)
        + SUM(iharm_14_overtime)
        + SUM(iharm_15_overtime)
        + SUM(iharm_16_overtime)
        + SUM(iharm_17_overtime)
        + SUM(iharm_18_overtime)
        + SUM(iharm_19_overtime)
        + SUM(iharm_20_overtime)
        + SUM(iharm_21_overtime)
        + SUM(iharm_22_overtime)
        + SUM(iharm_24_overtime) AS overCurOtherTimes
        FROM
        r_stat_limit_rate_d
        <where>
            <if test=" ids != null and ids.size > 0">
                AND my_index IN
                <foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test=" statTime != null and statTime !=''">
                AND  time_id >= #{statTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND  time_id &lt;= #{endTime}
            </if>
        </where>
        GROUP BY my_index
    </select>
    <select id="getSumLimitRatePage" resultType="com.njcn.harmonic.pojo.vo.MonitorOverLimitVO">
        SELECT
        my_index AS id,
        SUM(all_time) AS overDay,
        SUM(freq_dev_overtime) AS freqOverDay,
        SUM(voltage_dev_overtime ) AS volDevOverDay,
        SUM(flicker_overtime) AS flickerOverDay,
        SUM(i_neg_overtime) AS negativeOverDay,
        SUM(ubalance_overtime) AS threeUnbalance,
        SUM(uaberrance_overtime) AS volDisOverDay,
        SUM(uharm_3_overtime) AS overVolThreeTimes,
        SUM(uharm_5_overtime) AS overVolFiveTimes,
        SUM(uharm_7_overtime) AS overVolSevenTimes,
        SUM(uharm_11_overtime) AS overVolElevenTimes,
        SUM(uharm_13_overtime) AS overVolThirteenTimes,
        SUM(uharm_23_overtime) AS overVolTwentyThreeTimes,
        SUM(uharm_25_overtime) AS overVolTwentyFiveTimes,
        SUM(uharm_2_overtime)
        + SUM(uharm_4_overtime)
        + SUM(uharm_6_overtime)
        + SUM(uharm_8_overtime)
        + SUM(uharm_9_overtime)
        + SUM(uharm_10_overtime)
        + SUM(uharm_12_overtime)
        + SUM(uharm_14_overtime)
        + SUM(uharm_15_overtime)
        + SUM(uharm_16_overtime)
        + SUM(uharm_17_overtime)
        + SUM(uharm_18_overtime)
        + SUM(uharm_19_overtime)
        + SUM(uharm_20_overtime)
        + SUM(uharm_21_overtime)
        + SUM(uharm_22_overtime)
        + SUM(uharm_24_overtime) AS overVolOtherTimes,
        SUM(iharm_3_overtime) AS overCurThreeTimes,
        SUM(iharm_5_overtime) AS overCurFiveTimes,
        SUM(iharm_7_overtime) AS overCurSevenTimes,
        SUM(iharm_11_overtime) AS overCurElevenTimes,
        SUM(iharm_13_overtime) AS overCurThirteenTimes,
        SUM(iharm_23_overtime) AS overCurTwentyThreeTimes,
        SUM(iharm_25_overtime) AS overCurTwentyFiveTimes,
        SUM(iharm_2_overtime)
        + SUM(iharm_4_overtime)
        + SUM(iharm_6_overtime)
        + SUM(iharm_8_overtime)
        + SUM(iharm_9_overtime)
        + SUM(iharm_10_overtime)
        + SUM(iharm_12_overtime)
        + SUM(iharm_14_overtime)
        + SUM(iharm_15_overtime)
        + SUM(iharm_16_overtime)
        + SUM(iharm_17_overtime)
        + SUM(iharm_18_overtime)
        + SUM(iharm_19_overtime)
        + SUM(iharm_20_overtime)
        + SUM(iharm_21_overtime)
        + SUM(iharm_22_overtime)
        + SUM(iharm_24_overtime) AS overCurOtherTimes
        FROM
        r_stat_limit_target_d
        <where>
            <if test=" ids != null and ids.size > 0">
                AND my_index IN
                <foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test=" statTime != null and statTime !=''">
                AND  time_id >= #{statTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND  time_id &lt;= #{endTime}
            </if>
        </where>
        GROUP BY my_index
    </select>
    <select id="getPercentages" resultType="com.njcn.harmonic.pojo.vo.MonitorOverLimitVO$DataVO">
        SELECT
        DATE_FORMAT(time_id,'%Y-%m-%d') AS time,
        IFNULL(TRUNCATE ((1- (
        sum( flicker_overtime )+ sum( flicker_all_time )+ sum( freq_dev_overtime )+ sum( voltage_dev_overtime )+ sum( ubalance_overtime )+ sum( uaberrance_overtime )+ sum( i_neg_overtime )+ sum( uharm_2_overtime )+ sum( uharm_3_overtime )+ sum( uharm_4_overtime )+ sum( uharm_5_overtime )+ sum( uharm_6_overtime )+ sum( uharm_7_overtime )+ sum( uharm_8_overtime )+ sum( uharm_9_overtime )+ sum( uharm_10_overtime )+ sum( uharm_11_overtime )+ sum( uharm_12_overtime )+ sum( uharm_13_overtime )+ sum( uharm_14_overtime )+ sum( uharm_15_overtime )+ sum( uharm_16_overtime )+ sum( uharm_17_overtime )+ sum( uharm_18_overtime )+ sum( uharm_19_overtime )+ sum( uharm_20_overtime )+ sum( uharm_21_overtime )+ sum( uharm_22_overtime )+ sum( uharm_23_overtime )+ sum( uharm_24_overtime )+ sum( uharm_25_overtime )+ sum( iharm_2_overtime )+ sum( iharm_3_overtime )+ sum( iharm_4_overtime )+ sum( iharm_5_overtime )+ sum( iharm_6_overtime )+ sum( iharm_7_overtime )+ sum( iharm_8_overtime )+ sum( iharm_9_overtime )+ sum( iharm_10_overtime )+ sum( iharm_11_overtime )+ sum( iharm_12_overtime )+ sum( iharm_13_overtime )+ sum( iharm_14_overtime )+ sum( iharm_15_overtime )+ sum( iharm_16_overtime )+ sum( iharm_17_overtime )+ sum( iharm_18_overtime )+ sum( iharm_19_overtime )+ sum( iharm_20_overtime )+ sum( iharm_21_overtime )+ sum( iharm_22_overtime )+ sum( iharm_23_overtime )+ sum( iharm_24_overtime )+ sum( iharm_25_overtime )+ sum( inuharm_1_overtime )+ sum( inuharm_2_overtime )+ sum( inuharm_3_overtime )+ sum( inuharm_4_overtime )+ sum( inuharm_5_overtime )+ sum( inuharm_6_overtime )+ sum( inuharm_7_overtime )+ sum( inuharm_8_overtime )+ sum( inuharm_9_overtime )+ sum( inuharm_10_overtime )+ sum( inuharm_11_overtime )+ sum( inuharm_12_overtime )+ sum( inuharm_13_overtime )+ sum( inuharm_14_overtime )+ sum( inuharm_15_overtime )+ sum( inuharm_16_overtime )) /(
        SUM( all_time )* 71 )
        )* 100,2),0) `data`
        FROM
        r_stat_limit_rate_d
        <where>
            phasic_type = "T"
            <if test=" ids != null and ids.size > 0">
                AND my_index IN
                <foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test=" statTime != null and statTime !=''">
                AND  time_id >= #{statTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND  time_id &lt;= #{endTime}
            </if>
        </where>
        GROUP BY
        `time`
    </select>
    <select id="getSumPassRateList" resultType="com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO">
        SELECT
        my_index as lineId ,
        sum(all_time) as all_time,
        sum(flicker_all_time) as flicker_all_time,
        sum(freq_dev_overtime) as freq_dev_overtime,
        sum(voltage_dev_overtime) as voltage_dev_overtime,
        sum(ubalance_overtime) as ubalance_overtime,
        sum(flicker_overtime) as flicker_overtime,
        sum(uaberrance_overtime) as uaberrance_overtime,
        sum(uharm_2_overtime) as uharm_2_overtime,
        sum(uharm_3_overtime) as uharm_3_overtime,
        sum(uharm_4_overtime) as uharm_4_overtime,
        sum(uharm_5_overtime) as uharm_5_overtime,
        sum(uharm_6_overtime) as uharm_6_overtime,
        sum(uharm_7_overtime) as uharm_7_overtime,
        sum(uharm_8_overtime) as uharm_8_overtime,
        sum(uharm_9_overtime) as uharm_9_overtime,
        sum(uharm_10_overtime) as uharm_10_overtime,
        sum(uharm_11_overtime) as uharm_11_overtime,
        sum(uharm_12_overtime) as uharm_12_overtime,
        sum(uharm_13_overtime) as uharm_13_overtime,
        sum(uharm_14_overtime) as uharm_14_overtime,
        sum(uharm_15_overtime) as uharm_15_overtime,
        sum(uharm_16_overtime) as uharm_16_overtime,
        sum(uharm_17_overtime) as uharm_17_overtime,
        sum(uharm_18_overtime) as uharm_18_overtime,
        sum(uharm_19_overtime) as uharm_19_overtime,
        sum(uharm_20_overtime) as uharm_20_overtime,
        sum(uharm_21_overtime) as uharm_21_overtime,
        sum(uharm_22_overtime) as uharm_22_overtime,
        sum(uharm_23_overtime) as uharm_23_overtime,
        sum(uharm_24_overtime) as uharm_24_overtime,
        sum(uharm_25_overtime) as uharm_25_overtime,
        sum(iharm_2_overtime) as iharm_2_overtime,
        sum(iharm_3_overtime) as iharm_3_overtime,
        sum(iharm_4_overtime) as iharm_4_overtime,
        sum(iharm_5_overtime) as iharm_5_overtime,
        sum(iharm_6_overtime) as iharm_6_overtime,
        sum(iharm_7_overtime) as iharm_7_overtime,
        sum(iharm_8_overtime) as iharm_8_overtime,
        sum(iharm_9_overtime) as iharm_9_overtime,
        sum(iharm_10_overtime) as iharm_10_overtime,
        sum(iharm_11_overtime) as iharm_11_overtime,
        sum(iharm_12_overtime) as iharm_12_overtime,
        sum(iharm_13_overtime) as iharm_13_overtime,
        sum(iharm_14_overtime) as iharm_14_overtime,
        sum(iharm_15_overtime) as iharm_15_overtime,
        sum(iharm_16_overtime) as iharm_16_overtime,
        sum(iharm_17_overtime) as iharm_17_overtime,
        sum(iharm_18_overtime) as iharm_18_overtime,
        sum(iharm_19_overtime) as iharm_19_overtime,
        sum(iharm_20_overtime) as iharm_20_overtime,
        sum(iharm_21_overtime) as iharm_21_overtime,
        sum(iharm_22_overtime) as iharm_22_overtime,
        sum(iharm_23_overtime) as iharm_23_overtime,
        sum(iharm_24_overtime) as iharm_24_overtime,
        sum(iharm_25_overtime) as iharm_25_overtime,
        sum(inuharm_1_overtime) as inuharm_1_overtime,
        sum(inuharm_2_overtime) as inuharm_2_overtime,
        sum(inuharm_3_overtime) as inuharm_3_overtime,
        sum(inuharm_4_overtime) as inuharm_4_overtime,
        sum(inuharm_5_overtime) as inuharm_5_overtime,
        sum(inuharm_6_overtime) as inuharm_6_overtime,
        sum(inuharm_7_overtime) as inuharm_7_overtime,
        sum(inuharm_8_overtime) as inuharm_8_overtime,
        sum(inuharm_9_overtime) as inuharm_9_overtime,
        sum(inuharm_10_overtime) as inuharm_10_overtime,
        sum(inuharm_11_overtime) as inuharm_11_overtime,
        sum(inuharm_12_overtime) as inuharm_12_overtime,
        sum(inuharm_13_overtime) as inuharm_13_overtime,
        sum(inuharm_14_overtime) as inuharm_14_overtime,
        sum(inuharm_15_overtime) as inuharm_15_overtime,
        sum(inuharm_16_overtime) as inuharm_16_overtime,
        sum(i_neg_overtime) as i_neg_overtime
        from
            r_stat_limit_rate_d
        <where>
            phasic_type = "T"
            <if test=" ids != null and ids.size > 0">
                AND my_index IN
                <foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
                    #{item}
                </foreach>
            </if>
            <if test=" statTime != null and statTime !=''">
                AND  time_id >= #{statTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND  time_id &lt;= #{endTime}
            </if>
        </where>
        GROUP BY
            `my_index`
    </select>
</mapper>
