提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.system.service; |
X |
2 |
|
|
3 |
import com.dl.common.core.domain.entity.SysUser; |
|
4 |
import lombok.RequiredArgsConstructor; |
|
5 |
import org.springframework.stereotype.Service; |
|
6 |
|
|
7 |
import java.util.HashSet; |
|
8 |
import java.util.Set; |
|
9 |
|
|
10 |
/** |
|
11 |
* 用户权限处理 |
|
12 |
* |
|
13 |
* @author dl |
|
14 |
*/ |
|
15 |
@RequiredArgsConstructor |
|
16 |
@Service |
|
17 |
public class SysPermissionService { |
|
18 |
|
|
19 |
private final ISysRoleService roleService; |
|
20 |
private final ISysMenuService menuService; |
|
21 |
|
|
22 |
/** |
|
23 |
* 获取角色数据权限 |
|
24 |
* |
|
25 |
* @param user 用户信息 |
|
26 |
* @return 角色权限信息 |
|
27 |
*/ |
|
28 |
public Set<String> getRolePermission(SysUser user) { |
|
29 |
Set<String> roles = new HashSet<>(); |
|
30 |
// 管理员拥有所有权限 |
|
31 |
if (user.isAdmin()) { |
|
32 |
roles.add("admin"); |
|
33 |
} else { |
|
34 |
roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); |
|
35 |
} |
|
36 |
return roles; |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* 获取菜单数据权限 |
|
41 |
* |
|
42 |
* @param user 用户信息 |
|
43 |
* @return 菜单权限信息 |
|
44 |
*/ |
|
45 |
public Set<String> getMenuPermission(SysUser user) { |
|
46 |
Set<String> perms = new HashSet<>(); |
|
47 |
// 管理员拥有所有权限 |
|
48 |
if (user.isAdmin()) { |
|
49 |
perms.add("*:*:*"); |
|
50 |
} else { |
|
51 |
perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); |
|
52 |
} |
|
53 |
return perms; |
|
54 |
} |
|
55 |
} |