<?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.cmvr.aima.mapper.AimaAlarmMapper">
    <resultMap type="AimaAlarm" id="AimaAlarmResult">
        <result property="id" column="id"/><result property="createBy" column="create_by"/><result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/><result property="updateTime" column="update_time"/><result property="remark" column="remark"/>
        <result property="alarmCode" column="alarm_code"/><result property="taskInstanceId" column="task_instance_id"/><result property="taskId" column="task_id"/>
        <result property="taskName" column="task_name"/><result property="phoneId" column="phone_id"/><result property="phoneName" column="phone_name"/>
        <result property="vehicleId" column="vehicle_id"/><result property="vin" column="vin"/><result property="testCaseId" column="test_case_id"/>
        <result property="caseName" column="case_name"/><result property="alarmLevel" column="alarm_level"/><result property="alarmType" column="alarm_type"/>
        <result property="alarmTitle" column="alarm_title"/><result property="alarmContent" column="alarm_content"/><result property="alarmLocation" column="alarm_location"/>
        <result property="alarmTime" column="alarm_time"/><result property="handleStatus" column="handle_status"/><result property="handler" column="handler"/>
        <result property="handleTime" column="handle_time"/><result property="handleRemark" column="handle_remark"/><result property="evidenceImage" column="evidence_image"/>
    </resultMap>

    <sql id="selectAimaAlarmVo">
        select id, create_by, create_time, update_by, update_time, remark, alarm_code, task_instance_id, task_id, task_name, phone_id, phone_name, vehicle_id, vin, test_case_id, case_name, alarm_level, alarm_type, alarm_title, alarm_content, alarm_location, alarm_time, handle_status, handler, handle_time, handle_remark, evidence_image from aima_alarm
    </sql>

    <select id="selectAimaAlarmList" parameterType="AimaAlarm" resultMap="AimaAlarmResult">
        <include refid="selectAimaAlarmVo"/>
        <where>
            <if test="alarmCode != null and alarmCode != ''"> and alarm_code = #{alarmCode}</if>
            <if test="taskInstanceId != null and taskInstanceId != ''"> and task_instance_id = #{taskInstanceId}</if>
            <if test="taskId != null and taskId != ''"> and task_id = #{taskId}</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="handleStatus != null and handleStatus != ''"> and handle_status = #{handleStatus}</if>
        </where>
        order by alarm_time desc
    </select>

    <select id="selectAimaAlarmById" parameterType="String" resultMap="AimaAlarmResult">
        <include refid="selectAimaAlarmVo"/> where id = #{id}
    </select>

    <insert id="insertAimaAlarm" parameterType="AimaAlarm">
        insert into aima_alarm <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if><if test="createBy != null">create_by,</if><if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if><if test="updateTime != null">update_time,</if><if test="remark != null">remark,</if>
            <if test="alarmCode != null">alarm_code,</if><if test="taskInstanceId != null">task_instance_id,</if><if test="taskId != null">task_id,</if>
            <if test="taskName != null">task_name,</if><if test="phoneId != null">phone_id,</if><if test="phoneName != null">phone_name,</if>
            <if test="vehicleId != null">vehicle_id,</if><if test="vin != null">vin,</if><if test="testCaseId != null">test_case_id,</if>
            <if test="caseName != null">case_name,</if><if test="alarmLevel != null">alarm_level,</if><if test="alarmType != null">alarm_type,</if>
            <if test="alarmTitle != null">alarm_title,</if><if test="alarmContent != null">alarm_content,</if><if test="alarmLocation != null">alarm_location,</if>
            <if test="alarmTime != null">alarm_time,</if><if test="handleStatus != null">handle_status,</if><if test="handler != null">handler,</if>
            <if test="handleTime != null">handle_time,</if><if test="handleRemark != null">handle_remark,</if><if test="evidenceImage != null">evidence_image,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if><if test="createBy != null">#{createBy},</if><if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if><if test="updateTime != null">#{updateTime},</if><if test="remark != null">#{remark},</if>
            <if test="alarmCode != null">#{alarmCode},</if><if test="taskInstanceId != null">#{taskInstanceId},</if><if test="taskId != null">#{taskId},</if>
            <if test="taskName != null">#{taskName},</if><if test="phoneId != null">#{phoneId},</if><if test="phoneName != null">#{phoneName},</if>
            <if test="vehicleId != null">#{vehicleId},</if><if test="vin != null">#{vin},</if><if test="testCaseId != null">#{testCaseId},</if>
            <if test="caseName != null">#{caseName},</if><if test="alarmLevel != null">#{alarmLevel},</if><if test="alarmType != null">#{alarmType},</if>
            <if test="alarmTitle != null">#{alarmTitle},</if><if test="alarmContent != null">#{alarmContent},</if><if test="alarmLocation != null">#{alarmLocation},</if>
            <if test="alarmTime != null">#{alarmTime},</if><if test="handleStatus != null">#{handleStatus},</if><if test="handler != null">#{handler},</if>
            <if test="handleTime != null">#{handleTime},</if><if test="handleRemark != null">#{handleRemark},</if><if test="evidenceImage != null">#{evidenceImage},</if>
        </trim>
    </insert>

    <update id="updateAimaAlarm" parameterType="AimaAlarm">
        update aima_alarm <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if><if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if><if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if><if test="alarmCode != null">alarm_code = #{alarmCode},</if>
            <if test="taskInstanceId != null">task_instance_id = #{taskInstanceId},</if><if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskName != null">task_name = #{taskName},</if><if test="phoneId != null">phone_id = #{phoneId},</if>
            <if test="phoneName != null">phone_name = #{phoneName},</if><if test="vehicleId != null">vehicle_id = #{vehicleId},</if>
            <if test="vin != null">vin = #{vin},</if><if test="testCaseId != null">test_case_id = #{testCaseId},</if>
            <if test="caseName != null">case_name = #{caseName},</if><if test="alarmLevel != null">alarm_level = #{alarmLevel},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</if><if test="alarmTitle != null">alarm_title = #{alarmTitle},</if>
            <if test="alarmContent != null">alarm_content = #{alarmContent},</if><if test="alarmLocation != null">alarm_location = #{alarmLocation},</if>
            <if test="alarmTime != null">alarm_time = #{alarmTime},</if><if test="handleStatus != null">handle_status = #{handleStatus},</if>
            <if test="handler != null">handler = #{handler},</if><if test="handleTime != null">handle_time = #{handleTime},</if>
            <if test="handleRemark != null">handle_remark = #{handleRemark},</if><if test="evidenceImage != null">evidence_image = #{evidenceImage},</if>
        </trim> where id = #{id}
    </update>

    <delete id="deleteAimaAlarmById" parameterType="String">delete from aima_alarm where id = #{id}</delete>
    <delete id="deleteAimaAlarmByIds" parameterType="String">
        delete from aima_alarm where id in <foreach item="id" collection="array" open="(" separator="," close=")">#{id}</foreach>
    </delete>
</mapper>
