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 055bc15b
authored
Jul 12, 2023
by
chamberone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加角色信息
1 parent
5365be9a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
18 deletions
project-interface/src/main/java/com/dituhui/pea/pojo/ResourceInfo.java
project-interface/src/main/java/com/dituhui/pea/pojo/RoleInfo.java
project-interface/src/main/java/com/dituhui/pea/pojo/UserLoginDTO.java
project-user/src/main/java/com/dituhui/pea/user/dao/RoleDao.java
project-user/src/main/java/com/dituhui/pea/user/dao/UserRoleDao.java
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
project-interface/src/main/java/com/dituhui/pea/pojo/ResourceInfo.java
View file @
055bc15
...
...
@@ -26,11 +26,6 @@ public class ResourceInfo {
*/
private
String
extra
;
/**
* 团队id
*/
@NotBlank
(
message
=
"团队ID不能为空!"
)
private
String
teamId
;
/**
* 描述
*/
private
String
description
;
...
...
project-interface/src/main/java/com/dituhui/pea/pojo/RoleInfo.java
View file @
055bc15
...
...
@@ -22,11 +22,6 @@ public class RoleInfo {
@NotBlank
(
message
=
"角色名称不能为空!"
)
private
String
name
;
/**
* 团队id
*/
@NotBlank
(
message
=
"团队ID不能为空!"
)
private
String
teamId
;
/**
* 角色组id
*/
private
String
groupId
;
...
...
project-interface/src/main/java/com/dituhui/pea/pojo/UserLoginDTO.java
View file @
055bc15
package
com
.
dituhui
.
pea
.
pojo
;
import
java.util.List
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
...
...
@@ -20,4 +22,7 @@ public class UserLoginDTO {
private
String
wechat
;
private
String
token
;
private
List
<
RoleInfo
>
roles
;
private
List
<
ResourceInfo
>
resource
;
}
project-user/src/main/java/com/dituhui/pea/user/dao/RoleDao.java
View file @
055bc15
...
...
@@ -9,8 +9,6 @@ import org.springframework.data.repository.CrudRepository;
/**
* 角色表(Role)表数据库访问层
*
* @author zl
* @since 2020-12-09 15:33:38
*/
public
interface
RoleDao
extends
JpaRepository
<
RoleEntity
,
String
>,
JpaSpecificationExecutor
<
RoleEntity
>,
CrudRepository
<
RoleEntity
,
String
>
{
...
...
project-user/src/main/java/com/dituhui/pea/user/dao/UserRoleDao.java
View file @
055bc15
...
...
@@ -24,6 +24,12 @@ public interface UserRoleDao extends JpaRepository<UserRoleEntity, String>,
*/
List
<
UserRoleEntity
>
findByRoleId
(
String
roleId
);
/**
* 根据用户ID查询
* @param roleId 角色ID
* @return
*/
List
<
UserRoleEntity
>
findByUserId
(
String
userId
);
/**
* 根据角色ID和用户ID删除
...
...
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
View file @
055bc15
...
...
@@ -2,6 +2,7 @@ package com.dituhui.pea.user.service;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
javax.persistence.criteria.Path
;
import
javax.persistence.criteria.Predicate
;
...
...
@@ -12,18 +13,24 @@ import org.springframework.data.jpa.domain.Specification;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.alibaba.nacos.common.utils.CollectionUtils
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.enums.RedisKeyGroup
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
import
com.dituhui.pea.enums.ThirdPartyEnum
;
import
com.dituhui.pea.exception.BusinessException
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.ThirdUserInfo
;
import
com.dituhui.pea.pojo.UserInfo
;
import
com.dituhui.pea.pojo.UserLoginDTO
;
import
com.dituhui.pea.user.commom.RedisService
;
import
com.dituhui.pea.user.constant.TextConstant
;
import
com.dituhui.pea.user.dao.RoleDao
;
import
com.dituhui.pea.user.dao.UserDao
;
import
com.dituhui.pea.user.dao.UserRoleDao
;
import
com.dituhui.pea.user.entity.RoleEntity
;
import
com.dituhui.pea.user.entity.UserEntity
;
import
com.dituhui.pea.user.entity.UserRoleEntity
;
import
com.dituhui.pea.user.factory.ThirdStrategy
;
import
com.dituhui.pea.user.factory.ThirdStrategyFactory
;
import
com.dituhui.pea.user.utils.TextHelper
;
...
...
@@ -47,7 +54,7 @@ public class UserService {
/**
* 失效时间ms
*/
private
static
final
int
aliveTime
=
7200000
;
private
static
final
int
LIVE_TIME_MILLIS
=
7200000
;
@Autowired
UserDao
userDao
;
...
...
@@ -58,17 +65,35 @@ public class UserService {
@Autowired
private
RedisService
redisService
;
@Autowired
UserRoleDao
userRoleDao
;
@Autowired
RoleDao
roleDao
;
public
Result
<?>
userLogin
(
String
account
,
String
password
)
{
UserEntity
user
=
userDao
.
findByAccountAndPassword
(
account
,
SecureUtil
.
md5
(
password
));
log
.
info
(
"{}
:{}:{}:{}"
,
account
,
password
,
SecureUtil
.
md5
(
password
),
user
);
log
.
info
(
"{}
/{} login"
,
account
,
password
);
if
(
null
!=
user
)
{
// 生成token
UserLoginDTO
userDTO
=
BeanUtil
.
copyProperties
(
user
,
UserLoginDTO
.
class
);
// 生成token
String
uuid
=
IdUtil
.
simpleUUID
();
// 2小时
long
timestamp
=
System
.
currentTimeMillis
()
+
aliveTime
;
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
<
RoleEntity
>
roles
=
roleDao
.
findAllById
(
userRoles
.
stream
().
map
(
r
->
r
.
getRoleId
()).
collect
(
Collectors
.
toList
()));
if
(
CollectionUtils
.
isNotEmpty
(
roles
))
{
userDTO
.
setRoles
(
roles
.
stream
().
map
(
r
->
BeanUtil
.
copyProperties
(
r
,
RoleInfo
.
class
))
.
collect
(
Collectors
.
toList
()));
}
}
// 获取资源
userDTO
.
setToken
(
uuid
);
return
Result
.
success
(
userDTO
);
}
else
{
...
...
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