<?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.gyee.wisdom.alarm.sharding.mapper.FaultHisotryMapper">

    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
        insert into faulthistory (id, faulttime, operator, snapid,confirmtype, confirmtime, confirmperson,messagetype,alerttextlast)
        <foreach collection="list" item="item" index="index" separator="union all" >
            ( select
            #{item.id}, #{item.faultTime}, #{item.operator},#{item.snapId},#{item.confirmType},#{item.confirmTime},#{item.confirmPerson},#{item.messageType},#{item.alertTextLast}
            from dual )
        </foreach>
    </insert>



    <select id="queryFaultHistoryById" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.FaultHistory">
        SELECT * FROM faulthistory
        <where>
            id=#{historyid}
        </where>
    </select>

    <update id="faultClear" parameterType="java.util.Map">
        UPDATE faulthistory  SET  CONFIRMTYPE=1   where FAULTTIME > #{startTime} AND FAULTTIME <![CDATA[ <= ]]>#{endTime}
    </update>


    <update id="batchConfirm" parameterType="java.util.Map">
            UPDATE faulthistory  SET  CONFIRMTYPE=#{confirmType} ,CONFIRMPERSON=#{userName},ALERTSNAPID=#{alarmSnpaId},CONFIRMTIME=sysdate  where SNAPID = #{faultSnapId} and CONFIRMTYPE=0 and faultTime>(sysdate - interval '12' hour)
    </update>


    <update id="updateHistoryById" parameterType="com.gyee.wisdom.alarm.sharding.entity.FaultHistory">
        UPDATE
        faulthistory
        SET
            CONFIRMTYPE = #{confirmType} ,
            CONFIRMPERSON = #{confirmPerson} ,
            ALERTSNAPID = #{alertSnapId} ,
            CONFIRMTIME = #{confirmTime}
        WHERE SNAPID = #{snapId}
    </update>

</mapper>
