update [重大更新] 重写数据权限实现

This commit is contained in:
疯狂的狮子Li
2021-12-13 03:49:05 +00:00
parent 79fc16eeb7
commit aae3fe5305
24 changed files with 551 additions and 45 deletions

View File

@ -0,0 +1,25 @@
package com.ruoyi.common.annotation;
import java.lang.annotation.*;
/**
* 数据权限
*
* @author Lion Li
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DataColumn {
/**
* 占位符关键字
*/
String key() default "deptName";
/**
* 占位符替换值
*/
String value() default "dept_id";
}

View File

@ -0,0 +1,17 @@
package com.ruoyi.common.annotation;
import java.lang.annotation.*;
/**
* 数据权限组
*
* @author Lion Li
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DataPermission {
DataColumn[] value();
}

View File

@ -6,11 +6,14 @@ import java.lang.annotation.*;
* 数据权限过滤注解
*
* @author ruoyi
* @deprecated 3.6.0 移除 {@link com.ruoyi.common.annotation.DataPermission}
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Deprecated
public @interface DataScope {
/**
* 部门表的别名
*/
@ -25,4 +28,5 @@ public @interface DataScope {
* 是否过滤用户权限
*/
boolean isUser() default false;
}

View File

@ -162,7 +162,7 @@ public class SysUser extends BaseEntity {
private Long[] postIds;
/**
* 角色ID
* 数据权限 当前角色ID
*/
@ApiModelProperty(value = "角色ID")
@TableField(exist = false)

View File

@ -0,0 +1,66 @@
package com.ruoyi.common.enums;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 数据权限类型
*
* 语法支持 spel 模板表达式
*
* 内置数据 user 当前用户 内容参考 SysUser
* 如需扩展数据 需往 SysUser 内注入
* 内置服务 sdss 系统数据权限服务 内容参考 SysDataScopeService
* 如需扩展更多自定义服务 可以参考 sdss 自行编写
*
* @author Lion Li
*/
@Getter
@AllArgsConstructor
public enum DataScopeType {
/**
* 全部数据权限
*/
ALL("1", ""),
/**
* 自定数据权限
*/
CUSTOM("2", " #{#deptName} IN ( #{@sdss.getRoleCustom( #user.roleId )} ) "),
/**
* 部门数据权限
*/
DEPT("3", " #{#deptName} = #{#user.deptId} "),
/**
* 部门及以下数据权限
*/
DEPT_AND_CHILD("4", " #{#deptName} IN ( #{@sdss.getDeptAndChild( #user.deptId )} )"),
/**
* 仅本人数据权限
*/
SELF("5", " #{#userName?:1} = #{#user.userId} ");
private final String code;
/**
* 语法 采用 spel 模板表达式
*/
private final String sql;
public static DataScopeType findCode(String code) {
if (StringUtils.isBlank(code)) {
return null;
}
for (DataScopeType type : values()) {
if (type.getCode().equals(code)) {
return type;
}
}
return null;
}
}