<?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.PatrolPresetActionMapper">

    <resultMap type="PatrolPresetAction" id="PatrolPresetActionResult">
        <result property="presetActionId" column="preset_action_id"/>
        <result property="presetPosId" column="preset_pos_id"/>
        <result property="actionType" column="action_type"/>
        <result property="videoTime" column="video_time"/>
        <result property="photoCount" column="photo_count"/>
        <result property="photoGap" column="photo_gap"/>
        <result property="isEnable" column="is_enable"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <sql id="selectPatrolPresetActionVo">
        select preset_action_id,
               preset_pos_id,
               action_type,
               video_time,
               photo_count,
               photo_gap,
               is_enable,
               create_time
        from patrol_preset_action
    </sql>

    <select id="selectPatrolPresetActionList" parameterType="PatrolPresetAction" resultMap="PatrolPresetActionResult">
        <include refid="selectPatrolPresetActionVo"/>
        <where>
            <if test="presetPosId != null  and presetPosId != ''">and preset_pos_id = #{presetPosId}</if>
            <if test="actionType != null  and actionType != ''">and action_type = #{actionType}</if>
            <if test="videoTime != null  and videoTime != ''">and video_time = #{videoTime}</if>
            <if test="photoCount != null ">and photo_count = #{photoCount}</if>
            <if test="photoGap != null  and photoGap != ''">and photo_gap = #{photoGap}</if>
            <if test="isEnable != null  and isEnable != ''">and is_enable = #{isEnable}</if>
        </where>
    </select>

    <select id="selectPatrolPresetActionByPatrolPresetPosId" parameterType="Long" resultMap="PatrolPresetActionResult">
        <include refid="selectPatrolPresetActionVo"/>
        where preset_pos_id = #{presetPosId}
    </select>

    <insert id="insertPatrolPresetAction" parameterType="PatrolPresetAction">
        insert into patrol_preset_action
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="presetActionId != null">preset_action_id,</if>
            <if test="presetPosId != null and presetPosId!= ''">preset_pos_id,</if>
            <if test="actionType != null">action_type,</if>
            <if test="videoTime != null">video_time,</if>
            <if test="photoCount != null">photo_count,</if>
            <if test="photoGap != null">photo_gap,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="presetActionId != null">#{presetActionId},</if>
            <if test="presetPosId != null and presetPosId!= ''">#{presetPosId},</if>
            <if test="actionType != null">#{actionType},</if>
            <if test="videoTime != null">#{videoTime},</if>
            <if test="photoCount != null">#{photoCount},</if>
            <if test="photoGap != null">#{photoGap},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>
    <insert id="insertPatrolPresetActionList" parameterType="List">
        insert into patrol_preset_action (preset_pos_id, action_type, video_time, photo_count, photo_gap, create_time)
        values
        <foreach item="item" collection="list" separator=",">
            (#{item.presetPosId},#{item.actionType},#{item.videoTime},#{item.photoCount},#{item.photoGap},#{item.createTime})
        </foreach>
    </insert>

    <update id="updatePatrolPresetAction" parameterType="PatrolPresetAction">
        update patrol_preset_action
        <trim prefix="SET" suffixOverrides=",">
            <if test="presetPosId != null">preset_pos_id = #{presetPosId},</if>
            <if test="actionType != null">action_type = #{actionType},</if>
            <if test="videoTime != null">video_time = #{videoTime},</if>
            <if test="photoCount != null">photo_count = #{photoCount},</if>
            <if test="photoGap != null">photo_gap = #{photoGap},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where preset_action_id = #{presetActionId}
    </update>

    <delete id="deletePatrolPresetActionByPatrolPresetActionId" parameterType="Long">
        delete
        from patrol_preset_action
        where preset_action_id = #{presetActionId}
    </delete>
    <delete id="deletePatrolPresetActionByPatrolPresetPosId" parameterType="String">
        delete
        from patrol_preset_action
        where preset_pos_id = #{PresetPosId}
    </delete>

    <delete id="deletePatrolPresetActionByPatrolPresetPosIds" parameterType="String">
        delete from patrol_preset_action where preset_pos_id in
        <foreach item="presetActionId" collection="array" open="(" separator="," close=")">
            #{presetActionId}
        </foreach>
    </delete>
</mapper>