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

    <!--获取配网暂态事件明细-->
    <select id="getPwRmpEventDetail" resultType="com.njcn.event.pojo.po.RmpEventDetailPO">
        SELECT
        event_id AS eventId,
        measurement_point_id AS measurementPointId,
        event_type AS eventType,
        start_time AS startTime,
        duration AS duration,
        feature_amplitude AS featureAmplitude,
        phase AS phase,
        event_describe AS eventDescribe,
        wave_path AS wavePath
        FROM
        r_mp_event_detail
        WHERE
        measurement_point_id IN
        <foreach collection="monitorIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="param.startTime != null and param.startTime != ''">
            AND DATE_FORMAT(start_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{param.startTime}, '%Y-%m-%d')
        </if>
        <if test="param.endTime != null and param.endTime != ''">
            AND DATE_FORMAT(start_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{param.endTime}, '%Y-%m-%d')
        </if>
    </select>

    <select id="getDetailsOfTransientEvents" resultType="com.njcn.event.pojo.po.RmpEventDetailPO">
        SELECT
        event_id as eventId,
        measurement_point_id as measurementPointId,
        Event_Type as eventType,
        start_time as startTime,
        Duration as duration,
        feature_amplitude as featureAmplitude,
        phase as phase,
        event_describe as eventDescribe,
        wave_path as wavePath
        FROM
        r_mp_event_detail
        WHERE
        measurement_point_id IN
        <foreach collection="monitorIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="eventType != null and eventType.size() >0">
            AND Event_Type IN
            <foreach collection="eventType" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="startTime != null and startTime != ''">
            AND DATE_FORMAT(start_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{startTime}, '%Y-%m-%d')
        </if>
        <if test="endTime != null and endTime != ''">
            AND DATE_FORMAT(start_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{endTime}, '%Y-%m-%d')
        </if>
    </select>


    <!--  获取暂态事件明细 与上面的方法区别是日期精确到月 yy-MM -->
    <select id="getDetailsOfTransientEventsByMonth" resultType="com.njcn.event.pojo.po.RmpEventDetailPO">
        SELECT
        event_id as eventId,
        measurement_point_id as measurementPointId,
        Event_Type as eventType,
        start_time as startTime,
        Duration as duration,
        feature_amplitude as featureAmplitude,
        phase as phase,
        event_describe as eventDescribe,
        wave_path as wavePath
        FROM
        r_mp_event_detail
        WHERE
        measurement_point_id IN
        <foreach collection="monitorIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="eventType != null and eventType.size() >0">
            AND Event_Type IN
            <foreach collection="eventType" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <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>
    </select>
    <select id="selectByIdAndValue" resultType="com.njcn.event.pojo.po.EventDetailNew">
        SELECT
            rmed.measurement_point_id AS lineId,
            rmed.start_time AS startTime,
            line.`Name` AS lineName,
            gd.`Name` AS gdName,
            substation.id AS subId,
            substation.`Name` AS subName,
            pqdevice.IP AS ip,
            scale.`Name` AS scale,
            typeDict.name AS advanceType,
            reasonDict.name AS advanceReason,
            rmed.event_type AS eventType,
            rmed.feature_amplitude AS featureAmplitude,
            rmed.duration AS duration,
            rmed.severity AS severity
        FROM r_mp_event_detail rmed
        INNER JOIN pq_line line ON line.id = rmed.measurement_point_id
        INNER JOIN pq_line voltage ON voltage.id = line.pid
        INNER JOIN pq_voltage pqvoltage ON voltage.id = pqvoltage.id
        INNER JOIN sys_dict_data scale ON pqvoltage.Scale = scale.id
        INNER JOIN pq_line device ON device.id = voltage.pid
        INNER JOIN pq_device pqdevice ON pqdevice.id = device.id
        INNER JOIN pq_line substation ON substation.id = device.pid
        INNER JOIN pq_line gd ON substation.pid = gd.id
        INNER JOIN sys_dict_data reasonDict ON reasonDict.id = rmed.advance_reason
        INNER JOIN sys_dict_data typeDict ON typeDict.id = rmed.advance_type
        WHERE
            rmed.measurement_point_id IN
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="beginTime != null">
            AND DATE_FORMAT(rmed.start_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{beginTime}, '%Y-%m-%d')
        </if>
        <if test="endTime != null">
            AND DATE_FORMAT(rmed.start_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{endTime}, '%Y-%m-%d')
        </if>
        <if test="waveType!=null and waveType.size()>0">
            AND rmed.event_type IN
            <foreach collection="waveType" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="eventReason!=null and eventReason.size()>0">
            AND rmed.advance_reason IN
            <foreach collection="eventReason" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="eventType!=null  and eventType.size()>0">
            AND rmed.advance_type IN
            <foreach collection="eventType" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="eventValueMin != null and eventValueMin != ''">
            AND rmed.feature_amplitude <![CDATA[>=]]> #{eventValueMin}
        </if>
        <if test="eventValueMax != null and eventValueMax != ''">
            AND rmed.feature_amplitude <![CDATA[<=]]> #{eventValueMax}
        </if>
        <if test="persistMin != null and persistMin != ''">
            AND rmed.duration <![CDATA[>=]]> #{persistMin}
        </if>
        <if test="persistMax != null and persistMax != ''">
            AND rmed.duration <![CDATA[<=]]> #{persistMax}
        </if>
        <if test="severityMin != null and severityMin != ''">
            AND rmed.severity <![CDATA[>=]]> #{severityMin}
        </if>
        <if test="severityMax != null and severityMax != ''">
            AND rmed.severity <![CDATA[<=]]> #{severityMax}
        </if>
        <if test="fileFlag != null and fileFlag != ''">
            AND rmed.file_flag = #{fileFlag}
        </if>
        <if test="searchValue!=null and searchValue!=''">
            and (
            line.name like  CONCAT('%', #{searchValue},'%')
            or voltage.name like  CONCAT('%', #{searchValue},'%')
            or substation.name like  CONCAT('%', #{searchValue},'%')
            or gd.name like  CONCAT('%', #{searchValue},'%')
            or pqdevice.IP like CONCAT('%', #{searchValue},'%')
            )
        </if>
        ORDER BY rmed.start_time DESC
    </select>
</mapper>