<?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.PatrolLinkageStrategyRefMapper">
    
    <resultMap type="PatrolLinkageStrategyRef" id="PatrolLinkageStrategyRefResult">
        <result property="linkageStrategyRefId"    column="linkage_strategy_ref_id"    />
        <result property="linkageStrategyId"    column="linkage_strategy_id"    />
        <result property="patrolPointId"    column="patrol_point_id"    />
        <result property="isEnable"    column="is_enable"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectPatrolLinkageStrategyRefVo">
        select linkage_strategy_ref_id, linkage_strategy_id, patrol_point_id, is_enable, create_time from patrol_linkage_strategy_ref
    </sql>

    <select id="selectPatrolLinkageStrategyRefList" parameterType="PatrolLinkageStrategyRef" resultMap="PatrolLinkageStrategyRefResult">
        <include refid="selectPatrolLinkageStrategyRefVo"/>
        <where>  
            <if test="linkageStrategyId != null "> and linkage_strategy_id = #{linkageStrategyId}</if>
            <if test="patrolPointId != null "> and patrol_point_id = #{patrolPointId}</if>
            <if test="isEnable != null  and isEnable != ''"> and is_enable = #{isEnable}</if>
        </where>
    </select>
    
    <select id="selectPatrolLinkageStrategyRefByLinkageStrategyRefId" parameterType="Long" resultMap="PatrolLinkageStrategyRefResult">
        <include refid="selectPatrolLinkageStrategyRefVo"/>
        where linkage_strategy_ref_id = #{linkageStrategyRefId}
    </select>
        
    <insert id="insertPatrolLinkageStrategyRef" parameterType="PatrolLinkageStrategyRef" useGeneratedKeys="true" keyProperty="linkageStrategyRefId">
        insert into patrol_linkage_strategy_ref
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="linkageStrategyId != null">linkage_strategy_id,</if>
            <if test="patrolPointId != null">patrol_point_id,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="linkageStrategyId != null">#{linkageStrategyId},</if>
            <if test="patrolPointId != null">#{patrolPointId},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>
    <insert id="insertPatrolLinkageStrategyRefs" parameterType="List">
        insert into patrol_linkage_strategy_ref (linkage_strategy_id,patrol_point_id,create_time) values
        <foreach item="item" collection="list" separator="," >
            (#{item.linkageStrategyId},#{item.patrolPointId},#{item.createTime})
        </foreach>
    </insert>

    <update id="updatePatrolLinkageStrategyRef" parameterType="PatrolLinkageStrategyRef">
        update patrol_linkage_strategy_ref
        <trim prefix="SET" suffixOverrides=",">
            <if test="linkageStrategyId != null">linkage_strategy_id = #{linkageStrategyId},</if>
            <if test="patrolPointId != null">patrol_point_id = #{patrolPointId},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where linkage_strategy_ref_id = #{linkageStrategyRefId}
    </update>

    <delete id="deletePatrolLinkageStrategyRefByLinkageStrategyRefId" parameterType="Long">
        delete from patrol_linkage_strategy_ref where linkage_strategy_id = #{linkageStrategyId}
    </delete>

    <delete id="deletePatrolLinkageStrategyRefByLinkageStrategyRefIds" parameterType="String">
        delete from patrol_linkage_strategy_ref where linkage_strategy_ref_id in 
        <foreach item="linkageStrategyRefId" collection="array" open="(" separator="," close=")">
            #{linkageStrategyRefId}
        </foreach>
    </delete>
</mapper>