<?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.alarmdefect.mapper.AlarmDefectMapper">
    
    <resultMap type="com.inspect.alarmdefect.domain.AlarmDefect" id="AlarmDefectResult">
        <result property="lineId"    column="line_id"    />
        <result property="alarmId"    column="alarm_id"    />
        <result property="type"    column="type"    />
        <result property="x1"    column="x1"    />
        <result property="y1"    column="y1"    />
        <result property="x2"    column="x2"    />
        <result property="y2"    column="y2"    />
        <result property="confidence"    column="confidence"    />
        <result property="desc"    column="desc"    />
    </resultMap>

    <sql id="selectAlarmDefectVo">
        select line_id, alarm_id, type, x1, y1, x2, y2, confidence, desc from alarm_defect
    </sql>

    <select id="selectAlarmDefectList" parameterType="com.inspect.alarmdefect.domain.AlarmDefect" resultMap="AlarmDefectResult">
        <include refid="selectAlarmDefectVo"/>
        <where>  
            <if test="alarmId != null  and alarmId != ''"> and alarm_id = #{alarmId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</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>
            <if test="confidence != null  and confidence != ''"> and confidence = #{confidence}</if>
            <if test="desc != null  and desc != ''"> and desc = #{desc}</if>
        </where>
    </select>
    
    <select id="selectAlarmDefectByLineId" parameterType="Long" resultMap="AlarmDefectResult">
        <include refid="selectAlarmDefectVo"/>
        where line_id = #{lineId}
    </select>
        
    <insert id="insertAlarmDefect" parameterType="com.inspect.alarmdefect.domain.AlarmDefect" useGeneratedKeys="true" keyProperty="lineId">
        insert into alarm_defect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="alarmId != null">alarm_id,</if>
            <if test="type != null">type,</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>
            <if test="confidence != null">confidence,</if>
            <if test="desc != null">desc,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="alarmId != null">#{alarmId},</if>
            <if test="type != null">#{type},</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>
            <if test="confidence != null">#{confidence},</if>
            <if test="desc != null">#{desc},</if>
         </trim>
    </insert>

    <update id="updateAlarmDefect" parameterType="com.inspect.alarmdefect.domain.AlarmDefect">
        update alarm_defect
        <trim prefix="SET" suffixOverrides=",">
            <if test="alarmId != null">alarm_id = #{alarmId},</if>
            <if test="type != null">type = #{type},</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>
            <if test="confidence != null">confidence = #{confidence},</if>
            <if test="desc != null">desc = #{desc},</if>
        </trim>
        where line_id = #{lineId}
    </update>

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

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