2021-09-17 14:48:36 +08:00
|
|
|
package com.ruoyi.system.service;
|
2020-02-13 10:48:51 +08:00
|
|
|
|
2021-09-17 14:48:36 +08:00
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
2020-02-13 10:48:51 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
2021-09-17 14:48:36 +08:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2020-02-13 10:48:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户权限处理
|
|
|
|
*
|
|
|
|
* @author ruoyi
|
|
|
|
*/
|
|
|
|
@Component
|
|
|
|
public class SysPermissionService
|
|
|
|
{
|
|
|
|
@Autowired
|
|
|
|
private ISysRoleService roleService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ISysMenuService menuService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取角色数据权限
|
|
|
|
*
|
|
|
|
* @param user 用户信息
|
|
|
|
* @return 角色权限信息
|
|
|
|
*/
|
|
|
|
public Set<String> getRolePermission(SysUser user)
|
|
|
|
{
|
|
|
|
Set<String> roles = new HashSet<String>();
|
|
|
|
// 管理员拥有所有权限
|
|
|
|
if (user.isAdmin())
|
|
|
|
{
|
|
|
|
roles.add("admin");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId()));
|
|
|
|
}
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取菜单数据权限
|
|
|
|
*
|
|
|
|
* @param user 用户信息
|
|
|
|
* @return 菜单权限信息
|
|
|
|
*/
|
|
|
|
public Set<String> getMenuPermission(SysUser user)
|
|
|
|
{
|
2020-03-09 09:40:39 +08:00
|
|
|
Set<String> perms = new HashSet<String>();
|
2020-02-13 10:48:51 +08:00
|
|
|
// 管理员拥有所有权限
|
|
|
|
if (user.isAdmin())
|
|
|
|
{
|
2020-03-09 09:40:39 +08:00
|
|
|
perms.add("*:*:*");
|
2020-02-13 10:48:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-09 09:40:39 +08:00
|
|
|
perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId()));
|
2020-02-13 10:48:51 +08:00
|
|
|
}
|
2020-03-09 09:40:39 +08:00
|
|
|
return perms;
|
2020-02-13 10:48:51 +08:00
|
|
|
}
|
|
|
|
}
|