<?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.dcs.hnyz.mapper.AlarmEventMapper">
    
    <resultMap type="AlarmEvent" id="AlarmEventResult">
        <result property="alarmId"    column="alarm_id"    />
        <result property="equipmentId"    column="equipment_id"    />
        <result property="alarmCode"    column="alarm_code"    />
        <result property="alarmLevel"    column="alarm_level"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="message"    column="message"    />
        <result property="value"    column="value"    />
        <result property="unit"    column="unit"    />
        <result property="occurTime"    column="occur_time"    />
        <result property="recoverTime"    column="recover_time"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectAlarmEventVo">
        select alarm_id, equipment_id, alarm_code, alarm_level, alarm_type, message, value, unit, occur_time, recover_time, status, create_time, create_by, update_by, update_time, remark from alarm_event
    </sql>

    <select id="selectAlarmEventList" parameterType="AlarmEvent" resultMap="AlarmEventResult">
        <include refid="selectAlarmEventVo"/>
        <where>  
            <if test="equipmentId != null "> and equipment_id = #{equipmentId}</if>
            <if test="alarmCode != null  and alarmCode != ''"> and alarm_code = #{alarmCode}</if>
            <if test="alarmLevel != null and alarmLevel != ''"> and alarm_level = #{alarmLevel}</if>
            <if test="alarmType != null  and alarmType != ''"> and alarm_type = #{alarmType}</if>
            <if test="message != null  and message != ''"> and message = #{message}</if>
            <if test="value != null  and value != ''"> and value = #{value}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="occurTime != null "> and occur_time = #{occurTime}</if>
            <if test="recoverTime != null "> and recover_time = #{recoverTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAlarmEventByAlarmId" parameterType="Long" resultMap="AlarmEventResult">
        <include refid="selectAlarmEventVo"/>
        where alarm_id = #{alarmId}
    </select>

    <insert id="insertAlarmEvent" parameterType="AlarmEvent" useGeneratedKeys="true" keyProperty="alarmId">
        insert into alarm_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="equipmentId != null">equipment_id,</if>
            <if test="alarmCode != null">alarm_code,</if>
            <if test="alarmLevel != null">alarm_level,</if>
            <if test="alarmType != null">alarm_type,</if>
            <if test="message != null">message,</if>
            <if test="value != null">value,</if>
            <if test="unit != null">unit,</if>
            <if test="occurTime != null">occur_time,</if>
            <if test="recoverTime != null">recover_time,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="equipmentId != null">#{equipmentId},</if>
            <if test="alarmCode != null">#{alarmCode},</if>
            <if test="alarmLevel != null">#{alarmLevel},</if>
            <if test="alarmType != null">#{alarmType},</if>
            <if test="message != null">#{message},</if>
            <if test="value != null">#{value},</if>
            <if test="unit != null">#{unit},</if>
            <if test="occurTime != null">#{occurTime},</if>
            <if test="recoverTime != null">#{recoverTime},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateAlarmEvent" parameterType="AlarmEvent">
        update alarm_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="alarmCode != null">alarm_code = #{alarmCode},</if>
            <if test="alarmLevel != null">alarm_level = #{alarmLevel},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</if>
            <if test="message != null">message = #{message},</if>
            <if test="value != null">value = #{value},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="occurTime != null">occur_time = #{occurTime},</if>
            <if test="recoverTime != null">recover_time = #{recoverTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where alarm_id = #{alarmId}
    </update>

    <delete id="deleteAlarmEventByAlarmId" parameterType="Long">
        delete from alarm_event where alarm_id = #{alarmId}
    </delete>

    <delete id="deleteAlarmEventByAlarmIds" parameterType="String">
        delete from alarm_event where alarm_id in 
        <foreach item="alarmId" collection="array" open="(" separator="," close=")">
            #{alarmId}
        </foreach>
    </delete>
</mapper>