<?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.gather.event.eventlist.mapper.EventListMapper">

    <sql id="EventDetailColumns">
        event_id,
        measurement_point_id,
        start_time,
        event_type,
        advance_reason,
        advance_type,
        feature_amplitude,
        duration,
        eventass_index,
        dq_time,
        deal_time,
        num,
        file_flag,
        deal_flag,
        first_time,
        first_type,
        first_ms,
        energy,
        severity,
        sagsource,
        phase,
        event_describe,
        wave_path,
        create_time,
        transient_value,
        verify_reason,
        verify_reason_detail
    </sql>

    <sql id="TransientWhere">
        <where>
            <if test="param.startTimeStart != null and param.startTimeStart != ''">
                AND start_time &gt;= #{param.startTimeStart}
            </if>
            <if test="param.startTimeEnd != null and param.startTimeEnd != ''">
                AND start_time &lt;= #{param.startTimeEnd}
            </if>
            <if test="param.eventType != null and param.eventType != ''">
                AND event_type = #{param.eventType}
            </if>
            <if test="param.phase != null and param.phase != ''">
                AND phase = #{param.phase}
            </if>
            <if test="param.durationMin != null">
                AND duration &gt;= #{param.durationMin}
            </if>
            <if test="param.durationMax != null">
                AND duration &lt;= #{param.durationMax}
            </if>
            <if test="param.featureAmplitudeMin != null">
                AND feature_amplitude &gt;= #{param.featureAmplitudeMin}
            </if>
            <if test="param.featureAmplitudeMax != null">
                AND feature_amplitude &lt;= #{param.featureAmplitudeMax}
            </if>
            <if test="param.fileFlag != null">
                AND file_flag = #{param.fileFlag}
            </if>
            <if test="param.dealFlag != null">
                AND deal_flag = #{param.dealFlag}
            </if>
            <if test="param.lineIds != null and param.lineIds.size() &gt; 0">
                AND measurement_point_id IN
                <foreach collection="param.lineIds" item="lineId" open="(" separator="," close=")">
                    #{lineId}
                </foreach>
            </if>
        </where>
    </sql>

    <select id="selectTransientPage" resultType="com.njcn.gather.event.eventlist.pojo.po.MpEventDetailPO">
        SELECT
        <include refid="EventDetailColumns"/>
        FROM r_mp_event_detail
        <include refid="TransientWhere"/>
        ORDER BY start_time DESC, event_id DESC
    </select>

    <select id="selectTransientExportList" resultType="com.njcn.gather.event.eventlist.pojo.po.MpEventDetailPO">
        SELECT
        <include refid="EventDetailColumns"/>
        FROM r_mp_event_detail
        <include refid="TransientWhere"/>
        ORDER BY start_time DESC, event_id DESC
        LIMIT #{limit}
    </select>

    <select id="selectTransientDetail" resultType="com.njcn.gather.event.eventlist.pojo.po.MpEventDetailPO">
        SELECT
        <include refid="EventDetailColumns"/>
        FROM r_mp_event_detail
        WHERE event_id = #{eventId}
        LIMIT 1
    </select>

    <select id="selectTransientDetailsByIds" resultType="com.njcn.gather.event.eventlist.pojo.po.MpEventDetailPO">
        SELECT
        <include refid="EventDetailColumns"/>
        FROM r_mp_event_detail
        WHERE event_id IN
        <foreach collection="eventIds" item="eventId" open="(" separator="," close=")">
            #{eventId}
        </foreach>
    </select>
</mapper>
