<?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="io.dataease.base.mapper.ext.ExtSysRoleMapper">



    <resultMap id="roleItemMap" type="io.dataease.controller.sys.response.RoleUserItem">
        <id property="id" column="id"/>
        <result property="name" column="name"/>
    </resultMap>

    <select id="query" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="io.dataease.base.mapper.SysRoleMapper.BaseResultMap">
        select r.*
        from sys_role r
        <if test="_parameter != null">
            <include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        <if test="orderByClause == null">
            order by r.update_time desc
        </if>

    </select>


    <delete id="deleteRoleMenu">
        delete from sys_roles_menus where role_id = #{roleId}
    </delete>

    <insert id="batchInsertRoleMenu">
        insert into sys_roles_menus (role_id, menu_id) values
        <foreach collection="maps" item="map" separator=",">
            (#{map.roleId},#{map.menuId})
        </foreach>
    </insert>

    <select id="queryAll" resultMap="roleItemMap">
        select role_id as id, name from sys_role
    </select>

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



</mapper>
