package com.dl.system.service; import com.dl.common.core.domain.entity.SysUser; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.HashSet; import java.util.Set; /** * 用户权限处理 * * @author dl */ @RequiredArgsConstructor @Service public class SysPermissionService { private final ISysRoleService roleService; private final ISysMenuService menuService; /** * 获取角色数据权限 * * @param user 用户信息 * @return 角色权限信息 */ public Set getRolePermission(SysUser user) { Set roles = new HashSet<>(); // 管理员拥有所有权限 if (user.isAdmin()) { roles.add("admin"); } else { roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); } return roles; } /** * 获取菜单数据权限 * * @param user 用户信息 * @return 菜单权限信息 */ public Set getMenuPermission(SysUser user) { Set perms = new HashSet<>(); // 管理员拥有所有权限 if (user.isAdmin()) { perms.add("*:*:*"); } else { perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); } return perms; } }