Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
long-tern-care-service
Project
Project
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
hubin
long-tern-care-service
Commits
5ff86d98
Commit
5ff86d98
authored
Apr 07, 2021
by
hubin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
资源 角色管理接口开发
parent
16272d50
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
27 deletions
+52
-27
SystemResource.java
...a/com/hungraim/ltc/pojo/entity/system/SystemResource.java
+1
-1
SystemRole.java
.../java/com/hungraim/ltc/pojo/entity/system/SystemRole.java
+2
-2
MainMenuVO.java
...main/java/com/hungraim/ltc/pojo/vo/system/MainMenuVO.java
+1
-0
AuthorizationManager.java
...m/hungraim/ltc/gateway/security/AuthorizationManager.java
+5
-7
ResourcesController.java
...m/hungraim/ltc/system/controller/ResourcesController.java
+24
-11
RoleController.java
...va/com/hungraim/ltc/system/controller/RoleController.java
+18
-5
SystemResourceMapper.java
...ava/com/hungraim/ltc/system/dao/SystemResourceMapper.java
+1
-1
No files found.
common/common-core/src/main/java/com/hungraim/ltc/pojo/entity/system/SystemResource.java
View file @
5ff86d98
...
@@ -25,7 +25,7 @@ public class SystemResource {
...
@@ -25,7 +25,7 @@ public class SystemResource {
private
String
resourceType
;
private
String
resourceType
;
private
Long
parentId
;
private
Long
parentId
;
private
String
resourceIcon
;
private
String
resourceIcon
;
private
Date
createTime
;
private
Date
create
d
Time
;
@TableField
(
exist
=
false
)
@TableField
(
exist
=
false
)
private
List
<
Long
>
roleIds
;
private
List
<
Long
>
roleIds
;
...
...
common/common-core/src/main/java/com/hungraim/ltc/pojo/entity/system/SystemRole.java
View file @
5ff86d98
...
@@ -20,8 +20,8 @@ public class SystemRole {
...
@@ -20,8 +20,8 @@ public class SystemRole {
private
Long
roleId
;
private
Long
roleId
;
private
String
roleName
;
private
String
roleName
;
private
String
status
;
private
String
status
;
private
Date
createTime
;
private
Date
create
d
Time
;
private
Date
modify
Time
;
private
Date
updated
Time
;
}
}
common/common-core/src/main/java/com/hungraim/ltc/pojo/vo/system/MainMenuVO.java
View file @
5ff86d98
...
@@ -14,6 +14,7 @@ public class MainMenuVO {
...
@@ -14,6 +14,7 @@ public class MainMenuVO {
private
Long
parentId
;
private
Long
parentId
;
private
String
name
;
private
String
name
;
private
String
icon
;
private
String
icon
;
private
String
path
;
private
List
<
MainMenuVO
>
children
;
private
List
<
MainMenuVO
>
children
;
}
}
gateway-service/src/main/java/com/hungraim/ltc/gateway/security/AuthorizationManager.java
View file @
5ff86d98
...
@@ -26,6 +26,7 @@ import java.util.Set;
...
@@ -26,6 +26,7 @@ import java.util.Set;
/**
/**
* 鉴权管理器
* 鉴权管理器
*
* @author hubin
* @author hubin
*/
*/
@Component
@Component
...
@@ -53,13 +54,6 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
...
@@ -53,13 +54,6 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
return
Mono
.
just
(
new
AuthorizationDecision
(
true
));
return
Mono
.
just
(
new
AuthorizationDecision
(
true
));
}
}
// 非管理端路径无需鉴权直接放行
if
(!
pathMatcher
.
match
(
AuthConstants
.
ADMIN_URL_PATTERN
,
path
))
{
log
.
info
(
"请求无需鉴权,path={}"
,
path
);
return
Mono
.
just
(
new
AuthorizationDecision
(
true
));
}
// token为空拒绝访问
// token为空拒绝访问
String
token
=
request
.
getHeaders
().
getFirst
(
AuthConstants
.
AUTHORIZATION_KEY
);
String
token
=
request
.
getHeaders
().
getFirst
(
AuthConstants
.
AUTHORIZATION_KEY
);
log
.
info
(
"请求token,token={}"
,
token
);
log
.
info
(
"请求token,token={}"
,
token
);
...
@@ -92,6 +86,10 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
...
@@ -92,6 +86,10 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
log
.
info
(
"访问路径:{}"
,
path
);
log
.
info
(
"访问路径:{}"
,
path
);
log
.
info
(
"用户角色信息:{}"
,
roleId
);
log
.
info
(
"用户角色信息:{}"
,
roleId
);
log
.
info
(
"资源需要权限authorities:{}"
,
authorities
);
log
.
info
(
"资源需要权限authorities:{}"
,
authorities
);
//如果是管理员 直接放行
if
(
"ROLE_0"
.
equals
(
roleId
))
{
return
true
;
}
return
authorities
.
contains
(
roleId
);
return
authorities
.
contains
(
roleId
);
})
})
.
map
(
AuthorizationDecision:
:
new
)
.
map
(
AuthorizationDecision:
:
new
)
...
...
system/system-admin-service/src/main/java/com/hungraim/ltc/system/controller/ResourcesController.java
View file @
5ff86d98
...
@@ -3,17 +3,17 @@ package com.hungraim.ltc.system.controller;
...
@@ -3,17 +3,17 @@ package com.hungraim.ltc.system.controller;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.hungraim.ltc.pojo.entity.system.SystemResource
;
import
com.hungraim.ltc.pojo.entity.system.SystemResource
;
import
com.hungraim.ltc.pojo.entity.system.SystemRoleResource
;
import
com.hungraim.ltc.pojo.vo.system.MainMenuVO
;
import
com.hungraim.ltc.pojo.vo.system.MainMenuVO
;
import
com.hungraim.ltc.pojo.vo.system.ReqResource
;
import
com.hungraim.ltc.pojo.vo.system.ReqResource
;
import
com.hungraim.ltc.system.service.ISystemResourceService
;
import
com.hungraim.ltc.system.service.ISystemResourceService
;
import
com.hungraim.ltc.system.service.ISystemRoleResourceService
;
import
com.hungraim.ltc.util.Result
;
import
com.hungraim.ltc.util.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -30,6 +30,9 @@ public class ResourcesController {
...
@@ -30,6 +30,9 @@ public class ResourcesController {
@Autowired
@Autowired
private
ISystemResourceService
resourceService
;
private
ISystemResourceService
resourceService
;
@Autowired
private
ISystemRoleResourceService
roleResourceService
;
/**
/**
* 获取主菜单信息
* 获取主菜单信息
...
@@ -46,6 +49,7 @@ public class ResourcesController {
...
@@ -46,6 +49,7 @@ public class ResourcesController {
mainMenuVO
.
setName
(
item
.
getResourceName
());
mainMenuVO
.
setName
(
item
.
getResourceName
());
mainMenuVO
.
setId
(
item
.
getResourceId
());
mainMenuVO
.
setId
(
item
.
getResourceId
());
mainMenuVO
.
setParentId
(
item
.
getParentId
());
mainMenuVO
.
setParentId
(
item
.
getParentId
());
mainMenuVO
.
setPath
(
item
.
getResourceUrl
());
return
mainMenuVO
;
return
mainMenuVO
;
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
//转成tree形式菜单数据
//转成tree形式菜单数据
...
@@ -84,21 +88,30 @@ public class ResourcesController {
...
@@ -84,21 +88,30 @@ public class ResourcesController {
systemResource
.
setResourceId
(
reqResource
.
getId
());
systemResource
.
setResourceId
(
reqResource
.
getId
());
systemResource
.
setResourceIcon
(
reqResource
.
getIcon
());
systemResource
.
setResourceIcon
(
reqResource
.
getIcon
());
systemResource
.
setParentId
(
reqResource
.
getParentId
());
systemResource
.
setParentId
(
reqResource
.
getParentId
());
systemResource
.
setCreateTime
(
new
Date
());
systemResource
.
setCreate
d
Time
(
new
Date
());
resourceService
.
save
(
systemResource
);
resourceService
.
save
(
systemResource
);
SystemRoleResource
systemRoleResource
=
new
SystemRoleResource
();
systemRoleResource
.
setResourceId
(
systemResource
.
getResourceId
());
systemRoleResource
.
setRoleId
(
0L
);
roleResourceService
.
save
(
systemRoleResource
);
return
Result
.
success
(
"插入成功"
);
return
Result
.
success
(
"插入成功"
);
}
}
@PostMapping
(
"/queryResources"
)
@PostMapping
(
"/queryResources"
)
public
Result
queryResources
(
ReqResource
reqResource
){
public
Result
queryResources
(
ReqResource
reqResource
,
@RequestParam
(
defaultValue
=
"1"
)
int
pageNum
,
@RequestParam
(
defaultValue
=
"20"
)
int
pageSize
){
QueryWrapper
<
SystemResource
>
systemResourceQueryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
SystemResource
>
systemResourceQueryWrapper
=
new
QueryWrapper
<>();
if
(
StrUtil
.
isBlankIfStr
(
reqResource
.
getName
()))
{
if
(
!
StrUtil
.
isBlankIfStr
(
reqResource
.
getName
()))
{
systemResourceQueryWrapper
.
and
(
wrapper
->
wrapper
.
lambda
().
like
(
SystemResource:
:
getResourceName
,
reqResource
.
getName
()));
systemResourceQueryWrapper
.
or
(
wrapper
->
wrapper
.
lambda
().
like
(
SystemResource:
:
getResourceName
,
reqResource
.
getName
()));
}
}
if
(
StrUtil
.
isBlankIfStr
(
reqResource
.
getUrl
()))
{
if
(
!
StrUtil
.
isBlankIfStr
(
reqResource
.
getUrl
()))
{
systemResourceQueryWrapper
.
and
(
wrapper
->
wrapper
.
lambda
().
like
(
SystemResource:
:
getResourceUrl
,
reqResource
.
getUrl
()));
systemResourceQueryWrapper
.
or
(
wrapper
->
wrapper
.
lambda
().
like
(
SystemResource:
:
getResourceUrl
,
reqResource
.
getUrl
()));
}
}
return
Result
.
success
(
resourceService
.
list
(
systemResourceQueryWrapper
));
systemResourceQueryWrapper
.
orderByAsc
(
"resource_id"
);
return
Result
.
success
(
resourceService
.
page
(
new
Page
<>(
pageNum
,
pageSize
),
systemResourceQueryWrapper
));
}
}
...
...
system/system-admin-service/src/main/java/com/hungraim/ltc/system/controller/RoleController.java
View file @
5ff86d98
...
@@ -3,6 +3,7 @@ package com.hungraim.ltc.system.controller;
...
@@ -3,6 +3,7 @@ package com.hungraim.ltc.system.controller;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.hungraim.ltc.pojo.entity.system.SystemRole
;
import
com.hungraim.ltc.pojo.entity.system.SystemRole
;
import
com.hungraim.ltc.pojo.entity.system.SystemRoleResource
;
import
com.hungraim.ltc.pojo.entity.system.SystemRoleResource
;
import
com.hungraim.ltc.pojo.vo.system.ReqRoleInfo
;
import
com.hungraim.ltc.pojo.vo.system.ReqRoleInfo
;
...
@@ -13,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -13,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -62,9 +64,11 @@ public class RoleController {
...
@@ -62,9 +64,11 @@ public class RoleController {
SystemRole
systemRole
=
new
SystemRole
();
SystemRole
systemRole
=
new
SystemRole
();
systemRole
.
setRoleName
(
reqRoleInfo
.
getName
());
systemRole
.
setRoleName
(
reqRoleInfo
.
getName
());
systemRole
.
setStatus
(
reqRoleInfo
.
getStatus
());
systemRole
.
setStatus
(
reqRoleInfo
.
getStatus
());
systemRole
.
setCreateTime
(
new
Date
());
systemRole
.
setCreate
d
Time
(
new
Date
());
roleService
.
save
(
systemRole
);
roleService
.
save
(
systemRole
);
if
(
reqRoleInfo
.
getResource
()
==
null
){
reqRoleInfo
.
setResource
(
new
ArrayList
<>());
}
List
<
SystemRoleResource
>
roleResources
=
reqRoleInfo
.
getResource
().
stream
().
map
(
resourceId
->
{
List
<
SystemRoleResource
>
roleResources
=
reqRoleInfo
.
getResource
().
stream
().
map
(
resourceId
->
{
SystemRoleResource
systemRoleResource
=
new
SystemRoleResource
();
SystemRoleResource
systemRoleResource
=
new
SystemRoleResource
();
systemRoleResource
.
setRoleId
(
reqRoleInfo
.
getId
());
systemRoleResource
.
setRoleId
(
reqRoleInfo
.
getId
());
...
@@ -98,11 +102,13 @@ public class RoleController {
...
@@ -98,11 +102,13 @@ public class RoleController {
/**
/**
* 查询角色列表
* 查询角色列表
*
* @param reqRoleInfo
* @param reqRoleInfo
* @return
* @return
*/
*/
@PostMapping
(
"/queryRoles"
)
@PostMapping
(
"/queryRoles"
)
public
Result
queryRoles
(
ReqRoleInfo
reqRoleInfo
)
{
public
Result
queryRoles
(
ReqRoleInfo
reqRoleInfo
,
@RequestParam
(
defaultValue
=
"1"
)
int
pageNum
,
@RequestParam
(
defaultValue
=
"20"
)
int
pageSize
)
{
QueryWrapper
<
SystemRole
>
systemRoleQueryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
SystemRole
>
systemRoleQueryWrapper
=
new
QueryWrapper
<>();
if
(!
StrUtil
.
isBlankIfStr
(
reqRoleInfo
.
getName
()))
{
if
(!
StrUtil
.
isBlankIfStr
(
reqRoleInfo
.
getName
()))
{
...
@@ -111,11 +117,14 @@ public class RoleController {
...
@@ -111,11 +117,14 @@ public class RoleController {
if
(!
StrUtil
.
isBlankIfStr
(
reqRoleInfo
.
getStatus
()))
{
if
(!
StrUtil
.
isBlankIfStr
(
reqRoleInfo
.
getStatus
()))
{
systemRoleQueryWrapper
.
and
(
wrapper
->
wrapper
.
lambda
().
eq
(
SystemRole:
:
getStatus
,
reqRoleInfo
.
getStatus
()));
systemRoleQueryWrapper
.
and
(
wrapper
->
wrapper
.
lambda
().
eq
(
SystemRole:
:
getStatus
,
reqRoleInfo
.
getStatus
()));
}
}
return
Result
.
success
(
roleService
.
list
(
systemRoleQueryWrapper
));
systemRoleQueryWrapper
.
orderByAsc
(
"role_id"
);
return
Result
.
success
(
roleService
.
page
(
new
Page
<>(
pageNum
,
pageSize
),
systemRoleQueryWrapper
));
}
}
/**
/**
* 更新角色信息
* 更新角色信息
*
* @param reqRoleInfo
* @param reqRoleInfo
* @return
* @return
*/
*/
...
@@ -138,12 +147,16 @@ public class RoleController {
...
@@ -138,12 +147,16 @@ public class RoleController {
flag
=
true
;
flag
=
true
;
}
}
if
(
flag
)
{
if
(
flag
)
{
systemRole
.
set
Modify
Time
(
new
Date
());
systemRole
.
set
Updated
Time
(
new
Date
());
roleService
.
save
(
systemRole
);
roleService
.
save
(
systemRole
);
}
}
//查询该角色下所有的资源数据
//查询该角色下所有的资源数据
List
<
SystemRoleResource
>
roleResources
=
roleResourceService
.
list
(
new
LambdaQueryWrapper
<
SystemRoleResource
>().
eq
(
SystemRoleResource:
:
getRoleId
,
reqRoleInfo
.
getId
()));
List
<
SystemRoleResource
>
roleResources
=
roleResourceService
.
list
(
new
LambdaQueryWrapper
<
SystemRoleResource
>().
eq
(
SystemRoleResource:
:
getRoleId
,
reqRoleInfo
.
getId
()));
if
(
reqRoleInfo
.
getResource
()==
null
){
reqRoleInfo
.
setResource
(
new
ArrayList
<>());
}
List
<
SystemRoleResource
>
newRoleResources
=
reqRoleInfo
.
getResource
().
stream
()
List
<
SystemRoleResource
>
newRoleResources
=
reqRoleInfo
.
getResource
().
stream
()
.
filter
(
id
->
{
.
filter
(
id
->
{
for
(
SystemRoleResource
r
:
roleResources
)
{
for
(
SystemRoleResource
r
:
roleResources
)
{
...
...
system/system-admin-service/src/main/java/com/hungraim/ltc/system/dao/SystemResourceMapper.java
View file @
5ff86d98
...
@@ -19,7 +19,7 @@ public interface SystemResourceMapper extends BaseMapper<SystemResource> {
...
@@ -19,7 +19,7 @@ public interface SystemResourceMapper extends BaseMapper<SystemResource> {
*/
*/
@Select
(
"SELECT RESOURCE_ID,RESOURCE_NAME,RESOURCE_URL,METHOD FROM LTC_RESOURCE"
)
@Select
(
"SELECT RESOURCE_ID,RESOURCE_NAME,RESOURCE_URL,METHOD FROM LTC_RESOURCE"
)
@Results
({
@Results
({
@Result
(
property
=
"roleIds"
,
column
=
"
id
"
,
many
=
@Many
(
select
=
"com.hungraim.ltc.system.dao.SystemRoleResourceMapper.listRoleIds"
))
@Result
(
property
=
"roleIds"
,
column
=
"
RESOURCE_ID
"
,
many
=
@Many
(
select
=
"com.hungraim.ltc.system.dao.SystemRoleResourceMapper.listRoleIds"
))
})
})
List
<
SystemResource
>
listResourceRoles
();
List
<
SystemResource
>
listResourceRoles
();
...
...
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