feat(core): 新增项目及相关功能的数据访问层和权限控制切面
- 添加多个Mapper接口及XML文件支持项目、成员、里程碑、任务、风险、资源、 文件附件等模块的数据操作和查询功能,支持复杂查询与统计 - 新增Sa-Token权限配置,集成统一认证管理 - 引入权限常量类,定义系统角色、项目角色及权限编码标准 - 新增项目权限校验切面,实现基于注解的项目权限和角色校验逻辑 - 更新配置文件和依赖,集成MyBatis Plus、MinIO、Spring AI及文档解析相关库 - 调整MyBatis配置的类型别名包路径,统一领域实体引用路径
This commit is contained in:
@@ -2,6 +2,7 @@ package cn.yinlihupo.common.aspect;
|
||||
|
||||
import cn.yinlihupo.common.annotation.RequireProjectPermission;
|
||||
import cn.yinlihupo.common.annotation.RequireProjectRole;
|
||||
import cn.yinlihupo.common.enums.ErrorCode;
|
||||
import cn.yinlihupo.common.exception.BusinessException;
|
||||
import cn.yinlihupo.common.util.SecurityUtils;
|
||||
import cn.yinlihupo.service.system.ProjectPermissionService;
|
||||
@@ -41,7 +42,7 @@ public class ProjectPermissionAspect {
|
||||
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new BusinessException(403, "用户未登录");
|
||||
throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR, "用户未登录");
|
||||
}
|
||||
|
||||
// 管理员直接放行
|
||||
@@ -52,7 +53,7 @@ public class ProjectPermissionAspect {
|
||||
// 获取项目ID
|
||||
Long projectId = extractProjectId(joinPoint, annotation.projectIdParam());
|
||||
if (projectId == null) {
|
||||
throw new BusinessException(400, "无法获取项目ID");
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "无法获取项目ID");
|
||||
}
|
||||
|
||||
// 校验权限
|
||||
@@ -61,7 +62,7 @@ public class ProjectPermissionAspect {
|
||||
|
||||
if (!hasPermission) {
|
||||
log.warn("用户 [{}] 没有项目 [{}] 的权限 [{}]", userId, projectId, requiredPermission);
|
||||
throw new BusinessException(403, annotation.message());
|
||||
throw new BusinessException(ErrorCode.FORBIDDEN_ERROR, annotation.message());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +77,7 @@ public class ProjectPermissionAspect {
|
||||
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new BusinessException(403, "用户未登录");
|
||||
throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR, "用户未登录");
|
||||
}
|
||||
|
||||
// 管理员直接放行(如果允许)
|
||||
@@ -87,13 +88,13 @@ public class ProjectPermissionAspect {
|
||||
// 获取项目ID
|
||||
Long projectId = extractProjectId(joinPoint, annotation.projectIdParam());
|
||||
if (projectId == null) {
|
||||
throw new BusinessException(400, "无法获取项目ID");
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "无法获取项目ID");
|
||||
}
|
||||
|
||||
// 获取用户项目角色
|
||||
String userRole = projectPermissionService.getUserProjectRole(userId, projectId);
|
||||
if (userRole == null) {
|
||||
throw new BusinessException(403, "您不是该项目的成员");
|
||||
throw new BusinessException(ErrorCode.FORBIDDEN_ERROR, "您不是该项目的成员");
|
||||
}
|
||||
|
||||
// 校验角色
|
||||
@@ -109,7 +110,7 @@ public class ProjectPermissionAspect {
|
||||
if (!hasRole) {
|
||||
log.warn("用户 [{}] 在项目 [{}] 中的角色 [{}] 不符合要求 {}",
|
||||
userId, projectId, userRole, requiredRoles);
|
||||
throw new BusinessException(403, annotation.message());
|
||||
throw new BusinessException(ErrorCode.FORBIDDEN_ERROR, annotation.message());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user