| | |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | |
| | | |
| | | /** |
| | | * 用户权限处理 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | | public class SysPermissionService |
| | | { |
| | | public class SysPermissionService { |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | |
| | | @Value("${isAdmin}") |
| | | private List<Long> isAdmin; |
| | | |
| | | /** |
| | | * 获取角色数据权限 |
| | | * |
| | | * |
| | | * @param user 用户信息 |
| | | * @return 角色权限信息 |
| | | */ |
| | | public Set<String> getRolePermission(SysUser user) |
| | | { |
| | | public Set<String> getRolePermission(SysUser user) { |
| | | Set<String> roles = new HashSet<String>(); |
| | | // 管理员拥有所有权限 |
| | | if (user.isAdmin()) |
| | | { |
| | | // if (user.isAdmin()) |
| | | if (user.getUserId() != null && isAdmin.contains(user.getUserId())) { |
| | | roles.add("admin"); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); |
| | | } |
| | | return roles; |
| | |
| | | |
| | | /** |
| | | * 获取菜单数据权限 |
| | | * |
| | | * |
| | | * @param user 用户信息 |
| | | * @return 菜单权限信息 |
| | | */ |
| | | public Set<String> getMenuPermission(SysUser user) |
| | | { |
| | | public Set<String> getMenuPermission(SysUser user) { |
| | | Set<String> perms = new HashSet<String>(); |
| | | // 管理员拥有所有权限 |
| | | if (user.isAdmin()) |
| | | { |
| | | // if (user.isAdmin()) { |
| | | if (user.getUserId() != null && isAdmin.contains(user.getUserId())) { |
| | | perms.add("*:*:*"); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | List<SysRole> roles = user.getRoles(); |
| | | if (!roles.isEmpty() && roles.size() > 1) |
| | | { |
| | | if (!roles.isEmpty() && roles.size() > 1) { |
| | | // 多角色设置permissions属性,以便数据权限匹配权限 |
| | | for (SysRole role : roles) |
| | | { |
| | | for (SysRole role : roles) { |
| | | Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); |
| | | role.setPermissions(rolePerms); |
| | | perms.addAll(rolePerms); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); |
| | | } |
| | | } |