Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cash-loan-flow-boss
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QG
cash-loan-flow-boss
Commits
4299b799
Commit
4299b799
authored
Aug 06, 2019
by
xiaozhe.chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加role相关的类
parent
b088879e
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
154 additions
and
1 deletion
+154
-1
RoleService.java
.../cn/quantgroup/cashloanflowboss/api/role/RoleService.java
+33
-0
RoleUser.java
...quantgroup/cashloanflowboss/api/role/entity/RoleUser.java
+19
-0
RoleRepository.java
.../cashloanflowboss/api/role/repository/RoleRepository.java
+3
-1
RoleUserRepository.java
...hloanflowboss/api/role/repository/RoleUserRepository.java
+13
-0
TestController.java
.../cashloanflowboss/api/test/controller/TestController.java
+24
-0
UserSessionInfo.java
...roup/cashloanflowboss/api/user/model/UserSessionInfo.java
+12
-0
UserService.java
...tgroup/cashloanflowboss/api/user/service/UserService.java
+15
-0
UserSessionService.java
...cashloanflowboss/api/user/service/UserSessionService.java
+33
-0
ApplicationDictionary.java
...shloanflowboss/core/dictionary/ApplicationDictionary.java
+2
-0
No files found.
src/main/java/cn/quantgroup/cashloanflowboss/api/role/RoleService.java
0 → 100644
View file @
4299b799
package
cn
.
quantgroup
.
cashloanflowboss
.
api
.
role
;
import
cn.quantgroup.cashloanflowboss.api.role.entity.Role
;
import
cn.quantgroup.cashloanflowboss.api.role.entity.RoleUser
;
import
cn.quantgroup.cashloanflowboss.api.role.repository.RoleRepository
;
import
cn.quantgroup.cashloanflowboss.api.role.repository.RoleUserRepository
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Slf4j
@Service
public
class
RoleService
{
@Autowired
private
RoleRepository
roleRepository
;
@Autowired
private
RoleUserRepository
roleUserRepository
;
public
Role
findRoleByUserId
(
Long
userId
)
{
RoleUser
roleUser
=
roleUserRepository
.
findByUserId
(
userId
);
Long
roleId
=
roleUser
.
getRoleId
();
Role
role
=
findRoleByRoleId
(
roleId
);
return
role
;
}
public
Role
findRoleByRoleId
(
Long
roleId
)
{
return
roleRepository
.
findOne
(
roleId
);
}
}
src/main/java/cn/quantgroup/cashloanflowboss/api/role/entity/RoleUser.java
0 → 100644
View file @
4299b799
package
cn
.
quantgroup
.
cashloanflowboss
.
api
.
role
.
entity
;
import
cn.quantgroup.cashloanflowboss.core.persistence.Primary
;
import
lombok.Data
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
@Data
@Entity
@Table
(
name
=
"role_user"
)
public
class
RoleUser
extends
Primary
{
private
Long
roleId
;
private
Long
userId
;
}
src/main/java/cn/quantgroup/cashloanflowboss/api/role/repository/RoleRepository.java
View file @
4299b799
package
cn
.
quantgroup
.
cashloanflowboss
.
api
.
role
.
repository
;
import
cn.quantgroup.cashloanflowboss.api.role.entity.Role
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
/**
* Created by WeiWei on 2019/7/30.
*/
@Repository
public
interface
RoleRepository
{
public
interface
RoleRepository
extends
JpaRepository
<
Role
,
Long
>
{
}
src/main/java/cn/quantgroup/cashloanflowboss/api/role/repository/RoleUserRepository.java
0 → 100644
View file @
4299b799
package
cn
.
quantgroup
.
cashloanflowboss
.
api
.
role
.
repository
;
import
cn.quantgroup.cashloanflowboss.api.role.entity.RoleUser
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
@Repository
public
interface
RoleUserRepository
extends
JpaRepository
<
RoleUser
,
Long
>
{
RoleUser
findByUserId
(
Long
userId
);
}
src/main/java/cn/quantgroup/cashloanflowboss/api/test/controller/TestController.java
0 → 100644
View file @
4299b799
package
cn
.
quantgroup
.
cashloanflowboss
.
api
.
test
.
controller
;
import
cn.quantgroup.cashloanflowboss.api.user.entity.boss.User
;
import
cn.quantgroup.cashloanflowboss.api.user.service.UserService
;
import
cn.quantgroup.cashloanflowboss.core.base.Result
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/test"
)
public
class
TestController
{
@Autowired
private
UserService
userService
;
@GetMapping
(
"/user/info"
)
public
Result
findUserFromSession
()
{
User
currentUser
=
userService
.
findCurrentUser
();
return
new
Result
<>(
ApplicationStatus
.
SUCCESS
,
currentUser
);
}
}
src/main/java/cn/quantgroup/cashloanflowboss/api/user/model/UserSessionInfo.java
0 → 100644
View file @
4299b799
package
cn
.
quantgroup
.
cashloanflowboss
.
api
.
user
.
model
;
import
lombok.Builder
;
import
lombok.Data
;
@Data
@Builder
public
class
UserSessionInfo
{
private
String
userName
;
private
String
roleName
;
private
Long
channelId
;
}
src/main/java/cn/quantgroup/cashloanflowboss/api/user/service/UserService.java
View file @
4299b799
...
...
@@ -4,14 +4,20 @@ import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import
cn.quantgroup.cashloanflowboss.api.user.entity.boss.User
;
import
cn.quantgroup.cashloanflowboss.api.user.repository.boss.UserRepository
;
import
cn.quantgroup.cashloanflowboss.core.asserts.Assert
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus
;
import
cn.quantgroup.cashloanflowboss.utils.JSONTools
;
import
cn.quantgroup.cashloanflowboss.utils.MD5Tools
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpSession
;
import
java.util.Objects
;
/**
...
...
@@ -130,4 +136,13 @@ public class UserService {
}
public
User
findCurrentUser
()
{
HttpSession
session
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
().
getSession
();
Assert
.
isNull
(
session
.
getAttribute
(
ApplicationDictionary
.
USER_KEY
),
ApplicationStatus
.
INVALID_USER
);
User
user
=
JSONTools
.
deserialize
(
String
.
valueOf
(
session
.
getAttribute
(
ApplicationDictionary
.
USER_KEY
)),
new
TypeReference
<
User
>()
{
});
return
user
;
}
}
src/main/java/cn/quantgroup/cashloanflowboss/api/user/service/UserSessionService.java
0 → 100644
View file @
4299b799
package
cn
.
quantgroup
.
cashloanflowboss
.
api
.
user
.
service
;
import
cn.quantgroup.cashloanflowboss.api.user.entity.boss.User
;
import
cn.quantgroup.cashloanflowboss.api.user.model.UserSessionInfo
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary
;
import
cn.quantgroup.cashloanflowboss.utils.JSONTools
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpSession
;
@Slf4j
@Service
public
class
UserSessionService
{
public
void
setUserSessionInfo
(
User
user
)
{
HttpSession
session
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
().
getSession
();
session
.
setAttribute
(
ApplicationDictionary
.
USER_KEY
,
JSONTools
.
serialize
(
user
));
//query user role info
//UserSessionInfo.builder()
// .userName(user.getUsername())
// .roleName()
}
}
src/main/java/cn/quantgroup/cashloanflowboss/core/dictionary/ApplicationDictionary.java
View file @
4299b799
...
...
@@ -9,5 +9,7 @@ public final class ApplicationDictionary {
// 权限Session Key
public
static
final
String
SECURITY_KEY
=
"PERMISSION"
;
// user Session key
public
static
final
String
USER_KEY
=
"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