<?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.ruoyi.ems.mapper.AlarmHandleMapper">

    <resultMap type="com.ruoyi.ems.domain.AlarmHandle" id="AlarmHandleResult">
        <id property="id" column="id"/>
        <result property="alarmId" column="alarm_id"/>
        <result property="handleType" column="handle_type"/>
        <result property="handleContent" column="handle_content"/>
        <result property="handleResult" column="handle_result"/>
        <result property="handleBy" column="handle_by"/>
        <result property="handleTime" column="handle_time"/>
        <result property="attachments" column="attachments"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <select id="selectById" parameterType="Long" resultMap="AlarmHandleResult">
        SELECT id, alarm_id, handle_type, handle_content, handle_result,
               handle_by, handle_time, attachments, create_time
        FROM adm_op_alarm_handle
        WHERE id = #{id}
    </select>

    <select id="selectByAlarmId" parameterType="String" resultMap="AlarmHandleResult">
        SELECT id, alarm_id, handle_type, handle_content, handle_result,
               handle_by, handle_time, attachments, create_time
        FROM adm_op_alarm_handle
        WHERE alarm_id = #{alarmId}
        ORDER BY handle_time ASC
    </select>

    <insert id="insert" parameterType="com.ruoyi.ems.domain.AlarmHandle" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO adm_op_alarm_handle (
            alarm_id, handle_type, handle_content, handle_result,
            handle_by, handle_time, attachments, create_time
        ) VALUES (
                     #{alarmId}, #{handleType}, #{handleContent}, #{handleResult},
                     #{handleBy}, #{handleTime}, #{attachments}, NOW()
                 )
    </insert>

    <delete id="deleteByAlarmId" parameterType="String">
        DELETE FROM adm_op_alarm_handle WHERE alarm_id = #{alarmId}
    </delete>
</mapper>