<?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.dxhy.admin.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="queryUserName" resultType="com.dxhy.admin.sys.entity.SysUserEntity">
        select
        *
        from sys_user where loginname = #{loginname}
        <if test="userId != null and userId != '' ">
            and user_id != #{userId}
        </if>
    </select>

    <select id="queryUserMenu" resultType="com.dxhy.admin.sys.entity.SysUserEntity">
        SELECT user.*
        FROM sys_user user,
             sys_user_role role,
             sys_role_menu menu
        WHERE user.user_id = role.user_id
          AND role.role_id = menu.role_id
          and menu_id = #{menuId}
    </select>

    <select id="queryUserRole" resultType="com.dxhy.admin.sys.entity.SysUserEntity">
        SELECT user.*

        FROM sys_user user,
             sys_user_role role
        WHERE user.user_id = role.user_id
          and role.role_id = #{roleId}
    </select>

    <select id="queryUserBussiness" resultType="com.dxhy.admin.sys.entity.SysUserEntity">
        SELECT user.*

        FROM sys_user user,
             sys_user_business business
        WHERE user.user_id = business.user_id
          and business.business_id = #{businessId}
    </select>


    <select id="getUserCompanyList" resultType="com.dxhy.admin.sys.model.UserModel">
        SELECT user_id, username, loginname
        FROM sys_user
        WHERE company = #{company}
    </select>

    <select id="queryUserByEmail" resultType="com.dxhy.admin.sys.entity.SysUserEntity">
        select *
        from sys_user
        where email = #{email}
    </select>
</mapper>
