<?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.ruoyi.system.mapper.DragTableBtnMapper">
    
    <resultMap type="com.ruoyi.system.entity.DragTableBtn" id="DragTableBtnResult">
        <result property="id"    column="id"    />
        <result property="btnParentId"    column="btn_parent_id"    />
        <result property="btnKey"    column="btn_key"    />
        <result property="ancestorsId" column="ancestors_id"/>
        <result property="btnGroupName" column="btn_group_name"/>
        <result property="btnName"    column="btn_name"    />
        <result property="btnType"    column="btn_type"    />
        <result property="btnIcon" column="btn_icon"/>
        <result property="btnFormKey"    column="btn_form_key"    />
        <result property="btnProcessKey"    column="btn_process_key"    />
        <result property="btnTableKey"    column="btn_table_key"    />
        <result property="btnScriptKey"    column="btn_script_key"    />
        <result property="btnShowCondition"    column="btn_show_condition"    />
        <result property="btnParams"    column="btn_params"    />
        <result property="btnHasPermi"    column="btn_has_permi"    />
        <result property="btnSort"    column="btn_sort"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createById"    column="create_by_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateById"    column="update_by_id"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectDragTableBtnVo">
        select id, btn_parent_id,ancestors_id, btn_key,btn_group_name, btn_name, btn_type,btn_icon, btn_form_key, btn_process_key, btn_table_key, btn_script_key,btn_table_form_group_key,btn_show_condition, btn_params, btn_has_permi, btn_sort, del_flag, create_by, create_by_id, create_time, update_by, update_by_id, update_time, remark from drag_table_btn
    </sql>

    <select id="selectDragTableBtnList" parameterType="com.ruoyi.system.entity.DragTableBtn" resultMap="DragTableBtnResult">
        <include refid="selectDragTableBtnVo"/>
        where del_flag = '0'
            <if test="btnParentId != null "> and btn_parent_id = #{btnParentId}</if>
            <if test="btnKey != null  and btnKey != ''"> and btn_key = #{btnKey}</if>
            <if test="btnGroupName != null  and btnGroupName != ''"> and btn_group_name like concat('%', #{btnGroupName}, '%')</if>
            <if test="btnName != null  and btnName != ''"> and btn_name like concat('%', #{btnName}, '%')</if>
            <if test="btnType != null  and btnType != ''"> and btn_type = #{btnType}</if>
            <if test="btnFormKey != null  and btnFormKey != ''"> and btn_form_key = #{btnFormKey}</if>
            <if test="btnProcessKey != null  and btnProcessKey != ''"> and btn_process_key = #{btnProcessKey}</if>
            <if test="btnTableFormGroupKey !=null and btnTableFormGroupKey!=''">and btn_table_form_group_key=#{btnTableFormGroupKey}</if>
            <if test="btnTableKey != null  and btnTableKey != ''"> and btn_table_key = #{btnTableKey}</if>
            <if test="btnScriptKey != null  and btnScriptKey != ''"> and btn_script_key = #{btnScriptKey}</if>
            <if test="btnShowCondition != null  and btnShowCondition != ''"> and btn_show_condition = #{btnShowCondition}</if>
            <if test="btnParams != null  and btnParams != ''"> and btn_params = #{btnParams}</if>
            <if test="btnHasPermi != null  and btnHasPermi != ''"> and btn_has_permi = #{btnHasPermi}</if>
            <if test="btnSort != null "> and btn_sort = #{btnSort}</if>
            <if test="createById != null "> and create_by_id = #{createById}</if>
            <if test="updateById != null "> and update_by_id = #{updateById}</if>
             order by btn_sort asc
    </select>
    
    <select id="selectDragTableBtnById" parameterType="Long" resultMap="DragTableBtnResult">
        <include refid="selectDragTableBtnVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDragTableBtn" parameterType="com.ruoyi.system.entity.DragTableBtn">
        insert into drag_table_btn
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="btnParentId != null">btn_parent_id,</if>
            <if test="btnKey != null">btn_key,</if>
            <if test="ancestorsId != null">ancestors_id,</if>
            <if test="btnGroupName != null">btn_group_name,</if>
            <if test="btnName != null">btn_name,</if>
            <if test="btnType != null">btn_type,</if>
            <if test="btnIcon != null">btn_icon,</if>
            <if test="btnFormKey != null">btn_form_key,</if>
            <if test="btnProcessKey != null">btn_process_key,</if>
            <if test="btnTableKey != null">btn_table_key,</if>
            <if test="btnScriptKey != null">btn_script_key,</if>
            <if test="btnShowCondition != null">btn_show_condition,</if>
            <if test="btnParams != null">btn_params,</if>
            <if test="btnHasPermi != null">btn_has_permi,</if>
            <if test="btnSort != null">btn_sort,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createById != null">create_by_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
            del_flag
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="btnParentId != null">#{btnParentId},</if>
            <if test="btnKey != null">#{btnKey},</if>
            <if test="ancestorsId != null">#{ancestorsId},</if>
            <if test="btnGroupName != null">#{btnGroupName},</if>
            <if test="btnName != null">#{btnName},</if>
            <if test="btnType != null">#{btnType},</if>
            <if test="btnIcon != null">#{btnIcon},</if>
            <if test="btnFormKey != null">#{btnFormKey},</if>
            <if test="btnProcessKey != null">#{btnProcessKey},</if>
            <if test="btnTableKey != null">#{btnTableKey},</if>
            <if test="btnScriptKey != null">#{btnScriptKey},</if>
            <if test="btnShowCondition != null">#{btnShowCondition},</if>
            <if test="btnParams != null">#{btnParams},</if>
            <if test="btnHasPermi != null">#{btnHasPermi},</if>
            <if test="btnSort != null">#{btnSort},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createById != null">#{createById},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
            '0'
         </trim>
    </insert>

    <update id="updateDragTableBtn" parameterType="com.ruoyi.system.entity.DragTableBtn">
        update drag_table_btn
        <trim prefix="SET" suffixOverrides=",">
            <if test="btnParentId != null">btn_parent_id = #{btnParentId},</if>
            <if test="btnKey != null">btn_key = #{btnKey},</if>
            <if test="ancestorsId != null">ancestors_id = #{ancestorsId},</if>
            <if test="btnGroupName != null">btn_group_name = #{btnGroupName},</if>
            <if test="btnName != null">btn_name = #{btnName},</if>
            <if test="btnType != null">btn_type = #{btnType},</if>
            <if test="btnIcon != null">btn_icon = #{btnIcon},</if>
            <if test="btnFormKey != null">btn_form_key = #{btnFormKey},</if>
            <if test="btnProcessKey != null">btn_process_key = #{btnProcessKey},</if>
            <if test="btnTableKey != null">btn_table_key = #{btnTableKey},</if>
            <if test="btnScriptKey != null">btn_script_key = #{btnScriptKey},</if>
            <if test="btnShowCondition != null">btn_show_condition = #{btnShowCondition},</if>
            <if test="btnParams != null">btn_params = #{btnParams},</if>
            <if test="btnHasPermi != null">btn_has_permi = #{btnHasPermi},</if>
            <if test="btnSort != null">btn_sort = #{btnSort},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateById != null">update_by_id = #{updateById},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteDragTableBtnById" parameterType="Long">
        update drag_table_btn set del_flag = '2' where id = #{id}
    </update>

    <update id="batchDeleteDragTableBtnByBtnKeys" parameterType="String">
        update drag_table_btn set del_flag = '2' where btn_key in
        <foreach item="btnKey" collection="list" open="(" separator="," close=")">
            #{btnKey}
        </foreach>
    </update>

    <select id="selectDragTableBtnListByBtnKey" resultMap="DragTableBtnResult">
        <include refid="selectDragTableBtnVo"></include>
        where del_flag = '0' and btn_key in
        <foreach collection="list" item="btnKey" open="(" close=")" separator=",">
            #{btnKey}
        </foreach>
    </select>

    <select id="selectChildNodeById" resultMap="DragTableBtnResult">
        <include refid="selectDragTableBtnVo"></include>
        where del_flag = '0' and
        <foreach collection="list" item="id" open="(" close=")" separator="or">
            FIND_IN_SET(#{id},ancestors_id)
        </foreach>
    </select>

    <select id="hasChildByBtnId" resultType="Integer">
        select count(1) from drag_table_btn where btn_parent_id = #{btnId} and del_flag = '0'
    </select>

    <select id="selectDragTableBtnByBtnKey" parameterType="String" resultMap="DragTableBtnResult">
        <include refid="selectDragTableBtnVo"/>
        where btn_key = #{btnKey}
    </select>

</mapper>