<?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.inspect.alarmdifferent.mapper.AlarmDifferentMapper">
    
    <resultMap type="com.inspect.alarmdifferent.domain.AlarmDifferent" id="AlarmDifferentResult">
        <result property="lineId"    column="line_id"    />
        <result property="alarmId"    column="alarm_id"    />
        <result property="x1"    column="x1"    />
        <result property="y1"    column="y1"    />
        <result property="x2"    column="x2"    />
        <result property="y2"    column="y2"    />
    </resultMap>

    <sql id="selectAlarmDifferentVo">
        select line_id, alarm_id, x1, y1, x2, y2 from alarm_different
    </sql>

    <select id="selectAlarmDifferentList" parameterType="com.inspect.alarmdifferent.domain.AlarmDifferent" resultMap="AlarmDifferentResult">
        <include refid="selectAlarmDifferentVo"/>
        <where>  
            <if test="alarmId != null  and alarmId != ''"> and alarm_id = #{alarmId}</if>
            <if test="x1 != null  and x1 != ''"> and x1 = #{x1}</if>
            <if test="y1 != null  and y1 != ''"> and y1 = #{y1}</if>
            <if test="x2 != null  and x2 != ''"> and x2 = #{x2}</if>
            <if test="y2 != null  and y2 != ''"> and y2 = #{y2}</if>
        </where>
    </select>
    
    <select id="selectAlarmDifferentByLineId" parameterType="Long" resultMap="AlarmDifferentResult">
        <include refid="selectAlarmDifferentVo"/>
        where line_id = #{lineId}
    </select>
        
    <insert id="insertAlarmDifferent" parameterType="com.inspect.alarmdifferent.domain.AlarmDifferent">
        insert into alarm_different
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lineId != null">line_id,</if>
            <if test="alarmId != null">alarm_id,</if>
            <if test="x1 != null">x1,</if>
            <if test="y1 != null">y1,</if>
            <if test="x2 != null">x2,</if>
            <if test="y2 != null">y2,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lineId != null">#{lineId},</if>
            <if test="alarmId != null">#{alarmId},</if>
            <if test="x1 != null">#{x1},</if>
            <if test="y1 != null">#{y1},</if>
            <if test="x2 != null">#{x2},</if>
            <if test="y2 != null">#{y2},</if>
         </trim>
    </insert>

    <update id="updateAlarmDifferent" parameterType="com.inspect.alarmdifferent.domain.AlarmDifferent">
        update alarm_different
        <trim prefix="SET" suffixOverrides=",">
            <if test="alarmId != null">alarm_id = #{alarmId},</if>
            <if test="x1 != null">x1 = #{x1},</if>
            <if test="y1 != null">y1 = #{y1},</if>
            <if test="x2 != null">x2 = #{x2},</if>
            <if test="y2 != null">y2 = #{y2},</if>
        </trim>
        where line_id = #{lineId}
    </update>

    <delete id="deleteAlarmDifferentByLineId" parameterType="Long">
        delete from alarm_different where line_id = #{lineId}
    </delete>

    <delete id="deleteAlarmDifferentByLineIds" parameterType="String">
        delete from alarm_different where line_id in 
        <foreach item="lineId" collection="array" open="(" separator="," close=")">
            #{lineId}
        </foreach>
    </delete>
</mapper>