<?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.com.ctop.common.module.mapper.SysRoleMapper">

    <!-- 根据roleCode获取roleId -->
    <select id="getRoleIdByRoleCode" resultType="java.lang.String">
        select id
        from sys_role
        where role_code = #{roleCode}
    </select>

    <!-- 根据userId获取角色code -->
    <select id="getRoleCodeByUserId" resultType="java.lang.String">
        select c.role_code
        from sys_user a
                 left join sys_user_role b on a.id = b.user_id
                 left join sys_role c on b.role_id = c.id
        where a.id = #{userId}
    </select>


    <select id="queryRoleByUserId" resultType="cn.com.ctop.common.module.entity.SysRole">
        SELECT t2.role_name,t2.role_code
        FROM sys_user_role t1
                 LEFT JOIN sys_role t2 ON t1.role_id = t2.id
        WHERE t1.user_id = #{userId} LIMIT 1
    </select>

</mapper>
