<?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.zkqy.system.mapper.DragTableBtnRelevanceMapper">
    
    <resultMap type="com.zkqy.system.entity.DragTableBtnRelevance" id="DragTableBtnRelevanceResult">
        <result property="tableKey"    column="table_key"    />
        <result property="btnKey"    column="btn_key"    />
    </resultMap>

    <sql id="selectDragTableBtnRelevanceVo">
        select table_key, btn_key from drag_table_btn_relevance
    </sql>

    <select id="selectDragTableBtnRelevanceList" parameterType="com.zkqy.system.entity.DragTableBtnRelevance" resultMap="DragTableBtnRelevanceResult">
        <include refid="selectDragTableBtnRelevanceVo"/>
        <where>  
            <if test="tableKey != null  and tableKey != ''"> and table_key = #{tableKey}</if>
            <if test="btnKey != null  and btnKey != ''"> and btn_key = #{btnKey}</if>
        </where>
    </select>
    
    <select id="selectDragTableBtnRelevanceByTableKey" parameterType="String" resultMap="DragTableBtnRelevanceResult">
        <include refid="selectDragTableBtnRelevanceVo"/>
        where table_key = #{tableKey}
    </select>
        
    <insert id="batchInsertDragTableBtnRelevance" parameterType="com.zkqy.system.entity.DragTableBtnRelevance">
        insert into drag_table_btn_relevance
            (table_key,btn_key)
            values
            <foreach collection="list" item="item" separator=",">
                (#{item.tableKey},#{item.btnKey})
            </foreach>
    </insert>

    <update id="updateDragTableBtnRelevance" parameterType="com.zkqy.system.entity.DragTableBtnRelevance">
        update drag_table_btn_relevance
        <trim prefix="SET" suffixOverrides=",">
            <if test="btnKey != null">btn_key = #{btnKey},</if>
        </trim>
        where table_key = #{tableKey}
    </update>

    <delete id="deleteDragTableBtnRelevanceByTableKey" parameterType="String">
        delete from drag_table_btn_relevance where table_key = #{tableKey}
    </delete>

    <delete id="deleteDragTableBtnRelevanceByTableKeys" parameterType="String">
        delete from drag_table_btn_relevance where table_key in 
        <foreach item="tableKey" collection="list" open="(" separator="," close=")">
            #{tableKey}
        </foreach>
    </delete>

    <select id="selectBtnKeyByTableKey" resultType="string">
        select btn_key from drag_table_btn_relevance where table_key = #{tableKey}
    </select>

    <select id="selectBtnKeyBindOrNot" resultType="int">
        select count(1) from drag_table_btn_relevance where btn_key in
        <foreach collection="list" item="btnKey" open="(" close=")" separator=",">
            #{btnKey}
        </foreach>
    </select>

    <select id="selectDragTableBtnRelevanceByBtnKeys" resultMap="DragTableBtnRelevanceResult">
        <include refid="selectDragTableBtnRelevanceVo"></include>
        where btn_key in
        <foreach collection="list" item="btnKey" open="(" close=")" separator=",">
            #{btnKey}
        </foreach>
    </select>

</mapper>