<?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.renren.modules.sys.dao.SysUserDao">
    <!-- 查询用户的所有权限 -->
    <select id="queryAllPerms" resultType="string">
        select m.perms from sys_user_role ur
        LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
        LEFT JOIN sys_menu m on rm.menu_id = m.menu_id
        where ur.user_id = #{userId}
    </select>

    <!-- 查询用户的所有菜单ID -->
    <select id="queryAllMenuId" resultType="long">
        select distinct rm.menu_id from sys_user_role ur
        LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
        where ur.user_id = #{userId}
    </select>

    <select id="queryByUserName" resultType="io.renren.modules.sys.entity.SysUserEntity">
        select * from sys_user where username = #{username}
    </select>

    <select id="queryByMail" resultType="io.renren.modules.sys.entity.SysUserEntity">
        select * from sys_user where email = #{mail}
    </select>

    <select id="queryByUserId" resultType="io.renren.modules.sys.entity.SysUserEntity">
        select * from sys_user where user_id = #{userId}
    </select>

    <select id="queryByDeptAndRole" resultType="Long">
        select u.* from sys_user u
        left join SYS_USER_ROLE r on r.user_id = u.user_id
        left join SYS_ROLE_DEPT d on d.role_id = r.role_id
        where d.dept_id = #{deptId} and r.role_id = #{roleId}
    </select>

    <select id="queryByRole" resultType="io.renren.modules.sys.entity.SysUserEntity">
        select u.* from sys_user u
                            left join SYS_USER_ROLE r on r.user_id = u.user_id
        where r.role_id = 414
    </select>

    <select id="queryAllUser" resultType="io.renren.modules.sys.entity.SysUserEntity">
        select * from sys_user
    </select>

</mapper>
