<?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.bunny.service.mapper.AdminRoleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.bunny.entity.system.admin.AdminRole">
        <id column="id" property="id"/>
        <result column="role_name" property="roleName"/>
        <result column="description" property="description"/>
        <result column="role_code" property="roleCode"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, role_name, description, role_code, create_time, update_time, update_user, is_deleted
    </sql>

    <!-- 查询用户所有的角色信息 -->
    <select id="selectByRoleWithUserId">
        SELECT ar.id roleId, ar.role_code, ar.description roleDescription, aur.user_id
        FROM admin_user_role aur
                 LEFT JOIN admin_role ar ON ar.id = aur.role_id
        WHERE aur.user_id = #{userId}
    </select>
</mapper>
