Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2a4c8e1e
authored
Jul 12, 2023
by
丁伟峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into develop
2 parents
c991694e
b78b3d3c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
22 deletions
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
View file @
2a4c8e1
...
...
@@ -90,27 +90,7 @@ public class UserService {
long
timestamp
=
System
.
currentTimeMillis
()
+
LIVE_TIME_MILLIS
;
redisService
.
set
(
RedisKeyGroup
.
authToken
+
":"
+
uuid
,
user
,
timestamp
);
UserLoginDTO
userDTO
=
BeanUtil
.
copyProperties
(
user
,
UserLoginDTO
.
class
);
// 获取角色
List
<
UserRoleEntity
>
userRoles
=
userRoleDao
.
findByUserId
(
user
.
getId
());
if
(
CollectionUtils
.
isNotEmpty
(
userRoles
))
{
List
<
String
>
ids
=
userRoles
.
stream
().
map
(
r
->
r
.
getRoleId
()).
collect
(
Collectors
.
toList
());
List
<
RoleEntity
>
roles
=
roleDao
.
findAllById
(
ids
);
if
(
CollectionUtils
.
isNotEmpty
(
roles
))
{
userDTO
.
setRoles
(
roles
.
stream
().
map
(
r
->
BeanUtil
.
copyProperties
(
r
,
RoleInfo
.
class
))
.
collect
(
Collectors
.
toList
()));
// 获取资源
List
<
RoleResourceEntity
>
roleResources
=
roleResourceDao
.
findByRoleIdIn
(
ids
);
if
(
CollectionUtils
.
isNotEmpty
(
roleResources
))
{
List
<
String
>
resourceIds
=
roleResources
.
stream
().
map
(
r
->
r
.
getResourceId
())
.
collect
(
Collectors
.
toList
());
userDTO
.
setResources
(
resourceDao
.
findAllById
(
resourceIds
).
stream
()
.
map
(
r
->
BeanUtil
.
copyProperties
(
r
,
ResourceInfo
.
class
)).
collect
(
Collectors
.
toList
()));
}
}
}
UserLoginDTO
userDTO
=
convertToUserLoginDTO
(
user
);
userDTO
.
setToken
(
uuid
);
return
Result
.
success
(
userDTO
);
}
else
{
...
...
@@ -118,9 +98,37 @@ public class UserService {
}
}
private
UserLoginDTO
convertToUserLoginDTO
(
UserEntity
user
)
{
UserLoginDTO
userDTO
=
BeanUtil
.
copyProperties
(
user
,
UserLoginDTO
.
class
);
// 获取角色
List
<
UserRoleEntity
>
userRoles
=
userRoleDao
.
findByUserId
(
user
.
getId
());
if
(
CollectionUtils
.
isNotEmpty
(
userRoles
))
{
List
<
String
>
ids
=
userRoles
.
stream
().
map
(
r
->
r
.
getRoleId
()).
collect
(
Collectors
.
toList
());
List
<
RoleEntity
>
roles
=
roleDao
.
findAllById
(
ids
);
if
(
CollectionUtils
.
isNotEmpty
(
roles
))
{
userDTO
.
setRoles
(
roles
.
stream
().
map
(
r
->
BeanUtil
.
copyProperties
(
r
,
RoleInfo
.
class
))
.
collect
(
Collectors
.
toList
()));
// 获取资源
List
<
RoleResourceEntity
>
roleResources
=
roleResourceDao
.
findByRoleIdIn
(
ids
);
log
.
info
(
"role size:{} roleResources:{}"
,
ids
.
size
(),
CollectionUtils
.
isNotEmpty
(
roleResources
));
if
(
CollectionUtils
.
isNotEmpty
(
roleResources
))
{
List
<
String
>
resourceIds
=
roleResources
.
stream
().
map
(
r
->
r
.
getResourceId
())
.
collect
(
Collectors
.
toList
());
userDTO
.
setResources
(
resourceDao
.
findAllById
(
resourceIds
).
stream
()
.
map
(
r
->
BeanUtil
.
copyProperties
(
r
,
ResourceInfo
.
class
)).
collect
(
Collectors
.
toList
()));
}
}
}
return
userDTO
;
}
public
Result
<?>
getUserInfo
(
String
token
)
{
UserEntity
user
=
(
UserEntity
)
redisService
.
get
(
RedisKeyGroup
.
authToken
+
":"
+
token
);
return
Result
.
success
(
user
);
UserLoginDTO
userDTO
=
convertToUserLoginDTO
(
user
);
userDTO
.
setToken
(
token
);
return
Result
.
success
(
userDTO
);
}
public
String
getUserName
(
String
userId
)
{
...
...
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