<?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.xhkjedu.suser.mapper.system.RoleMapper">
    <!-- 获取所有角色 -->
    <select id="listAllRoles" resultType="com.xhkjedu.suser.model.system.TRole">
        SELECT r.roleid,r.rolename,r.roletype,r.comm,r.createid,r.createtime,u.username AS createname,
        (SELECT COUNT(*) FROM t_user_role ur WHERE ur.roleid=r.roleid) AS usernum
        FROM t_role r LEFT JOIN t_user u ON r.createid = u.userid
        WHERE r.schoolid=#{schoolid} ORDER BY createtime desc
    </select>

    <!-- 获取角色下用户 -->
    <select id="getRoleDetail" resultType="com.xhkjedu.suser.vo.system.RoleVo">
        SELECT r.roleid,r.rolename,r.comm,r.roletype
        from t_role r
        WHERE r.roleid=#{roleid} limit 1
    </select>
    <!--根据角色id获取角色类型-->
    <select id="getTypeById" resultType="java.lang.Integer">
        select roletype from t_role where roleid=#{roleid}
    </select>
    <!--角色选择列表-->
    <select id="listForSel" resultType="java.util.Map">
        select r.roleid,r.rolename,r.roletype
        from t_role r
        where r.schoolid=#{schoolid} order by createtime desc
    </select>
</mapper>
