<?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.ycwl.basic.mapper.MenuMapper">
    <insert id="addRoleMenu">
        insert into role_menu(`role_id`, `menu_id`)
        values
        <foreach collection="list" item="item" separator=",">
            (#{id},#{item})
        </foreach>
    </insert>
    <insert id="add">
        insert into menu(id, parent_id, target, `name`, type, sort, permission_url, is_remove, business_type, icon)
        values
        (#{id}, #{parentId}, #{target}, #{name}, #{type}, #{sort}, #{permissionUrl}, #{isRemove}, #{businessType}, #{icon})
    </insert>
    <update id="update">
        update menu
        <set>
            <if test="parentId!= null ">
                parent_id = #{parentId},
            </if>
            <if test="target!= null and target!= ''">
                target = #{target},
            </if>
            <if test="name!= null and name!= ''">
                `name` = #{name},
            </if>
            <if test="type!= null ">
                `type` = #{type},
            </if>
            <if test="sort!= null ">
                sort = #{sort},
            </if>
            <if test="permissionUrl!= null and permissionUrl!= ''">
                permission_url = #{permissionUrl},
            </if>
            <if test="businessType!= null ">
                business_type = #{businessType},
            </if>
            <if test="icon!= null and icon!= ''">
                icon = #{icon},
            </if>
        </set>
        where id = #{id}
    </update>

    <delete id="deleteRoleMenuByRoleId">
        delete
        from role_menu
        where role_id = #{id}
    </delete>
    <delete id="deleteById">
        update menu set is_remove=1 where id = #{id}
    </delete>
    <delete id="deleteRoleMenuByMenuId">
        delete
        from role_menu
        where menu_id = #{id}
    </delete>

    <select id="getListByType" resultType="com.ycwl.basic.model.pc.menu.MenuNode">
        select id,
               parent_id,
               target,
               `name`,
               `type`,
               sort
        from menu
        where is_remove = 0
          <if test="type!= null ">
                and business_type = #{type}
          </if>
    </select>


</mapper>
