<?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.patrol.mapper.PatrolPresetRecordMapper">
    
    <resultMap type="PatrolPresetRecord" id="PatrolPresetRecordResult">
        <result property="presetRecordId"    column="preset_record_id"    />
        <result property="presetPosCode"    column="preset_pos_code"    />
        <result property="presetPosName"    column="preset_pos_name"    />
        <result property="channelId"    column="channel_id"    />
        <result property="channelCode"    column="channel_code"    />
        <result property="channelType"    column="channel_type"    />
        <result property="description"    column="description"    />
        <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="videoNvrCode"    column="video_nvr_code"    />
        <result property="eqpBookId"    column="eqp_book_id"    />
        <result property="patrolDeviceCode"    column="patrol_device_code"    />
    </resultMap>

    <sql id="selectPatrolPresetRecordVo">
        select preset_record_id, preset_pos_code, preset_pos_name, channel_id, channel_code, channel_type, description, create_by, create_time, update_by, update_time, video_nvr_code, eqp_book_id, patrol_device_code from patrol_preset_record
    </sql>

    <select id="selectPatrolPresetRecordList" parameterType="PatrolPresetRecord" resultMap="PatrolPresetRecordResult">
        <include refid="selectPatrolPresetRecordVo"/>
        <where>  
            <if test="presetPosCode != null  and presetPosCode != ''"> and preset_pos_code = #{presetPosCode}</if>
            <if test="presetPosName != null  and presetPosName != ''"> and preset_pos_name like concat('%', #{presetPosName}, '%')</if>
            <if test="channelId != null "> and channel_id = #{channelId}</if>
            <if test="channelCode != null  and channelCode != ''"> and channel_code = #{channelCode}</if>
            <if test="channelType != null  and channelType != ''"> and channel_type = #{channelType}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="videoNvrCode != null  and videoNvrCode != ''"> and video_nvr_code = #{videoNvrCode}</if>
            <if test="eqpBookId != null "> and eqp_book_id = #{eqpBookId}</if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''"> and patrol_device_code = #{patrolDeviceCode}</if>
        </where>
    </select>
    
    <select id="selectPatrolPresetRecordByPresetRecordId" parameterType="Long" resultMap="PatrolPresetRecordResult">
        <include refid="selectPatrolPresetRecordVo"/>
        where preset_record_id = #{presetRecordId}
    </select>
        
    <insert id="insertPatrolPresetRecord" parameterType="PatrolPresetRecord" useGeneratedKeys="true" keyProperty="presetRecordId">
        insert into patrol_preset_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="presetPosCode != null and presetPosCode != ''">preset_pos_code,</if>
            <if test="presetPosName != null">preset_pos_name,</if>
            <if test="channelId != null">channel_id,</if>
            <if test="channelCode != null">channel_code,</if>
            <if test="channelType != null">channel_type,</if>
            <if test="description != null">description,</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="videoNvrCode != null">video_nvr_code,</if>
            <if test="eqpBookId != null">eqp_book_id,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="presetPosCode != null and presetPosCode != ''">#{presetPosCode},</if>
            <if test="presetPosName != null">#{presetPosName},</if>
            <if test="channelId != null">#{channelId},</if>
            <if test="channelCode != null">#{channelCode},</if>
            <if test="channelType != null">#{channelType},</if>
            <if test="description != null">#{description},</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="videoNvrCode != null">#{videoNvrCode},</if>
            <if test="eqpBookId != null">#{eqpBookId},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
         </trim>
    </insert>

    <update id="updatePatrolPresetRecord" parameterType="PatrolPresetRecord">
        update patrol_preset_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="presetPosCode != null and presetPosCode != ''">preset_pos_code = #{presetPosCode},</if>
            <if test="presetPosName != null">preset_pos_name = #{presetPosName},</if>
            <if test="channelId != null">channel_id = #{channelId},</if>
            <if test="channelCode != null">channel_code = #{channelCode},</if>
            <if test="channelType != null">channel_type = #{channelType},</if>
            <if test="description != null">description = #{description},</if>
            <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="videoNvrCode != null">video_nvr_code = #{videoNvrCode},</if>
            <if test="eqpBookId != null">eqp_book_id = #{eqpBookId},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
        </trim>
        where preset_record_id = #{presetRecordId}
    </update>

    <delete id="deletePatrolPresetRecordByPresetRecordId" parameterType="Long">
        delete from patrol_preset_record where preset_record_id = #{presetRecordId}
    </delete>

    <delete id="deletePatrolPresetRecordByPresetRecordIds" parameterType="String">
        delete from patrol_preset_record where preset_record_id in 
        <foreach item="presetRecordId" collection="array" open="(" separator="," close=")">
            #{presetRecordId}
        </foreach>
    </delete>
</mapper>