Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
0df49fcf
Commit
0df49fcf
authored
Jul 14, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增角色数据权限配(仅本人数据权限)
parent
fcde7155
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
13 deletions
+36
-13
ruoyi-admin/src/main/resources/templates/system/role/dataScope.html
+1
-0
ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScope.java
+7
-2
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
+22
-5
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+2
-2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
+1
-1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
+3
-3
No files found.
ruoyi-admin/src/main/resources/templates/system/role/dataScope.html
View file @
0df49fcf
...
...
@@ -28,6 +28,7 @@
<option
value=
"2"
th:field=
"*{dataScope}"
>
自定数据权限
</option>
<option
value=
"3"
th:field=
"*{dataScope}"
>
本部门数据权限
</option>
<option
value=
"4"
th:field=
"*{dataScope}"
>
本部门及以下数据权限
</option>
<option
value=
"5"
th:field=
"*{dataScope}"
>
仅本人数据权限
</option>
</select>
<span
class=
"help-block m-b-none"
><i
class=
"fa fa-info-circle"
></i>
特殊情况下,设置为“自定数据权限”
</span>
</div>
...
...
ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScope.java
View file @
0df49fcf
...
...
@@ -17,7 +17,12 @@ import java.lang.annotation.Target;
public
@interface
DataScope
{
/**
* 表的别名
*
部门
表的别名
*/
public
String
tableAlias
()
default
""
;
public
String
deptAlias
()
default
""
;
/**
* 用户表的别名
*/
public
String
userAlias
()
default
""
;
}
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
View file @
0df49fcf
...
...
@@ -45,6 +45,11 @@ public class DataScopeAspect
public
static
final
String
DATA_SCOPE_DEPT_AND_CHILD
=
"4"
;
/**
* 仅本人数据权限
*/
public
static
final
String
DATA_SCOPE_SELF
=
"5"
;
/**
* 数据权限过滤关键字
*/
public
static
final
String
DATA_SCOPE
=
"dataScope"
;
...
...
@@ -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
a
lias
)
public
static
void
dataScopeFilter
(
JoinPoint
joinPoint
,
SysUser
user
,
String
deptAlias
,
String
userA
lias
)
{
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 = {} ) "
,
a
lias
,
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) "
,
deptA
lias
,
role
.
getRoleId
()));
}
else
if
(
DATA_SCOPE_DEPT
.
equals
(
dataScope
))
{
sqlString
.
append
(
StringUtils
.
format
(
" OR {}.dept_id = {} "
,
a
lias
,
user
.
getDeptId
()));
sqlString
.
append
(
StringUtils
.
format
(
" OR {}.dept_id = {} "
,
deptA
lias
,
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
));
}
}
}
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
View file @
0df49fcf
...
...
@@ -33,7 +33,7 @@ public class SysDeptServiceImpl implements ISysDeptService
* @return 部门信息集合
*/
@Override
@DataScope
(
table
Alias
=
"d"
)
@DataScope
(
dept
Alias
=
"d"
)
public
List
<
SysDept
>
selectDeptList
(
SysDept
dept
)
{
return
deptMapper
.
selectDeptList
(
dept
);
...
...
@@ -46,7 +46,7 @@ public class SysDeptServiceImpl implements ISysDeptService
* @return 所有部门信息
*/
@Override
@DataScope
(
table
Alias
=
"d"
)
@DataScope
(
dept
Alias
=
"d"
)
public
List
<
Ztree
>
selectDeptTree
(
SysDept
dept
)
{
List
<
SysDept
>
deptList
=
deptMapper
.
selectDeptList
(
dept
);
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
View file @
0df49fcf
...
...
@@ -51,7 +51,7 @@ public class SysRoleServiceImpl implements ISysRoleService
* @return 角色数据集合信息
*/
@Override
@DataScope
(
tableAlias
=
"u
"
)
@DataScope
(
deptAlias
=
"d
"
)
public
List
<
SysRole
>
selectRoleList
(
SysRole
role
)
{
return
roleMapper
.
selectRoleList
(
role
);
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
View file @
0df49fcf
...
...
@@ -61,7 +61,7 @@ public class SysUserServiceImpl implements ISysUserService
* @return 用户信息集合信息
*/
@Override
@DataScope
(
table
Alias
=
"u"
)
@DataScope
(
deptAlias
=
"d"
,
user
Alias
=
"u"
)
public
List
<
SysUser
>
selectUserList
(
SysUser
user
)
{
return
userMapper
.
selectUserList
(
user
);
...
...
@@ -73,7 +73,7 @@ public class SysUserServiceImpl implements ISysUserService
* @param user 用户信息
* @return 用户信息集合信息
*/
@DataScope
(
table
Alias
=
"u"
)
@DataScope
(
deptAlias
=
"d"
,
user
Alias
=
"u"
)
public
List
<
SysUser
>
selectAllocatedList
(
SysUser
user
)
{
return
userMapper
.
selectAllocatedList
(
user
);
...
...
@@ -85,7 +85,7 @@ public class SysUserServiceImpl implements ISysUserService
* @param user 用户信息
* @return 用户信息集合信息
*/
@DataScope
(
table
Alias
=
"u"
)
@DataScope
(
deptAlias
=
"d"
,
user
Alias
=
"u"
)
public
List
<
SysUser
>
selectUnallocatedList
(
SysUser
user
)
{
return
userMapper
.
selectUnallocatedList
(
user
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment