<?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.majornetwork.EventDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.njcn.event.pojo.po.RmpEventDetailPO">
        <id column="event_id" property="eventId" />
        <result column="measurement_point_id" property="measurementPointId" />
        <result column="event_type" property="eventType" />
        <result column="Event_Reason" property="eventReason" />
        <result column="start_time" property="startTime" />
        <result column="duration" property="duration" />
        <result column="feature_amplitude" property="featureAmplitude" />
        <result column="phase" property="phase" />
        <result column="event_describe" property="eventDescribe" />
        <result column="wave_path" property="wavePath" />
    </resultMap>
    <select id="ListEventType" resultType="com.njcn.event.pojo.vo.GeneralVO">
        SELECT
         id,
        sum(IF(`event_type` =#{condMap.Voltage_Dip}, num, 0)) as sagsCount,
        sum(IF(`event_type` = #{condMap.Short_Interruptions}, num, 0)) as breakCount,
        sum(IF(`event_type` = #{condMap.Voltage_Rise}, num, 0)) as upCount
        from(
            SELECT
            measurement_point_id AS id,
            event_type,
            count(event_id) as num
            FROM
            r_mp_event_detail
            where measurement_point_id in
            <foreach collection="condMap.ids" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
            <if test="condMap.startTime != null and condMap.startTime != ''">
                and start_time &gt;= #{condMap.startTime}
            </if>
            <if test="condMap.endTime != null and condMap.endTime != ''">
                and start_time &lt;= #{condMap.endTime}
            </if>
            GROUP BY
            measurement_point_id,event_type
        ) a
        GROUP BY id
    </select>

</mapper>
