<?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="cn.fateverse.admin.mapper.RoleMenuMapper">

    <select id="selectMenuIdsByRoleId" resultType="java.lang.Long">
        select menu_id from sys_role_menu  where role_id = #{roleId}
    </select>

    <insert id="batch">
        insert into sys_role_menu (role_id, menu_id)
        values
        <foreach collection="list" item="roleMenu" separator=",">
            (#{roleMenu.roleId},#{roleMenu.menuId})
        </foreach>
    </insert>

    <delete id="deleteByRoleId">
        delete from sys_role_menu where role_id = #{roleId}
    </delete>

    <delete id="deleteByMenuId">
        delete from sys_role_menu where menu_id = #{menuId}
    </delete>

    <delete id="unBindMenu">
        delete from sys_role_menu
        where menu_id = #{menuId}
        and role_id in
        <foreach collection="roleIds" item="roleId" separator="," open="(" close=")">
            #{roleId}
        </foreach>
    </delete>

    <delete id="unBindAllMenu">
        delete from sys_role_menu where menu_id = #{menuId}
    </delete>
</mapper>