<?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.event.mapper.distribution.PwEventDistributionStatisticsMapper">



    <!--获取监测点暂态事件明细数据-->
    <select id="getRmpEventDetail" resultType="com.njcn.event.pojo.po.RmpEventDetailPO">
        SELECT
            measurement_point_id as measurementPointId,
            start_time AS startTime,
            duration AS duration,
            feature_amplitude AS featureAmplitude
        FROM
            `r_mp_event_detail`
    </select>

    <!--获取监测点电压暂降和短时中断分布情况-->
    <select id="getEventDipShortDistributionByCond"
            resultType="com.njcn.event.pojo.vo.EventDipShortDistributionVO">
        SELECT
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 80 AND r.feature_amplitude &lt;= 90 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp90with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 70 AND r.feature_amplitude &lt; 80 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp80with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 60 AND r.feature_amplitude &lt; 70 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp70with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 50 AND r.feature_amplitude &lt; 60 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp60with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 40 AND r.feature_amplitude &lt; 50 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp50with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 30 AND r.feature_amplitude &lt; 40 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp40with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 20 AND r.feature_amplitude &lt; 30 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp30with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 10 AND r.feature_amplitude &lt; 20 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp20with60000ms",

        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 10 AND
        duration &lt;= 100 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with100ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 100 AND
        duration &lt;= 250 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with250ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 250 AND
        duration &lt;= 500 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with500ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 500 AND
        duration &lt;= 1000 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with1000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 1000 AND
        duration &lt;= 3000 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with3000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 3000 AND
        duration &lt;= 10000 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with10000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 10000 AND
        duration &lt;= 20000 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with20000ms",
        COALESCE( sum( CASE WHEN r.feature_amplitude &gt;= 0 AND r.feature_amplitude &lt; 10 AND duration &gt; 20000 AND
        duration &lt;= 60000 THEN 1 ELSE 0 END ), 0 ) "featureAmp10with60000ms"

        FROM
        (
        SELECT
        duration,
        feature_amplitude
        FROM
        r_mp_event_detail
        WHERE 1 = 1
        AND measurement_point_id IN
        <foreach collection="monitorIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>

        AND event_type IN
        <foreach collection="eventTypeList" item="type" open="(" close=")" separator=",">
            #{type}
        </foreach>

        <choose>
            <when test="dateType != null and dateType == 3">
                <if test="startTime != null and startTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m') &gt;= #{startTime}
                </if>
                <if test="endTime != null and endTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m') &lt;= #{endTime}
                </if>
            </when>
            <when test="dateType != null and dateType == 5">
                <if test="startTime != null and startTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m-%d') &gt;= #{startTime}
                </if>
                <if test="endTime != null and endTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m-%d') &lt;= #{endTime}
                </if>
            </when>
        </choose>
        )
        r
    </select>

    <!--获取监测点电压暂升分布情况-->
    <select id="getEventRiseDistributionByCond" resultType="com.njcn.event.pojo.vo.EventRiseDistributionVO">
        SELECT
        COALESCE(sum(CASE WHEN r.feature_amplitude &gt;= 120 AND duration &gt; 10 AND duration &lt;= 500 THEN 1 ELSE 0 END), 0) "featureAmp120with500ms",
        COALESCE(sum(CASE WHEN r.feature_amplitude &gt;= 120 AND duration &gt; 500 AND duration &lt;= 5000 THEN 1 ELSE 0 END), 0) "featureAmp120with5000ms",
        COALESCE(sum(CASE WHEN r.feature_amplitude &gt;= 120 AND duration &gt; 5000 AND duration &lt;= 60000 THEN 1 ELSE 0 END), 0) "featureAmp120with60000ms",

        COALESCE(sum(CASE WHEN r.feature_amplitude &gt;= -120 AND r.feature_amplitude &lt;= 110 AND duration &gt; 10 AND duration &lt;= 500 THEN 1 ELSE 0 END), 0) "featureAmp110with500ms",
        COALESCE(sum(CASE WHEN r.feature_amplitude &gt;= -120 AND r.feature_amplitude &lt;= 110 AND duration &gt; 500 AND duration &lt;= 5000 THEN 1 ELSE 0 END), 0) "featureAmp110with5000ms",
        COALESCE(sum(CASE WHEN r.feature_amplitude &gt;= -120 AND r.feature_amplitude &lt;= 110 AND duration &gt; 5000 AND duration &lt;= 60000 THEN 1 ELSE 0 END), 0) "featureAmp110with60000ms"

        FROM
        (
        SELECT
        duration,
        feature_amplitude
        FROM
        r_mp_event_detail
        WHERE 1 = 1
        AND measurement_point_id IN
        <foreach collection="monitorIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>

        AND event_type IN
        <foreach collection="eventTypeList" item="type" open="(" close=")" separator=",">
            #{type}
        </foreach>

        <choose>
            <when test="dateType != null and dateType == 3">
                <if test="startTime != null and startTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m') &gt;= #{startTime}
                </if>
                <if test="endTime != null and endTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m') &lt;= #{endTime}
                </if>
            </when>
            <when test="dateType != null and dateType == 5">
                <if test="startTime != null and startTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m-%d') &gt;= #{startTime}
                </if>
                <if test="endTime != null and endTime != ''">
                    AND DATE_FORMAT(start_time, '%Y-%m-%d') &lt;= #{endTime}
                </if>
            </when>
        </choose>
        )
        r
    </select>
</mapper>