提交 | 用户 | 时间
|
a6316e
|
1 |
package com.billion.framework.web.service; |
A |
2 |
|
|
3 |
import java.util.HashSet; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Set; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.stereotype.Component; |
|
8 |
import org.springframework.util.CollectionUtils; |
|
9 |
import com.billion.common.constant.UserConstants; |
|
10 |
import com.billion.common.core.domain.entity.SysRole; |
|
11 |
import com.billion.common.core.domain.entity.SysUser; |
|
12 |
import com.billion.common.utils.StringUtils; |
|
13 |
import com.billion.system.service.ISysMenuService; |
|
14 |
import com.billion.system.service.ISysRoleService; |
|
15 |
|
|
16 |
/** |
|
17 |
* 用户权限处理 |
|
18 |
* |
|
19 |
* @author ruoyi |
|
20 |
*/ |
|
21 |
@Component |
|
22 |
public class SysPermissionService |
|
23 |
{ |
|
24 |
@Autowired |
|
25 |
private ISysRoleService roleService; |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private ISysMenuService menuService; |
|
29 |
|
|
30 |
/** |
|
31 |
* 获取角色数据权限 |
|
32 |
* |
|
33 |
* @param user 用户信息 |
|
34 |
* @return 角色权限信息 |
|
35 |
*/ |
|
36 |
public Set<String> getRolePermission(SysUser user) |
|
37 |
{ |
|
38 |
Set<String> roles = new HashSet<String>(); |
|
39 |
// 管理员拥有所有权限 |
|
40 |
if (user.isAdmin()) |
|
41 |
{ |
|
42 |
roles.add("admin"); |
|
43 |
} |
|
44 |
else |
|
45 |
{ |
|
46 |
roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); |
|
47 |
} |
|
48 |
return roles; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* 获取菜单数据权限 |
|
53 |
* |
|
54 |
* @param user 用户信息 |
|
55 |
* @return 菜单权限信息 |
|
56 |
*/ |
|
57 |
public Set<String> getMenuPermission(SysUser user) |
|
58 |
{ |
|
59 |
Set<String> perms = new HashSet<String>(); |
|
60 |
// 管理员拥有所有权限 |
|
61 |
if (user.isAdmin()) |
|
62 |
{ |
|
63 |
perms.add("*:*:*"); |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
67 |
List<SysRole> roles = user.getRoles(); |
|
68 |
if (!CollectionUtils.isEmpty(roles)) |
|
69 |
{ |
|
70 |
// 多角色设置permissions属性,以便数据权限匹配权限 |
|
71 |
for (SysRole role : roles) |
|
72 |
{ |
|
73 |
if (StringUtils.equals(role.getStatus(), UserConstants.ROLE_NORMAL)) |
|
74 |
{ |
|
75 |
Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); |
|
76 |
role.setPermissions(rolePerms); |
|
77 |
perms.addAll(rolePerms); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
else |
|
82 |
{ |
|
83 |
perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); |
|
84 |
} |
|
85 |
} |
|
86 |
return perms; |
|
87 |
} |
|
88 |
} |