<?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.simuwang.base.mapper.system.SysRoleMapper">
    <select id="selectMenuByRoleId" resultType="com.simuwang.base.common.support.dos.OnlyIdNameDO">
        select sm.menu_id    as id,
               sm.menu_name  as name
        from sys_menu sm
                 join sys_role_menu srm on sm.menu_id = srm.menu_id
                 join sys_role sr on sr.role_id = srm.role_id and sr.isvalid = 1
        where sr.role_id = #{roleId}
          and sm.isvalid = 1
        order by sm.menu_id
    </select>

    <delete id="delRoleMenuByUserId" parameterType="int">
        delete from sys_role_menu where role_id =#{roleId}
    </delete>

    <insert id="batchRoleMenus">
        insert into sys_role_menu(role_id, menu_id) values
        <foreach collection="menuIds" item="menuId" separator=",">
            (#{roleId}, #{menuId})
        </foreach>
    </insert>
</mapper>