mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 17:38:48 +08:00
Pre Merge pull request !687 from Binary/dev
This commit is contained in:
commit
bd156ce586
@ -1,10 +1,18 @@
|
||||
package org.dromara.common.core.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 通用 角色服务
|
||||
*
|
||||
* @author AprilWind
|
||||
*/
|
||||
public interface RoleService {
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色权限 roleKey:roleName
|
||||
*/
|
||||
Map<String, String> selectRoleKeysByUserId(Long userId);
|
||||
}
|
||||
|
||||
@ -3,10 +3,14 @@ package org.dromara.common.satoken.core.service;
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.enums.UserType;
|
||||
import org.dromara.common.core.service.RoleService;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* sa-token 权限管理实现类
|
||||
@ -36,6 +40,25 @@ public class SaPermissionImpl implements StpInterface {
|
||||
@Override
|
||||
public List<String> getRoleList(Object loginId, String loginType) {
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
|
||||
if (loginId != null) {
|
||||
// 查询指定用户权限
|
||||
if (loginId instanceof Long) {
|
||||
Long selectUserId = (Long) loginId;
|
||||
Long userId = null;
|
||||
if (loginUser != null) {
|
||||
userId = loginUser.getUserId();
|
||||
}
|
||||
if (!selectUserId.equals(userId)) {
|
||||
// 查询的不是当前登录用户 那么查询数据库指定用户的权限
|
||||
RoleService roleService = SpringUtils.getBean("sysRoleServiceImpl");
|
||||
Map<String, String> roleKeysByUserId = roleService.selectRoleKeysByUserId(selectUserId);
|
||||
Set<String> roleKeySet = roleKeysByUserId.keySet();
|
||||
return new ArrayList<>(roleKeySet);
|
||||
} // else 查询的是当前登录用户 走原来的逻辑
|
||||
}
|
||||
}
|
||||
|
||||
UserType userType = UserType.getUserType(loginUser.getUserType());
|
||||
if (userType == UserType.SYS_USER) {
|
||||
return new ArrayList<>(loginUser.getRolePermission());
|
||||
|
||||
@ -40,6 +40,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 角色 业务层处理
|
||||
@ -97,6 +98,18 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
|
||||
return baseMapper.selectRolesByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色权限 roleKey:roleName
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> selectRoleKeysByUserId(Long userId) {
|
||||
List<SysRoleVo> sysRoleVos = baseMapper.selectRolesByUserId(userId);
|
||||
return sysRoleVos.stream().collect(Collectors.toMap(SysRoleVo::getRoleKey, SysRoleVo::getRoleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色列表(包含被授权状态)
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user