<?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.alarminfo.mapper.AlarmInfoMapper">
    
    <resultMap type="com.inspect.alarminfo.domain.AlarmInfo" id="AlarmInfoResult">
        <result property="lineId"    column="line_id"    />
        <result property="bayName"    column="bay_name"    />
        <result property="deviceName"    column="device_name"    />
        <result property="pointName"    column="point_name"    />
        <result property="time"    column="time"    />
        <result property="picWidth"    column="pic_width"    />
        <result property="picHeight"    column="pic_height"    />
        <result property="picRaw"    column="pic_raw"    />
        <result property="picDifferent"    column="pic_different"    />
        <result property="picDiffBase"    column="pic_diff_base"    />
    </resultMap>

    <sql id="selectAlarmInfoVo">
        select line_id, bay_name, device_name, point_name, time, pic_width, pic_height, pic_raw, pic_different, pic_diff_base from alarm_info
    </sql>

    <select id="selectAlarmInfoList" parameterType="com.inspect.alarminfo.domain.AlarmInfo" resultMap="AlarmInfoResult">
        <include refid="selectAlarmInfoVo"/>
        <where>  
            <if test="bayName != null  and bayName != ''"> and bay_name like concat('%', #{bayName}, '%')</if>
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="pointName != null  and pointName != ''"> and point_name like concat('%', #{pointName}, '%')</if>
            <if test="time != null "> and time = #{time}</if>
            <if test="picWidth != null "> and pic_width = #{picWidth}</if>
            <if test="picHeight != null  and picHeight != ''"> and pic_height = #{picHeight}</if>
            <if test="picRaw != null  and picRaw != ''"> and pic_raw = #{picRaw}</if>
            <if test="picDifferent != null  and picDifferent != ''"> and pic_different = #{picDifferent}</if>
            <if test="picDiffBase != null  and picDiffBase != ''"> and pic_diff_base = #{picDiffBase}</if>
        </where>
    </select>
    
    <select id="selectAlarmInfoByLineId" parameterType="Long" resultMap="AlarmInfoResult">
        <include refid="selectAlarmInfoVo"/>
        where line_id = #{lineId}
    </select>
        
    <insert id="insertAlarmInfo" parameterType="com.inspect.alarminfo.domain.AlarmInfo" useGeneratedKeys="true" keyProperty="lineId">
        insert into alarm_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bayName != null">bay_name,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="pointName != null">point_name,</if>
            <if test="time != null">time,</if>
            <if test="picWidth != null">pic_width,</if>
            <if test="picHeight != null">pic_height,</if>
            <if test="picRaw != null">pic_raw,</if>
            <if test="picDifferent != null">pic_different,</if>
            <if test="picDiffBase != null">pic_diff_base,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bayName != null">#{bayName},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="pointName != null">#{pointName},</if>
            <if test="time != null">#{time},</if>
            <if test="picWidth != null">#{picWidth},</if>
            <if test="picHeight != null">#{picHeight},</if>
            <if test="picRaw != null">#{picRaw},</if>
            <if test="picDifferent != null">#{picDifferent},</if>
            <if test="picDiffBase != null">#{picDiffBase},</if>
         </trim>
    </insert>

    <update id="updateAlarmInfo" parameterType="com.inspect.alarminfo.domain.AlarmInfo">
        update alarm_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="bayName != null">bay_name = #{bayName},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="pointName != null">point_name = #{pointName},</if>
            <if test="time != null">time = #{time},</if>
            <if test="picWidth != null">pic_width = #{picWidth},</if>
            <if test="picHeight != null">pic_height = #{picHeight},</if>
            <if test="picRaw != null">pic_raw = #{picRaw},</if>
            <if test="picDifferent != null">pic_different = #{picDifferent},</if>
            <if test="picDiffBase != null">pic_diff_base = #{picDiffBase},</if>
        </trim>
        where line_id = #{lineId}
    </update>

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

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