<?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.prepare.harmonic.mapper.mysql.line.RMpPartHarmonicDetailDMapper">

    <select id="getPartSumByData" resultType="com.njcn.harmonic.pojo.po.RMpPartHarmonicDetailM">
        SELECT
        measurement_point_id,
        sum( is_harmonic ) measurement_over_day,
        sum( is_freq ) freq_over_day,
        sum( is_v_dev_up ) v_dev_up_over_day,
        sum( is_v_dev_low ) v_dev_low_over_day,
        sum( is_v_dev ) v_dev_over_day,
        sum( is_v_thd ) v_thd_over_day,
        sum( is_v ) v_over_day,
        sum( is_i ) i_over_day,
        sum( is_v_2 ) v_2_over_day,
        sum( is_v_3 ) v_3_over_day,
        sum( is_v_4 ) v_4_over_day,
        sum( is_v_5 ) v_5_over_day,
        sum( is_v_6 ) v_6_over_day,
        sum( is_v_7 ) v_7_over_day,
        sum( is_v_8 ) v_8_over_day,
        sum( is_v_9 ) v_9_over_day,
        sum( is_v_10 ) v_10_over_day,
        sum( is_v_11 ) v_11_over_day,
        sum( is_v_12 ) v_12_over_day,
        sum( is_v_13 ) v_13_over_day,
        sum( is_v_14 ) v_14_over_day,
        sum( is_v_15 ) v_15_over_day,
        sum( is_v_16 ) v_16_over_day,
        sum( is_v_17 ) v_17_over_day,
        sum( is_v_18 ) v_18_over_day,
        sum( is_v_19 ) v_19_over_day,
        sum( is_v_20 ) v_20_over_day,
        sum( is_v_21 ) v_21_over_day,
        sum( is_v_22 ) v_22_over_day,
        sum( is_v_23 ) v_23_over_day,
        sum( is_v_24 ) v_24_over_day,
        sum( is_v_25 ) v_25_over_day,
        sum( is_i_2 ) i_2_over_day,
        sum( is_i_3 ) i_3_over_day,
        sum( is_i_4 ) i_4_over_day,
        sum( is_i_5 ) i_5_over_day,
        sum( is_i_6 ) i_6_over_day,
        sum( is_i_7 ) i_7_over_day,
        sum( is_i_8 ) i_8_over_day,
        sum( is_i_9 ) i_9_over_day,
        sum( is_i_10 ) i_10_over_day,
        sum( is_i_11 ) i_11_over_day,
        sum( is_i_12 ) i_12_over_day,
        sum( is_i_13 ) i_13_over_day,
        sum( is_i_14 ) i_14_over_day,
        sum( is_i_15 ) i_15_over_day,
        sum( is_i_16 ) i_16_over_day,
        sum( is_i_17 ) i_17_over_day,
        sum( is_i_18 ) i_18_over_day,
        sum( is_i_19 ) i_19_over_day,
        sum( is_i_20 ) i_20_over_day,
        sum( is_i_21 ) i_21_over_day,
        sum( is_i_22 ) i_22_over_day,
        sum( is_i_23 ) i_23_over_day,
        sum( is_i_24 ) i_24_over_day,
        sum( is_i_25 ) i_25_over_day,
        sum( is_unbalance ) unbalance_over_day,
        sum( is_i_neg ) i_neg_over_day
        FROM
        `r_mp_part_harmonic_detail_d`
        WHERE
        <![CDATA[data_date >= #{startTime}]]>
        AND <![CDATA[data_date <= #{endTime}]]>
        AND measurement_point_id = #{lineId}
        GROUP BY
        measurement_point_id
    </select>

    <select id="getHarmonicDetailDayOne" resultType="com.njcn.harmonic.pojo.po.RMpPartHarmonicDetailD">
        select
        t0.time_id dataDate,
        t0.my_index measurementPointId,
        case
        when t0.freq_dev_overtime>0 then 1
        else 0
        end isFreq,
        t0.freq_dev_overtime freqTimes,
        t0.voltage_dev_overtime vDevTimes,
        case
        when (t0.voltage_dev_overtime>0) then 1
        else 0
        end isVDev,
        case
        when t0.uaberrance_overtime>0 then 1
        else 0
        end isVThd,
        case
        when t0.ubalance_overtime>0 then 1
        else 0
        end isUnbalance,
        case
        when t0.i_neg_overtime>0 then 1
        else 0
        end isINeg,
        case
        when t0.uharm_2_overtime>0 then 1
        else 0
        end isV2,
        case
        when t0.uharm_3_overtime>0 then 1
        else 0
        end isV3,
        case
        when t0.uharm_4_overtime>0 then 1
        else 0
        end isV4,
        case
        when t0.uharm_5_overtime>0 then 1
        else 0
        end isV5,
        case
        when t0.uharm_6_overtime>0 then 1
        else 0
        end isV6,
        case
        when t0.uharm_7_overtime>0 then 1
        else 0
        end isV7,
        case
        when t0.uharm_8_overtime>0 then 1
        else 0
        end isV8,
        case
        when t0.uharm_9_overtime>0 then 1
        else 0
        end isV9,
        case
        when t0.uharm_10_overtime>0 then 1
        else 0
        end isV10,
        case
        when t0.uharm_11_overtime>0 then 1
        else 0
        end isV11,
        case
        when t0.uharm_12_overtime>0 then 1
        else 0
        end isV12,
        case
        when t0.uharm_13_overtime>0 then 1
        else 0
        end isV13,
        case
        when t0.uharm_14_overtime>0 then 1
        else 0
        end isV14,
        case
        when t0.uharm_15_overtime>0 then 1
        else 0
        end isV15,
        case
        when t0.uharm_16_overtime>0 then 1
        else 0
        end isV16,
        case
        when t0.uharm_17_overtime>0 then 1
        else 0
        end isV17,
        case
        when t0.uharm_18_overtime>0 then 1
        else 0
        end isV18,
        case
        when t0.uharm_19_overtime>0 then 1
        else 0
        end isV19,
        case
        when t0.uharm_20_overtime>0 then 1
        else 0
        end isV20,
        case
        when t0.uharm_21_overtime>0 then 1
        else 0
        end isV21,
        case
        when t0.uharm_22_overtime>0 then 1
        else 0
        end isV22,
        case
        when t0.uharm_23_overtime>0 then 1
        else 0
        end isV23,
        case
        when t0.uharm_24_overtime>0 then 1
        else 0
        end isV24,
        case
        when t0.uharm_25_overtime>0 then 1
        else 0
        end isV25,
        case
        when t0.iharm_2_overtime>0 then 1
        else 0
        end isI2,
        case
        when t0.iharm_3_overtime>0 then 1
        else 0
        end isI3,
        case
        when t0.iharm_4_overtime>0 then 1
        else 0
        end isI4,
        case
        when t0.iharm_5_overtime>0 then 1
        else 0
        end isI5,
        case
        when t0.iharm_6_overtime>0 then 1
        else 0
        end isI6,
        case
        when t0.iharm_7_overtime>0 then 1
        else 0
        end isI7,
        case
        when t0.iharm_8_overtime>0 then 1
        else 0
        end isI8,
        case
        when t0.iharm_9_overtime>0 then 1
        else 0
        end isI9,
        case
        when t0.iharm_10_overtime>0 then 1
        else 0
        end isI10,
        case
        when t0.iharm_11_overtime>0 then 1
        else 0
        end isI11,
        case
        when t0.iharm_12_overtime>0 then 1
        else 0
        end isI12,
        case
        when t0.iharm_13_overtime>0 then 1
        else 0
        end isI13,
        case
        when t0.iharm_14_overtime>0 then 1
        else 0
        end isI14,
        case
        when t0.iharm_15_overtime>0 then 1
        else 0
        end isI15,
        case
        when t0.iharm_16_overtime>0 then 1
        else 0
        end isI16,
        case
        when t0.iharm_17_overtime>0 then 1
        else 0
        end isI17,
        case
        when t0.iharm_18_overtime>0 then 1
        else 0
        end isI18,
        case
        when t0.iharm_19_overtime>0 then 1
        else 0
        end isI19,
        case
        when t0.iharm_20_overtime>0 then 1
        else 0
        end isI20,
        case
        when t0.iharm_21_overtime>0 then 1
        else 0
        end isI21,
        case
        when t0.iharm_22_overtime>0 then 1
        else 0
        end isI22,
        case
        when t0.iharm_23_overtime>0 then 1
        else 0
        end isI23,
        case
        when t0.iharm_24_overtime>0 then 1
        else 0
        end isI24,
        case
        when t0.iharm_25_overtime>0 then 1
        else 0
        end isI25,
        case
        when ifnull(t1.up, 0)>0 then 1
        else 0
        end isVDevUp,
        case
        when ifnull(t1.down, 0)>0 then 1
        else 0
        end isVDevLow,
        case
        when (
        t0.uaberrance_overtime>0
        or t0.uharm_2_overtime>0
        or t0.uharm_3_overtime>0
        or t0.uharm_4_overtime>0
        or t0.uharm_5_overtime>0
        or t0.uharm_6_overtime>0
        or t0.uharm_7_overtime>0
        or t0.uharm_8_overtime>0
        or t0.uharm_9_overtime>0
        or t0.uharm_10_overtime>0
        or t0.uharm_11_overtime>0
        or t0.uharm_12_overtime>0
        or t0.uharm_13_overtime>0
        or t0.uharm_14_overtime>0
        or t0.uharm_15_overtime>0
        or t0.uharm_16_overtime>0
        or t0.uharm_17_overtime>0
        or t0.uharm_18_overtime>0
        or t0.uharm_19_overtime>0
        or t0.uharm_20_overtime>0
        or t0.uharm_21_overtime>0
        or t0.uharm_22_overtime>0
        or t0.uharm_23_overtime>0
        or t0.uharm_24_overtime>0
        or t0.uharm_25_overtime>0
        ) then 1
        else 0
        end isV,
        case
        when (
        t0.iharm_2_overtime>0
        or t0.iharm_3_overtime>0
        or t0.iharm_4_overtime>0
        or t0.iharm_5_overtime>0
        or t0.iharm_6_overtime>0
        or t0.iharm_7_overtime>0
        or t0.iharm_8_overtime>0
        or t0.iharm_9_overtime>0
        or t0.iharm_10_overtime>0
        or t0.iharm_11_overtime>0
        or t0.iharm_12_overtime>0
        or t0.iharm_13_overtime>0
        or t0.iharm_14_overtime>0
        or t0.iharm_15_overtime>0
        or t0.iharm_16_overtime>0
        or t0.iharm_17_overtime>0
        or t0.iharm_18_overtime>0
        or t0.iharm_19_overtime>0
        or t0.iharm_20_overtime>0
        or t0.iharm_21_overtime>0
        or t0.iharm_22_overtime>0
        or t0.iharm_23_overtime>0
        or t0.iharm_24_overtime>0
        or t0.iharm_25_overtime>0
        ) then 1
        else 0
        end isI,
        case
        when t0.flicker_overtime>0 then 1
        else 0
        end isFlicker,
        case
        when (
        t0.inuharm_1_overtime>0
        or t0.inuharm_2_overtime>0
        or t0.inuharm_3_overtime>0
        or t0.inuharm_4_overtime>0
        or t0.inuharm_5_overtime>0
        or t0.inuharm_6_overtime>0
        or t0.inuharm_7_overtime>0
        or t0.inuharm_8_overtime>0
        or t0.inuharm_9_overtime>0
        or t0.inuharm_10_overtime>0
        or t0.inuharm_11_overtime>0
        or t0.inuharm_12_overtime>0
        or t0.inuharm_13_overtime>0
        or t0.inuharm_14_overtime>0
        or t0.inuharm_15_overtime>0
        or t0.inuharm_16_overtime>0
        ) then 1
        else 0
        end isInuharm,
        case
        when t0.uharm_2_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_3_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_4_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_5_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_6_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_7_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_8_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_9_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_10_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_11_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_12_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_13_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_14_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_15_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_16_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_17_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_18_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_19_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_20_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_21_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_22_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_23_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_24_overtime>0 then 1
        else 0
        end +
        case
        when t0.uharm_25_overtime>0 then 1
        else 0
        end vTimes,
        case
        when t0.iharm_2_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_3_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_4_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_5_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_6_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_7_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_8_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_9_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_10_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_11_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_12_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_13_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_14_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_15_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_16_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_17_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_18_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_19_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_20_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_21_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_22_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_23_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_24_overtime>0 then 1
        else 0
        end +
        case
        when t0.iharm_25_overtime>0 then 1
        else 0
        end iTimes,
        case
        when t0.ubalance_overtime>0 then 1
        else 0
        end unbalanceTimes,
        case
        when t0.i_neg_overtime>0 then 1
        else 0
        end iNegTimes
        from
        r_stat_limit_rate_d t0
        left join
        (
        select
        t0.`time` time,
        t0.line_id lineId,
        sum(case when t0.vl_dev&gt;=0 and t0.vl_dev>t1.Voltage_Dev then 1 else 0 end) up,
        sum(case when t0.vl_dev&lt;0 and abs(t0.vl_dev)>abs(t1.Voltage_Dev) then 1 else 0 end) down
        from
        r_stat_data_v_d t0
        left join pq_overlimit t1 on
        t0.line_id = t1.Id
        where
        value_type = 'MAX'
        and phasic_type in ('A', 'B', 'C')
        and `time` = #{time}
        group by
        t0.`time`,
        t0.line_id
        ) t1 on
        t0.time_id = t1.time
        and t0.my_index = t1.lineId
        where
        t0.phasic_type = 'T'
        and t0.time_id = #{time}
        <if test="lineList != null and lineList.size() > 0">
            and t0.my_index in
            <foreach collection="lineList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="getPartSum" resultType="java.util.Map">
        SELECT
        sum(is_harmonic) "isHarmonicCount" ,
        sum(is_freq) "isFreqCount" ,
        sum(is_v_dev) "isVDevCount" ,
        sum(is_v) "isVCount" ,
        sum(is_i) "isICount" ,
        sum(is_unbalance) "isUnbalanceCount" ,
        sum(is_i_neg) "isINegCount"
        FROM
        r_mp_part_harmonic_detail_d
        WHERE
        measurement_point_id in
        <foreach collection="lineIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        AND data_date between #{startTime} and #{endTime}
    </select>

</mapper>
