Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-usercenter
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 958ab538
authored
Mar 19, 2022
by
levphon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
获取用户下级by用户id
1 parent
799bd47d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
36 deletions
src/main/java/cn/com/glsx/shield/modules/api/FeignUserController.java
src/main/java/cn/com/glsx/shield/modules/service/UserService.java
src/main/java/cn/com/glsx/shield/modules/api/FeignUserController.java
View file @
958ab53
...
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
/**
/**
* feign用户服务接口
* feign用户服务接口
...
@@ -53,25 +54,32 @@ public class FeignUserController implements cn.com.glsx.usercenter.api.feign.Use
...
@@ -53,25 +54,32 @@ public class FeignUserController implements cn.com.glsx.usercenter.api.feign.Use
}
}
@Override
@Override
@GetMapping
(
value
=
"/getSuperior
User
ById"
)
@GetMapping
(
value
=
"/getSuperiorById"
)
public
R
<
User
>
getSuperior
UserById
(
@RequestParam
(
"id"
)
Long
i
d
)
{
public
R
<
User
>
getSuperior
ById
(
@RequestParam
(
"id"
)
Long
userI
d
)
{
cn
.
com
.
glsx
.
shield
.
modules
.
entity
.
User
u
=
userService
.
getSuperiorUserById
(
i
d
);
cn
.
com
.
glsx
.
shield
.
modules
.
entity
.
User
u
=
userService
.
getSuperiorUserById
(
userI
d
);
User
user
=
null
;
User
user
=
null
;
if
(
u
!=
null
)
{
if
(
u
!=
null
)
{
user
=
UserConverter
.
INSTANCE
.
do2foo
(
u
);
user
=
UserConverter
.
INSTANCE
.
do2foo
(
u
);
user
.
setMid
(
i
d
);
user
.
setMid
(
userI
d
);
}
}
return
R
.
ok
().
data
(
user
);
return
R
.
ok
().
data
(
user
);
}
}
@Override
@Override
@PostMapping
(
value
=
"/getSuperior
User
ByIds"
)
@PostMapping
(
value
=
"/getSuperiorByIds"
)
public
R
<
List
<
User
>>
getSuperior
User
ByIds
(
@RequestBody
Collection
<
Long
>
userIds
)
{
public
R
<
List
<
User
>>
getSuperiorByIds
(
@RequestBody
Collection
<
Long
>
userIds
)
{
List
<
User
>
userList
=
userService
.
getSuperiorUserByIds
(
userIds
);
List
<
User
>
userList
=
userService
.
getSuperiorUserByIds
(
userIds
);
return
R
.
ok
().
data
(
userList
);
return
R
.
ok
().
data
(
userList
);
}
}
@Override
@Override
@GetMapping
(
value
=
"/getSubordinateById"
)
public
R
<
Set
<
Long
>>
getSubordinateById
(
@RequestParam
(
"id"
)
Long
userId
)
{
Set
<
Long
>
userIdSet
=
userService
.
getSubordinateById
(
userId
);
return
R
.
ok
().
data
(
userIdSet
);
}
@Override
@ApiOperation
(
value
=
"系统用户列表查询"
)
@ApiOperation
(
value
=
"系统用户列表查询"
)
@GetMapping
(
"/findByUser"
)
@GetMapping
(
"/findByUser"
)
public
R
<
List
<
User
>>
findByUser
(
@RequestBody
FindUserRequest
request
)
{
public
R
<
List
<
User
>>
findByUser
(
@RequestBody
FindUserRequest
request
)
{
...
...
src/main/java/cn/com/glsx/shield/modules/service/UserService.java
View file @
958ab53
...
@@ -31,6 +31,7 @@ import com.glsx.plat.jwt.base.ComJwtUser;
...
@@ -31,6 +31,7 @@ import com.glsx.plat.jwt.base.ComJwtUser;
import
com.glsx.plat.jwt.util.JwtUtils
;
import
com.glsx.plat.jwt.util.JwtUtils
;
import
com.glsx.plat.web.utils.SessionUtils
;
import
com.glsx.plat.web.utils.SessionUtils
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.shiro.authc.credential.HashedCredentialsMatcher
;
import
org.apache.shiro.authc.credential.HashedCredentialsMatcher
;
...
@@ -754,58 +755,64 @@ public class UserService {
...
@@ -754,58 +755,64 @@ public class UserService {
authUser
.
setRoles
(
list
);
authUser
.
setRoles
(
list
);
}
}
//可见租户
//可见租户
Set
<
Long
>
tenantIds
=
this
.
getRelationAuthTenantIds
(
authUser
);
Set
<
Long
>
tenantIds
=
this
.
getRelationAuthTenantIds
(
user
.
getId
(),
roleList
.
get
(
0
).
getId
());
//可见根部门(租户)
authUser
.
setVisibleTenantIds
(
tenantIds
);
//超级管理员无需查询更详细的部门、用户等信息
//超级管理员无需查询更详细的部门、用户等信息
if
(!
isSupperAdmin
)
{
if
(!
isSupperAdmin
)
{
//可见部门
//可见部门
Set
<
Long
>
deptIds
=
this
.
getRelationAuthDeptIds
(
authUser
);
Set
<
Long
>
deptIds
=
this
.
getRelationAuthDeptIds
(
user
.
getId
(),
roleList
.
get
(
0
).
getId
());
//可见组织(部门)
authUser
.
setVisibleDeptIds
(
deptIds
);
//可见用户
Set
<
Long
>
userIds
=
this
.
getRelationAuthUserIds
(
user
.
getId
(),
roleList
.
get
(
0
).
getId
());
//可见用户
//可见用户
Set
<
Long
>
userIds
=
this
.
getRelationAuthUserIds
(
authUser
);
authUser
.
setVisibleCreatorIds
(
userIds
);
}
}
return
authUser
;
return
authUser
;
}
}
public
Set
<
Long
>
getRelationAuthTenantIds
(
SyntheticUser
authUser
)
{
/**
* 获取用户根据数据权限范围内的可见租户id
List
<
Tenant
>
deptList
=
departmentService
.
getUserRoleTenants
(
authUser
.
getUserId
(),
*
authUser
.
getRoles
().
get
(
0
).
getRoleId
());
* @param userId
* @param roleId
Set
<
Long
>
tenantIds
=
deptList
.
stream
().
map
(
Tenant:
:
getId
).
collect
(
Collectors
.
toSet
());
* @return
*/
public
Set
<
Long
>
getRelationAuthTenantIds
(
Long
userId
,
Long
roleId
)
{
//可见根部门(租户)
List
<
Tenant
>
deptList
=
departmentService
.
getUserRoleTenants
(
userId
,
roleId
);
authUser
.
setVisibleTenantIds
(
tenantIds
);
return
tenantIds
;
return
deptList
.
stream
().
map
(
Tenant:
:
getId
).
collect
(
Collectors
.
toSet
())
;
}
}
public
Set
<
Long
>
getRelationAuthDeptIds
(
SyntheticUser
authUser
)
{
/**
* 获取用户根据数据权限范围内的可见部门id
List
<
Department
>
deptList
=
departmentService
.
getUserRoleDepartments
(
authUser
.
getUserId
(),
*
authUser
.
getRoles
().
get
(
0
).
getRoleId
());
* @param userId
* @param roleId
Set
<
Long
>
deptIds
=
deptList
.
stream
().
map
(
Department:
:
getId
).
collect
(
Collectors
.
toSet
());
* @return
*/
public
Set
<
Long
>
getRelationAuthDeptIds
(
Long
userId
,
Long
roleId
)
{
//可见组织(部门)
List
<
Department
>
deptList
=
departmentService
.
getUserRoleDepartments
(
userId
,
roleId
);
authUser
.
setVisibleDeptIds
(
deptIds
);
return
dept
Ids
;
return
dept
List
.
stream
().
map
(
Department:
:
getId
).
collect
(
Collectors
.
toSet
())
;
}
}
/**
/**
* 获取用户根据数据权限范围内的可见用户id
* 获取用户根据数据权限范围内的可见用户id
*
*
* @param authUser
* @param userId
* @param roleId
* @return
* @return
*/
*/
public
Set
<
Long
>
getRelationAuthUserIds
(
SyntheticUser
authUser
)
{
public
Set
<
Long
>
getRelationAuthUserIds
(
Long
userId
,
Long
roleId
)
{
List
<
User
>
userList
=
departmentService
.
getUserRoleUsers
(
authUser
.
getUserId
(),
authUser
.
getRoles
().
get
(
0
).
getRoleId
()
);
List
<
User
>
userList
=
departmentService
.
getUserRoleUsers
(
userId
,
roleId
);
Set
<
Long
>
userIds
=
userList
.
stream
().
map
(
User:
:
getId
).
collect
(
Collectors
.
toSet
());
return
userList
.
stream
().
map
(
User:
:
getId
).
collect
(
Collectors
.
toSet
());
//可见用户
authUser
.
setVisibleCreatorIds
(
userIds
);
return
userIds
;
}
}
/**
/**
...
@@ -1000,6 +1007,16 @@ public class UserService {
...
@@ -1000,6 +1007,16 @@ public class UserService {
return
userMapper
.
selectSuperiorUserById
(
id
);
return
userMapper
.
selectSuperiorUserById
(
id
);
}
}
public
Set
<
Long
>
getSubordinateById
(
Long
userId
)
{
List
<
Role
>
roleList
=
roleService
.
getUserRoleList
(
userId
);
if
(
CollectionUtils
.
isEmpty
(
roleList
))
{
return
Sets
.
newHashSet
();
}
return
this
.
getRelationAuthUserIds
(
userId
,
roleList
.
get
(
0
).
getId
());
}
public
List
<
cn
.
com
.
glsx
.
usercenter
.
api
.
dto
.
response
.
User
>
getSuperiorUserByIds
(
Collection
<
Long
>
userIds
)
{
public
List
<
cn
.
com
.
glsx
.
usercenter
.
api
.
dto
.
response
.
User
>
getSuperiorUserByIds
(
Collection
<
Long
>
userIds
)
{
return
userMapper
.
selectSuperiorUserByIds
(
userIds
);
return
userMapper
.
selectSuperiorUserByIds
(
userIds
);
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment