<?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.RMpSurplusHarmonicDetailDMapper">

    <select id="getSurplusSumByData" resultType="com.njcn.harmonic.pojo.po.RMpSurplusHarmonicDetailM">
        SELECT
            measurement_point_id,
            sum( is_inuharm ) inuharm_over_day,
            sum( is_flicker ) flicker_over_day,
            sum( is_inuharm_1 ) inuharm_1_over_day,
            sum( is_inuharm_2 ) inuharm_2_over_day,
            sum( is_inuharm_3 ) inuharm_3_over_day,
            sum( is_inuharm_4 ) inuharm_4_over_day,
            sum( is_inuharm_5 ) inuharm_5_over_day,
            sum( is_inuharm_6 ) inuharm_6_over_day,
            sum( is_inuharm_7 ) inuharm_7_over_day,
            sum( is_inuharm_8 ) inuharm_8_over_day,
            sum( is_inuharm_9 ) inuharm_9_over_day,
            sum( is_inuharm_10 ) inuharm_10_over_day,
            sum( is_inuharm_11 ) inuharm_11_over_day,
            sum( is_inuharm_12 ) inuharm_12_over_day,
            sum( is_inuharm_13 ) inuharm_13_over_day,
            sum( is_inuharm_14 ) inuharm_14_over_day,
            sum( is_inuharm_15 ) inuharm_15_over_day,
            sum( is_inuharm_16 ) inuharm_16_over_day
        FROM
            `r_mp_surplus_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="getHarmonicDetailDayTwo" resultType="com.njcn.harmonic.pojo.po.RMpSurplusHarmonicDetailD">
        select
        t0.time_id dataDate,
        t0.my_index measurementPointId,
        case
            when t0.flicker_overtime>0 then 1
            else 0
        end isFlicker,
        t0.flicker_overtime flickerTimes,
        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.inuharm_1_overtime>0 then 1
            else 0
        end isInuharm1,
        case
            when t0.inuharm_2_overtime>0 then 1
            else 0
        end isInuharm2,
        case
            when t0.inuharm_3_overtime>0 then 1
            else 0
        end isInuharm3,
        case
            when t0.inuharm_4_overtime>0 then 1
            else 0
        end isInuharm4,
        case
            when t0.inuharm_5_overtime>0 then 1
            else 0
        end isInuharm5,
        case
            when t0.inuharm_6_overtime>0 then 1
            else 0
        end isInuharm6,
        case
            when t0.inuharm_7_overtime>0 then 1
            else 0
        end isInuharm7,
        case
            when t0.inuharm_8_overtime>0 then 1
            else 0
        end isInuharm8,
        case
            when t0.inuharm_9_overtime>0 then 1
            else 0
        end isInuharm9,
        case
            when t0.inuharm_10_overtime>0 then 1
            else 0
        end isInuharm10,
        case
            when t0.inuharm_11_overtime>0 then 1
            else 0
        end isInuharm11,
        case
            when t0.inuharm_12_overtime>0 then 1
            else 0
        end isInuharm12,
        case
            when t0.inuharm_13_overtime>0 then 1
            else 0
        end isInuharm13,
        case
            when t0.inuharm_14_overtime>0 then 1
            else 0
        end isInuharm14,
        case
            when t0.inuharm_15_overtime>0 then 1
            else 0
        end isInuharm15,
        case
            when t0.inuharm_16_overtime>0 then 1
            else 0
        end isInuharm16,
        case
        when t0.inuharm_1_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_2_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_3_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_4_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_5_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_6_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_7_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_8_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_9_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_10_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_11_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_12_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_13_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_14_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_15_overtime>0 then 1
        else 0
        end +
        case
        when t0.inuharm_16_overtime>0 then 1
        else 0
        end inuharmTimes
    from
        r_stat_limit_rate_d t0
    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="getSurplusSum" resultType="java.util.Map">
        SELECT
            sum( is_flicker ) "isFlickerCount",
            sum( is_inuharm ) "isInuharmCount"
        FROM
            r_mp_surplus_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>
