|
|
|
@ -44,6 +44,11 @@ public class DataScopeAspect
|
|
|
|
|
*/
|
|
|
|
|
public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 仅本人数据权限
|
|
|
|
|
*/
|
|
|
|
|
public static final String DATA_SCOPE_SELF = "5";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据权限过滤关键字
|
|
|
|
|
*/
|
|
|
|
@ -76,7 +81,8 @@ public class DataScopeAspect
|
|
|
|
|
// 如果是超级管理员,则不过滤数据
|
|
|
|
|
if (!currentUser.isAdmin())
|
|
|
|
|
{
|
|
|
|
|
dataScopeFilter(joinPoint, currentUser, controllerDataScope.tableAlias());
|
|
|
|
|
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
|
|
|
|
controllerDataScope.userAlias());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -88,7 +94,7 @@ public class DataScopeAspect
|
|
|
|
|
* @param user 用户
|
|
|
|
|
* @param alias 别名
|
|
|
|
|
*/
|
|
|
|
|
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String alias)
|
|
|
|
|
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sqlString = new StringBuilder();
|
|
|
|
|
|
|
|
|
@ -103,19 +109,30 @@ public class DataScopeAspect
|
|
|
|
|
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 = {} ) ", alias,
|
|
|
|
|
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
|
|
|
|
|
role.getRoleId()));
|
|
|
|
|
}
|
|
|
|
|
else if (DATA_SCOPE_DEPT.equals(dataScope))
|
|
|
|
|
{
|
|
|
|
|
sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", alias, user.getDeptId()));
|
|
|
|
|
sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
|
|
|
|
|
}
|
|
|
|
|
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
|
|
|
|
|
{
|
|
|
|
|
String deptChild = user.getDept().getParentId() + "," + user.getDeptId();
|
|
|
|
|
sqlString.append(StringUtils.format(
|
|
|
|
|
" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or ancestors LIKE '%{}%' )",
|
|
|
|
|
alias, user.getDeptId(), deptChild));
|
|
|
|
|
deptAlias, user.getDeptId(), deptChild));
|
|
|
|
|
}
|
|
|
|
|
else if (DATA_SCOPE_SELF.equals(dataScope))
|
|
|
|
|
{
|
|
|
|
|
if (StringUtils.isNotBlank(userAlias))
|
|
|
|
|
{
|
|
|
|
|
sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sqlString.append(StringUtils.format(" OR {}.dept_id IS NULL ", deptAlias));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|