Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
ece29de7
Commit
ece29de7
authored
Jun 02, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
菜单权限分配与角色分配
parent
e6d847b7
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
215 additions
and
343 deletions
+215
-343
portal-manager/doc/api.md
portal-manager/doc/api.md
+96
-294
portal-manager/src/main/java/com/mortals/xhx/module/menu/web/MenuController.java
.../java/com/mortals/xhx/module/menu/web/MenuController.java
+19
-0
portal-manager/src/main/java/com/mortals/xhx/module/role/service/RoleAuthService.java
.../com/mortals/xhx/module/role/service/RoleAuthService.java
+2
-2
portal-manager/src/main/java/com/mortals/xhx/module/role/service/RoleUserService.java
.../com/mortals/xhx/module/role/service/RoleUserService.java
+5
-2
portal-manager/src/main/java/com/mortals/xhx/module/role/service/impl/RoleAuthServiceImpl.java
...als/xhx/module/role/service/impl/RoleAuthServiceImpl.java
+35
-15
portal-manager/src/main/java/com/mortals/xhx/module/role/service/impl/RoleUserServiceImpl.java
...als/xhx/module/role/service/impl/RoleUserServiceImpl.java
+6
-23
portal-manager/src/main/java/com/mortals/xhx/module/role/web/RoleAuthController.java
...a/com/mortals/xhx/module/role/web/RoleAuthController.java
+4
-4
portal-manager/src/main/java/com/mortals/xhx/module/role/web/RoleUserController.java
...a/com/mortals/xhx/module/role/web/RoleUserController.java
+20
-0
portal-manager/src/main/java/com/mortals/xhx/module/user/model/vo/UserVo.java
...ain/java/com/mortals/xhx/module/user/model/vo/UserVo.java
+0
-2
portal-manager/src/test/java/com/mortals/httpclient/menu/MenuController.http
...test/java/com/mortals/httpclient/menu/MenuController.http
+6
-1
portal-manager/src/test/java/com/mortals/httpclient/role/RoleAuthController.http
.../java/com/mortals/httpclient/role/RoleAuthController.http
+11
-0
portal-manager/src/test/java/com/mortals/httpclient/role/RoleUserController.http
.../java/com/mortals/httpclient/role/RoleUserController.http
+11
-0
No files found.
portal-manager/doc/api.md
View file @
ece29de7
This diff is collapsed.
Click to expand it.
portal-manager/src/main/java/com/mortals/xhx/module/menu/web/MenuController.java
View file @
ece29de7
...
...
@@ -110,5 +110,24 @@ public class MenuController extends BaseCRUDJsonBodyMappingController<MenuServic
return
ret
.
toJSONString
();
}
/**
* 查询所有可用菜单(树)
*/
@PostMapping
(
value
=
"findAll"
)
public
String
findAll
()
{
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
try
{
List
<
MenuEntity
>
menuEntityList
=
this
.
service
.
findAllEnable
();
ret
.
put
(
KEY_RESULT_DATA
,
menuEntityList
);
}
catch
(
Exception
e
)
{
log
.
error
(
"更新错误"
,
e
);
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
e
.
getMessage
());
}
return
ret
.
toJSONString
();
}
}
\ No newline at end of file
portal-manager/src/main/java/com/mortals/xhx/module/role/service/RoleAuthService.java
View file @
ece29de7
...
...
@@ -15,7 +15,7 @@ import com.mortals.xhx.module.role.model.RoleAuthQuery;
public
interface
RoleAuthService
extends
ICRUDService
<
RoleAuthEntity
,
Long
>
{
/**
* 角色分配资源
* 角色分配
菜单
资源
*/
void
doDistributionSource
(
RoleAuthQuery
query
);
void
assignMenu
(
RoleAuthQuery
query
);
}
\ No newline at end of file
portal-manager/src/main/java/com/mortals/xhx/module/role/service/RoleUserService.java
View file @
ece29de7
...
...
@@ -12,7 +12,10 @@ import com.mortals.xhx.module.role.model.RoleUserQuery;
* @date 2022-05-25
*/
public
interface
RoleUserService
extends
ICRUDService
<
RoleUserEntity
,
Long
>{
void
doDistributionUser
(
RoleUserQuery
query
);
void
doDistributionRole
(
RoleUserQuery
query
);
/**
* 给用户分配角色
* @param query
*/
void
assignRoleToUser
(
RoleUserQuery
query
);
}
\ No newline at end of file
portal-manager/src/main/java/com/mortals/xhx/module/role/service/impl/RoleAuthServiceImpl.java
View file @
ece29de7
...
...
@@ -3,37 +3,57 @@ package com.mortals.xhx.module.role.service.impl;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.xhx.module.menu.model.MenuEntity
;
import
com.mortals.xhx.module.menu.model.MenuQuery
;
import
com.mortals.xhx.module.menu.service.MenuService
;
import
com.mortals.xhx.module.role.dao.RoleAuthDao
;
import
com.mortals.xhx.module.role.model.RoleAuthEntity
;
import
com.mortals.xhx.module.role.model.RoleAuthQuery
;
import
com.mortals.xhx.module.role.service.RoleAuthService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
(
"roleAuthService"
)
public
class
RoleAuthServiceImpl
extends
AbstractCRUDServiceImpl
<
RoleAuthDao
,
RoleAuthEntity
,
Long
>
implements
RoleAuthService
{
@Autowired
private
MenuService
menuService
;
@Override
public
void
doDistributionSource
(
RoleAuthQuery
query
)
{
// 删除角色资源老数据
public
void
assignMenu
(
RoleAuthQuery
query
)
{
Map
<
Long
,
MenuEntity
>
menuEntityMap
=
menuService
.
find
(
new
MenuQuery
()).
stream
().
collect
(
Collectors
.
toMap
(
x
->
x
.
getId
(),
y
->
y
));
// 删除角色菜单资源老数据
Long
roleId
=
query
.
getRoleId
();
Map
<
String
,
Object
>
condition
=
new
HashMap
<>();
condition
.
put
(
"roleId"
,
roleId
);
this
.
dao
.
delete
(
condition
);
List
<
RoleAuthEntity
>
list
=
new
ArrayList
<>();
// for (Long sourceId : query.getResourceIdList()) {
// RoleAuthEntity entity = new RoleAuthEntity();
// entity.setRoleId(roleId);
// entity.setResourceId(sourceId);
// list.add(entity);
// }
this
.
dao
.
insertBatch
(
list
);
Set
<
Long
>
curSet
=
query
.
getMenuIdList
().
stream
().
collect
(
Collectors
.
toSet
());
query
.
getMenuIdList
().
stream
().
forEach
(
item
->
{
buildMenus
(
curSet
,
menuEntityMap
.
get
(
item
),
menuEntityMap
);
});
List
<
RoleAuthEntity
>
list
=
curSet
.
stream
().
map
(
item
->
{
RoleAuthEntity
entity
=
new
RoleAuthEntity
();
entity
.
setRoleId
(
roleId
);
entity
.
setMenuId
(
item
);
return
entity
;
}).
collect
(
Collectors
.
toList
());
this
.
save
(
list
);
}
private
void
buildMenus
(
Set
<
Long
>
curSet
,
MenuEntity
menuEntity
,
Map
<
Long
,
MenuEntity
>
menuEntityMap
)
{
if
(!
ObjectUtils
.
isEmpty
(
menuEntity
))
{
if
(!
curSet
.
contains
(
menuEntity
.
getId
()))
{
curSet
.
add
(
menuEntity
.
getId
());
}
if
(!
ObjectUtils
.
isEmpty
(
menuEntity
.
getParentId
()))
{
buildMenus
(
curSet
,
menuEntityMap
.
get
(
menuEntity
.
getParentId
()),
menuEntityMap
);
}
}
}
}
\ No newline at end of file
portal-manager/src/main/java/com/mortals/xhx/module/role/service/impl/RoleUserServiceImpl.java
View file @
ece29de7
...
...
@@ -25,31 +25,14 @@ import java.util.Map;
public
class
RoleUserServiceImpl
extends
AbstractCRUDServiceImpl
<
RoleUserDao
,
RoleUserEntity
,
Long
>
implements
RoleUserService
{
@Override
public
void
doDistributionUser
(
RoleUserQuery
query
)
{
Long
roleId
=
query
.
getRoleId
();
// 删除角色对应的用户信息
Map
<
String
,
Object
>
condition
=
new
HashMap
<>(
1
);
condition
.
put
(
"roleId"
,
roleId
);
dao
.
delete
(
condition
);
List
<
Long
>
userIdList
=
query
.
getUserIdList
();
List
<
RoleUserEntity
>
list
=
new
ArrayList
<>();
for
(
Long
userId
:
userIdList
)
{
RoleUserEntity
rolseUser
=
new
RoleUserEntity
();
rolseUser
.
setRoleId
(
roleId
);
rolseUser
.
setUserId
(
userId
);
list
.
add
(
rolseUser
);
}
this
.
dao
.
insertBatch
(
list
);
}
@Override
public
void
doDistributionRole
(
RoleUserQuery
query
)
{
// 删除角色对应的用户信息
public
void
assignRoleToUser
(
RoleUserQuery
query
)
{
//删除当前用户所有关联角色
Long
userId
=
query
.
getUserId
();
Map
<
String
,
Object
>
condition
=
new
HashMap
<>(
1
);
condition
.
put
(
"userId"
,
userId
);
dao
.
delete
(
condition
);
//新增用户角色
List
<
Long
>
roleIdList
=
query
.
getRoleIdList
();
List
<
RoleUserEntity
>
list
=
new
ArrayList
<>();
for
(
Long
roleId
:
roleIdList
)
{
...
...
@@ -58,7 +41,7 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, Ro
rolseUser
.
setUserId
(
userId
);
list
.
add
(
rolseUser
);
}
this
.
dao
.
insertBatch
(
list
);
this
.
save
(
list
);
}
}
\ No newline at end of file
portal-manager/src/main/java/com/mortals/xhx/module/role/web/RoleAuthController.java
View file @
ece29de7
...
...
@@ -38,12 +38,12 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
}
/**
* 分配菜单
* 分配菜单
到角色
*/
@PostMapping
(
value
=
"
distributionSourc
e"
)
public
String
distributionUser
(
@RequestBody
RoleAuthQuery
query
)
{
@PostMapping
(
value
=
"
assignMenuToRol
e"
)
public
String
assignMenuToRole
(
@RequestBody
RoleAuthQuery
query
)
{
try
{
service
.
doDistributionSource
(
query
);
service
.
assignMenu
(
query
);
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
return
ret
.
toJSONString
();
...
...
portal-manager/src/main/java/com/mortals/xhx/module/role/web/RoleUserController.java
View file @
ece29de7
...
...
@@ -55,4 +55,24 @@ public class RoleUserController extends BaseCRUDJsonBodyMappingController<RoleUs
}
/**
* 给用户分配角色
*/
@PostMapping
(
value
=
"assignRoleToUser"
)
public
String
assignRoleToUser
(
@RequestBody
RoleUserQuery
query
)
{
JSONObject
ret
=
new
JSONObject
();
try
{
this
.
service
.
assignRoleToUser
(
query
);
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
ret
.
put
(
KEY_RESULT_MSG
,
"分配角色成功!"
);
recordSysLog
(
request
,
getCurUser
(),
"分配角色成功!"
);
return
ret
.
toJSONString
();
}
catch
(
Exception
e
)
{
log
.
error
(
"分配角色错误"
,
e
);
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
ret
.
put
(
KEY_RESULT_MSG
,
super
.
convertException
(
e
));
return
ret
.
toJSONString
();
}
}
}
\ No newline at end of file
portal-manager/src/main/java/com/mortals/xhx/module/user/model/vo/UserVo.java
View file @
ece29de7
...
...
@@ -48,6 +48,4 @@ public class UserVo extends BaseEntityLong {
/** 查询条件 */
private
String
query
;
/** 角色id */
private
Long
roleId
;
}
\ No newline at end of file
portal-manager/src/test/java/com/mortals/httpclient/menu/MenuController.http
View file @
ece29de7
...
...
@@ -6,7 +6,8 @@ Content-Type: application/json
{
"page":1,
"size":10
"size":10,
"parentId":2
}
...
...
@@ -47,5 +48,9 @@ Authorization: {{authToken}}
Accept: application/json
###菜单信息业务列表
POST {{baseUrl}}/menu/findAll
Authorization: {{authToken}}
Content-Type: application/json
portal-manager/src/test/java/com/mortals/httpclient/role/RoleAuthController.http
View file @
ece29de7
...
...
@@ -10,6 +10,17 @@ Content-Type: application/json
}
###分配菜单到角色
POST {{baseUrl}}/role/auth/assignMenuToRole
Authorization: {{authToken}}
Content-Type: application/json
{
"roleId":2,
"menuIdList":[2]
}
###角色菜单权限关联更新与保存
POST {{baseUrl}}/role/auth/save
Authorization: {{authToken}}
...
...
portal-manager/src/test/java/com/mortals/httpclient/role/RoleUserController.http
View file @
ece29de7
...
...
@@ -10,6 +10,17 @@ Content-Type: application/json
}
###分配用户到角色
POST {{baseUrl}}/role/user/assignRoleToUser
Authorization: {{authToken}}
Content-Type: application/json
{
"userId":1,
"roleIdList":[1,2]
}
###角色用户关联更新与保存
POST {{baseUrl}}/role/user/save
Authorization: {{authToken}}
...
...
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