feat(auth): 增加飞书登录返回角色权限和用户信息接口
- 飞书登录接口返回token、用户信息、角色列表、权限列表及管理员标识 - 新增接口获取当前登录用户详细信息,包含角色权限和用户基本属性 - 全局异常处理增加未登录异常捕获,返回对应错误码和信息 - 新增系统权限初始化SQL脚本,包含菜单、按钮权限及角色分配 - 实现权限管理的增删改查及权限树查询接口 - 实现角色管理的分页查询、详情查询、新增修改删除及权限分配接口 - 实现用户管理分页查询、详情、角色查询、新增修改功能及角色ID列表接口 - 权限、角色和用户接口均添加Sa-Token权限校验注解,确保安全访问
This commit is contained in:
@@ -2,6 +2,8 @@ package cn.yinlihupo.service.system;
|
||||
|
||||
import cn.yinlihupo.domain.entity.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 飞书认证服务接口
|
||||
*/
|
||||
@@ -36,4 +38,28 @@ public interface FeishuAuthService {
|
||||
* @return 用户实体
|
||||
*/
|
||||
SysUser getOrCreateUserByPhone(String phone, String realName, String avatar, String email, String openId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户实体
|
||||
*/
|
||||
SysUser getUserById(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户角色列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色编码列表
|
||||
*/
|
||||
List<String> getUserRoles(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户权限列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 权限编码列表
|
||||
*/
|
||||
List<String> getUserPermissions(Long userId);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.yinlihupo.common.config.FeishuConfig;
|
||||
import cn.yinlihupo.domain.entity.SysUser;
|
||||
import cn.yinlihupo.mapper.SysPermissionMapper;
|
||||
import cn.yinlihupo.mapper.SysUserMapper;
|
||||
import cn.yinlihupo.service.system.FeishuAuthService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -17,6 +18,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 飞书认证服务实现类
|
||||
@@ -28,6 +31,7 @@ public class FeishuAuthServiceImpl implements FeishuAuthService {
|
||||
|
||||
private final FeishuConfig feishuConfig;
|
||||
private final SysUserMapper sysUserMapper;
|
||||
private final SysPermissionMapper sysPermissionMapper;
|
||||
|
||||
/**
|
||||
* 飞书OAuth授权端点
|
||||
@@ -203,4 +207,36 @@ public class FeishuAuthServiceImpl implements FeishuAuthService {
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUserById(Long userId) {
|
||||
if (userId == null) {
|
||||
return null;
|
||||
}
|
||||
return sysUserMapper.selectById(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUserRoles(Long userId) {
|
||||
if (userId == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> roles = sysUserMapper.selectRoleCodesByUserId(userId);
|
||||
return roles != null ? roles : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUserPermissions(Long userId) {
|
||||
if (userId == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 先获取用户角色
|
||||
List<String> roleCodes = sysUserMapper.selectRoleCodesByUserId(userId);
|
||||
if (roleCodes == null || roleCodes.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 根据角色查询权限
|
||||
List<String> permissions = sysPermissionMapper.selectPermissionCodesByRoleCodes(roleCodes);
|
||||
return permissions != null ? permissions : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user