mirror of https://gitee.com/y_project/RuoYi.git
新增角色数据权限配(仅本人数据权限)
parent
fcde715553
commit
0df49fcfe8
|
@ -28,6 +28,7 @@
|
||||||
<option value="2" th:field="*{dataScope}">自定数据权限</option>
|
<option value="2" th:field="*{dataScope}">自定数据权限</option>
|
||||||
<option value="3" th:field="*{dataScope}">本部门数据权限</option>
|
<option value="3" th:field="*{dataScope}">本部门数据权限</option>
|
||||||
<option value="4" th:field="*{dataScope}">本部门及以下数据权限</option>
|
<option value="4" th:field="*{dataScope}">本部门及以下数据权限</option>
|
||||||
|
<option value="5" th:field="*{dataScope}">仅本人数据权限</option>
|
||||||
</select>
|
</select>
|
||||||
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 特殊情况下,设置为“自定数据权限”</span>
|
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 特殊情况下,设置为“自定数据权限”</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,7 +17,12 @@ import java.lang.annotation.Target;
|
||||||
public @interface DataScope
|
public @interface DataScope
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 表的别名
|
* 部门表的别名
|
||||||
*/
|
*/
|
||||||
public String tableAlias() default "";
|
public String deptAlias() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户表的别名
|
||||||
|
*/
|
||||||
|
public String userAlias() default "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,11 @@ public class DataScopeAspect
|
||||||
*/
|
*/
|
||||||
public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
|
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())
|
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 user 用户
|
||||||
* @param alias 别名
|
* @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();
|
StringBuilder sqlString = new StringBuilder();
|
||||||
|
|
||||||
|
@ -103,19 +109,30 @@ public class DataScopeAspect
|
||||||
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
||||||
{
|
{
|
||||||
sqlString.append(StringUtils.format(
|
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()));
|
role.getRoleId()));
|
||||||
}
|
}
|
||||||
else if (DATA_SCOPE_DEPT.equals(dataScope))
|
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))
|
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
|
||||||
{
|
{
|
||||||
String deptChild = user.getDept().getParentId() + "," + user.getDeptId();
|
String deptChild = user.getDept().getParentId() + "," + user.getDeptId();
|
||||||
sqlString.append(StringUtils.format(
|
sqlString.append(StringUtils.format(
|
||||||
" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or ancestors LIKE '%{}%' )",
|
" 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
* @return 部门信息集合
|
* @return 部门信息集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@DataScope(tableAlias = "d")
|
@DataScope(deptAlias = "d")
|
||||||
public List<SysDept> selectDeptList(SysDept dept)
|
public List<SysDept> selectDeptList(SysDept dept)
|
||||||
{
|
{
|
||||||
return deptMapper.selectDeptList(dept);
|
return deptMapper.selectDeptList(dept);
|
||||||
|
@ -46,7 +46,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
* @return 所有部门信息
|
* @return 所有部门信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@DataScope(tableAlias = "d")
|
@DataScope(deptAlias = "d")
|
||||||
public List<Ztree> selectDeptTree(SysDept dept)
|
public List<Ztree> selectDeptTree(SysDept dept)
|
||||||
{
|
{
|
||||||
List<SysDept> deptList = deptMapper.selectDeptList(dept);
|
List<SysDept> deptList = deptMapper.selectDeptList(dept);
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class SysRoleServiceImpl implements ISysRoleService
|
||||||
* @return 角色数据集合信息
|
* @return 角色数据集合信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@DataScope(tableAlias = "u")
|
@DataScope(deptAlias = "d")
|
||||||
public List<SysRole> selectRoleList(SysRole role)
|
public List<SysRole> selectRoleList(SysRole role)
|
||||||
{
|
{
|
||||||
return roleMapper.selectRoleList(role);
|
return roleMapper.selectRoleList(role);
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
* @return 用户信息集合信息
|
* @return 用户信息集合信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@DataScope(tableAlias = "u")
|
@DataScope(deptAlias = "d", userAlias = "u")
|
||||||
public List<SysUser> selectUserList(SysUser user)
|
public List<SysUser> selectUserList(SysUser user)
|
||||||
{
|
{
|
||||||
return userMapper.selectUserList(user);
|
return userMapper.selectUserList(user);
|
||||||
|
@ -73,7 +73,7 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 用户信息集合信息
|
* @return 用户信息集合信息
|
||||||
*/
|
*/
|
||||||
@DataScope(tableAlias = "u")
|
@DataScope(deptAlias = "d", userAlias = "u")
|
||||||
public List<SysUser> selectAllocatedList(SysUser user)
|
public List<SysUser> selectAllocatedList(SysUser user)
|
||||||
{
|
{
|
||||||
return userMapper.selectAllocatedList(user);
|
return userMapper.selectAllocatedList(user);
|
||||||
|
@ -85,7 +85,7 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @return 用户信息集合信息
|
* @return 用户信息集合信息
|
||||||
*/
|
*/
|
||||||
@DataScope(tableAlias = "u")
|
@DataScope(deptAlias = "d", userAlias = "u")
|
||||||
public List<SysUser> selectUnallocatedList(SysUser user)
|
public List<SysUser> selectUnallocatedList(SysUser user)
|
||||||
{
|
{
|
||||||
return userMapper.selectUnallocatedList(user);
|
return userMapper.selectUnallocatedList(user);
|
||||||
|
|
Loading…
Reference in New Issue