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,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;
}
}