新增数据权限过滤注解
parent
63dd90d494
commit
8ab4e12c61
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,21 @@
|
||||
package com.ruoyi.framework.aspectj.lang.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 数据权限过滤注解
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DataScope
|
||||
{
|
||||
/** 表的别名 */
|
||||
String tableAlias() default "";
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package com.ruoyi.framework.datascope;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.security.ShiroUtils;
|
||||
import com.ruoyi.project.system.role.domain.Role;
|
||||
import com.ruoyi.project.system.user.domain.User;
|
||||
|
||||
/**
|
||||
* 数据范围处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DataScopeUtils
|
||||
{
|
||||
/**
|
||||
* 全部数据权限
|
||||
*/
|
||||
public static final String DATA_SCOPE_ALL = "1";
|
||||
|
||||
/**
|
||||
* 自定数据权限
|
||||
*/
|
||||
public static final String DATA_SCOPE_CUSTOM = "2";
|
||||
|
||||
/**
|
||||
* 数据范围过滤
|
||||
*
|
||||
* @return 标准连接条件对象
|
||||
*/
|
||||
public static String dataScopeFilter()
|
||||
{
|
||||
return dataScopeFilter("u");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据范围过滤
|
||||
*
|
||||
* @param da 部门表别名
|
||||
* @return 标准连接条件对象
|
||||
*/
|
||||
public static String dataScopeFilter(String da)
|
||||
{
|
||||
User user = ShiroUtils.getUser();
|
||||
// 如果是超级管理员,则不过滤数据
|
||||
if (user.isAdmin())
|
||||
{
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
StringBuilder sqlString = new StringBuilder();
|
||||
|
||||
for (Role role : user.getRoles())
|
||||
{
|
||||
String dataScope = role.getDataScope();
|
||||
if (DATA_SCOPE_ALL.equals(dataScope))
|
||||
{
|
||||
sqlString = new StringBuilder();
|
||||
break;
|
||||
}
|
||||
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
||||
{
|
||||
sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", da, role.getRoleId()));
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(sqlString.toString()))
|
||||
{
|
||||
return " AND (" + sqlString.substring(4) + ")";
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue