<?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.metadata.patrolpointmnt.mapper.BasedataPatrolPointPresetMapper">
    <resultMap type="BasedataPatrolPointPreset" id="BasedataPatrolPointPresetResult">
        <result property="patrolPointPresetId" column="patrol_point_preset_id"/>
        <result property="patrolPointId" column="patrol_point_id"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="channelId" column="channel_id"/>
        <result property="presetCode" column="preset_code"/>
        <result property="presetName" column="preset_name"/>
        <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="deleteFlag" column="delete_flag"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="channelCode" column="channel_code"/>
        <result property="videoNvrCode" column="video_nvr_code"/>
    </resultMap>

    <sql id="selectBasedataPatrolPointPresetVo">
        select patrol_point_preset_id,
               patrol_point_id,
               eqp_book_id,
               channel_id,
               preset_code,
               preset_name,
               create_by,
               create_time,
               update_by,
               update_time,
               delete_flag,
               patrol_device_code,
               channel_code,
               video_nvr_code
        from basedata_patrolpoint_preset
    </sql>

    <select id="selectBasedataPatrolPointPresetList" parameterType="BasedataPatrolPointPreset"
            resultMap="BasedataPatrolPointPresetResult">
        <include refid="selectBasedataPatrolPointPresetVo"/>
        <where>
            <if test="patrolPointId != null ">and patrol_point_id = #{patrolPointId}</if>
            <if test="eqpBookId != null ">and eqp_book_id = #{eqpBookId}</if>
            <if test="channelId != null ">and channel_id = #{channelId}</if>
            <if test="presetCode != null  and presetCode != ''">and preset_code = #{presetCode}</if>
            <if test="presetName != null  and presetName != ''">and preset_name like concat('%', #{presetName}, '%')
            </if>
            <if test="deleteFlag != null  and deleteFlag != ''">and delete_flag = #{deleteFlag}</if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="channelCode != null  and channelCode != ''">and channel_code = #{channelCode}</if>
            <if test="videoNvrCode != null  and videoNvrCode != ''">and video_nvr_code = #{videoNvrCode}</if>
            <if test="patrolPointIdList != null  and patrolPointIdList != ''">
                and patrol_point_id in
                <foreach item="item" collection="patrolPointIdList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectBasedataPatrolPointPresetListByPointIds" parameterType="java.util.List"
            resultMap="BasedataPatrolPointPresetResult">
        <include refid="selectBasedataPatrolPointPresetVo"/>
        WHERE patrol_point_id IN
        <foreach item="item" collection="patrolPointIds" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectBasedataPatrolPointPresetByPatrolPointPresetId" parameterType="Long"
            resultMap="BasedataPatrolPointPresetResult">
        <include refid="selectBasedataPatrolPointPresetVo"/>
        where patrol_point_preset_id = #{patrolPointPresetId}
    </select>

    <insert id="insertBasedataPatrolPointPreset" parameterType="BasedataPatrolPointPreset" useGeneratedKeys="true"
            keyProperty="patrolPointPresetId">
        insert into basedata_patrolpoint_preset
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patrolPointId != null">patrol_point_id,</if>
            <if test="eqpBookId != null">eqp_book_id,</if>
            <if test="channelId != null">channel_id,</if>
            <if test="presetCode != null">preset_code,</if>
            <if test="presetName != null">preset_name,</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="deleteFlag != null">delete_flag,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
            <if test="channelCode != null">channel_code,</if>
            <if test="videoNvrCode != null">video_nvr_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="patrolPointId != null">#{patrolPointId},</if>
            <if test="eqpBookId != null">#{eqpBookId},</if>
            <if test="channelId != null">#{channelId},</if>
            <if test="presetCode != null">#{presetCode},</if>
            <if test="presetName != null">#{presetName},</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="deleteFlag != null">#{deleteFlag},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
            <if test="channelCode != null">#{channelCode},</if>
            <if test="videoNvrCode != null">#{videoNvrCode},</if>
        </trim>
    </insert>

    <update id="updateBasedataPatrolPointPreset" parameterType="BasedataPatrolPointPreset">
        update basedata_patrolpoint_preset
        <trim prefix="SET" suffixOverrides=",">
            <if test="patrolPointId != null">patrol_point_id = #{patrolPointId},</if>
            <if test="eqpBookId != null">eqp_book_id = #{eqpBookId},</if>
            <if test="channelId != null">channel_id = #{channelId},</if>
            <if test="presetCode != null">preset_code = #{presetCode},</if>
            <if test="presetName != null">preset_name = #{presetName},</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="deleteFlag != null">delete_flag = #{deleteFlag},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
            <if test="channelCode != null">channel_code = #{channelCode},</if>
            <if test="videoNvrCode != null">video_nvr_code = #{videoNvrCode},</if>
        </trim>
        where patrol_point_preset_id = #{patrolPointPresetId}
    </update>

    <delete id="deleteBasedataPatrolPointPresetByPatrolPointPresetId" parameterType="Long">
        delete
        from basedata_patrolpoint_preset
        where patrol_point_preset_id = #{patrolPointPresetId}
    </delete>

    <delete id="deleteBasedataPatrolPointPresetByPatrolPointPresetIds" parameterType="String">
        delete from basedata_patrolpoint_preset where patrol_point_preset_id in
        <foreach item="patrolPointPresetId" collection="array" open="(" separator="," close=")">
            #{patrolPointPresetId}
        </foreach>
    </delete>

    <delete id="deleteBySendCode">
        delete from basedata_patrolpoint_preset where patrol_point_id in (select patrol_point_id from basedata_patrolpoint where patrol_point_code like concat(#{sendCode}, '%'));
    </delete>

    <select id="selectBasedataPatrolPointPresetByPatrolPointId" parameterType="Long"
            resultMap="BasedataPatrolPointPresetResult">
        <include refid="selectBasedataPatrolPointPresetVo"/>
        where patrol_point_id = #{patrolPointId}
    </select>
</mapper>