<?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.mapper.data.EventDetailMapper">
    <select id="queryDealFlag" resultType="java.lang.Integer"
            parameterType="java.lang.String">
		select dealflag from pqs_eventdetail where
		eventdetail_index = #{indexEvt}
	</select>

    <update id="updateDealFlag">
		update pqs_eventdetail set dealflag = #{code} where
		eventdetail_index = #{indexEvt}
	</update>

    <update id="updateCause">
		update pqs_eventdetail set eventreason = (select
		a.dic_index from pqs_dicdata a,pqs_dictype b where b.dictype_name =
		'暂降原因' and a.dic_type = b.dictype_index and a.triphase = #{code} and
		a.state = 1 and b.state = 1)
		where
		eventdetail_index = #{indexEvt}
	</update>

    <select id="querySagDescriptionbyId" resultType="java.lang.String">
		select
		a.dic_name from pqs_dicdata a,pqs_dictype b where b.dictype_name =
		#{typename} and a.dic_type = b.dictype_index and a.triphase =#{code}
		and a.state = 1 and b.state = 1
	</select>

    <select id="querySagDescriptionbyIndex" resultType="java.lang.String">
		select
		b.dic_name from pqs_dicdata b,pqs_eventdetail
		a where a.eventreason =
		b.dic_index and a.eventdetail_index =
		#{indexEvt}
	</select>

    <update id="updateSagData">
		update pqs_eventdetail
		set eventtype =(select
		a.dic_index from pqs_dicdata a,pqs_dictype b where b.dictype_name =
		'暂降类型' and a.dic_type = b.dictype_index and a.triphase =
		#{sagEvent.sagType} and a.state = 1 and b.state = 1)
		,dqtime =
		#{sagEvent.dqTime},
		num =
		#{sagEvent.number},firsttime =
		#{sagEvent.firstTime},firstms =
		#{sagEvent.firstMs}
		,firsttype = (select
		a.dic_index from pqs_dicdata
		a,pqs_dictype b where b.dictype_name =
		'暂降类型' and a.dic_type =
		b.dictype_index and a.triphase =
		#{sagEvent.firstType} and a.state = 1 and b.state = 1)
		where
		eventdetail_index =
		#{sagEvent.indexEventDetail}
	</update>

    <select id="queryCountsByReasonAndLineIndexs" resultType="Integer">
        SELECT
        COUNT (1)
        FROM
        pqs_eventdetail
        WHERE
        EventReason=#{eventReason}
        AND
        LineID
        IN
        <foreach collection="list" open="(" close=")" separator=","
                 item="item">
            #{item}
        </foreach>
        AND
        TIMEID
        BETWEEN #{startTime} AND #{endTime}
    </select>

    <select id="queryCountsByTypeAndLineIndexs" resultType="Integer">
        SELECT
        COUNT (1)
        FROM
        pqs_eventdetail
        WHERE
        EventType=#{eventType}
        AND
        LineID
        IN
        <foreach collection="list" open="(" close=")" separator=","
                 item="item">
            #{item}
        </foreach>
        AND
        TIMEID
        BETWEEN #{startTime} AND #{endTime}
    </select>

    <update id="updateSeverity">
        update
          PQS_EVENTDETAIL
        set
          Severity = #{severity}
        where
          EVENTDETAIL_INDEX=#{index}
    </update>

    <select id="getPtType" resultType="java.lang.Integer">
        select b.pttype
        from pqs_eventdetail a, pq_linedetail b
        where a.eventdetail_index = #{eventIndex}
        and a.lineid = b.line_index
    </select>


    <select id="selectByIndex" resultType="eventDetail">
        SELECT
            EVENTDETAIL_INDEX,
            LINEID,
            TIMEID,
            MS,
            WAVETYPE,
            PERSISTTIME,
            EVENTVALUE,
            EVENTREASON,
            EVENTTYPE,
            EVENTASS_INDEX,
            DQTIME,
            DEALTIME,
            NUM,
            FILEFLAG,
            DEALFLAG,
            FIRSTTIME,
            FIRSTTYPE,
            FIRSTMS,
            WAVENAME,
            Energy,
            Severity
        FROM
            PQS_EVENTDETAIL
        WHERE
            EVENTDETAIL_INDEX = #{eventIndex}
    </select>
    <select id="selectByTimeIdAndLineIndex" resultType="eventDetail">
        SELECT
            EVENTDETAIL_INDEX,
            LINEID,
            TIMEID,
            MS,
            WAVETYPE,
            PERSISTTIME,
            EVENTVALUE,
            EVENTREASON,
            EVENTTYPE,
            EVENTASS_INDEX,
            DQTIME,
            DEALTIME,
            NUM,
            FILEFLAG,
            DEALFLAG,
            FIRSTTIME,
            FIRSTTYPE,
            FIRSTMS,
            WAVENAME,
            Energy,
            Severity
        FROM
            PQS_EVENTDETAIL
        WHERE
            TIMEID = #{timeId}
            and
            MS = #{ms}
            and
            lineId =#{lineId}
    </select>
</mapper>