Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
5b07634c
提交
5b07634c
authored
3月 02, 2019
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改管理员和角色拥有的授权~
上级
b3b3b815
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
133 行增加
和
19 行删除
+133
-19
AdminController.java
...er/mall/admin/application/controller/AdminController.java
+12
-5
RoleController.java
...der/mall/admin/application/controller/RoleController.java
+10
-4
AdminConvert.java
.../iocoder/mall/admin/application/convert/AdminConvert.java
+8
-0
AdminRoleVO.java
...ava/cn/iocoder/mall/admin/application/vo/AdminRoleVO.java
+44
-0
RoleResourceTreeNodeVO.java
...der/mall/admin/application/vo/RoleResourceTreeNodeVO.java
+11
-0
RoleService.java
.../src/main/java/cn/iocoder/mall/admin/api/RoleService.java
+12
-1
RoleMapper.java
...l/src/main/java/cn/iocoder/mall/admin/dao/RoleMapper.java
+3
-0
RoleServiceImpl.java
...n/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java
+10
-2
RoleMapper.xml
...min-service-impl/src/main/resources/mapper/RoleMapper.xml
+8
-0
RoleResourceMapper.xml
...ice-impl/src/main/resources/mapper/RoleResourceMapper.xml
+6
-6
CollectionUtil.java
...java/cn/iocoder/common/framework/util/CollectionUtil.java
+9
-1
没有找到文件。
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/AdminController.java
浏览文件 @
5b07634c
...
...
@@ -6,6 +6,7 @@ import cn.iocoder.mall.admin.api.ResourceService;
import
cn.iocoder.mall.admin.api.RoleService
;
import
cn.iocoder.mall.admin.api.bo.AdminPageBO
;
import
cn.iocoder.mall.admin.api.bo.ResourceBO
;
import
cn.iocoder.mall.admin.api.bo.RoleBO
;
import
cn.iocoder.mall.admin.api.constant.ResourceConstants
;
import
cn.iocoder.mall.admin.api.dto.AdminAddDTO
;
import
cn.iocoder.mall.admin.api.dto.AdminPageDTO
;
...
...
@@ -14,8 +15,8 @@ import cn.iocoder.mall.admin.application.convert.AdminConvert;
import
cn.iocoder.mall.admin.application.convert.ResourceConvert
;
import
cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO
;
import
cn.iocoder.mall.admin.application.vo.AdminPageVO
;
import
cn.iocoder.mall.admin.application.vo.AdminRoleVO
;
import
cn.iocoder.mall.admin.application.vo.AdminVO
;
import
cn.iocoder.mall.admin.application.vo.RoleVO
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder
;
import
com.alibaba.dubbo.config.annotation.Reference
;
import
io.swagger.annotations.Api
;
...
...
@@ -143,10 +144,16 @@ public class AdminController {
@GetMapping
(
"/role_list"
)
@ApiOperation
(
value
=
"指定管理员拥有的角色列表"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"管理员编号"
,
required
=
true
,
example
=
"1"
)
public
CommonResult
<
List
<
RoleVO
>>
roleList
(
@RequestParam
(
"id"
)
Integer
id
)
{
// return RoleConvert.INSTANCE.convert()
// TODO 需要讨论下 api 提供的方式
return
null
;
public
CommonResult
<
List
<
AdminRoleVO
>>
roleList
(
@RequestParam
(
"id"
)
Integer
id
)
{
// 获得管理员拥有的角色集合
Set
<
Integer
>
adminRoleIdSet
=
roleService
.
getRoleList
(
id
).
getData
();
// 获得所有角色数组
List
<
RoleBO
>
allRoleList
=
roleService
.
getRoleList
().
getData
();
// 转换出返回结果
List
<
AdminRoleVO
>
result
=
AdminConvert
.
INSTANCE
.
convert
(
allRoleList
);
// 设置每个角色是否赋予给改管理员
result
.
forEach
(
adminRoleVO
->
adminRoleVO
.
setAssigned
(
adminRoleIdSet
.
contains
(
adminRoleVO
.
getId
())));
return
CommonResult
.
success
(
result
);
}
@PostMapping
(
"/assign_role"
)
...
...
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/RoleController.java
浏览文件 @
5b07634c
package
cn
.
iocoder
.
mall
.
admin
.
application
.
controller
;
import
cn.iocoder.common.framework.util.CollectionUtil
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.admin.api.ResourceService
;
import
cn.iocoder.mall.admin.api.RoleService
;
...
...
@@ -82,11 +83,13 @@ public class RoleController {
@ApiImplicitParam
(
name
=
"id"
,
value
=
"角色编号"
,
required
=
true
,
example
=
"1"
)
public
CommonResult
<
List
<
RoleResourceTreeNodeVO
>>
resourceTree
(
@RequestParam
(
"id"
)
Integer
id
)
{
// 芋艿:此处,严格来说可以在校验下角色是否存在。不过呢,校验了也没啥意义,因为一般不存在这个情况,且不会有业务上的影响。并且,反倒多了一次 rpc 调用。
Set
<
Integer
>
roleIds
=
new
HashSet
<>();
roleIds
.
add
(
id
);
List
<
ResourceBO
>
resources
=
resourceService
.
getResourcesByTypeAndRoleIds
(
null
,
roleIds
);
// 第一步,获得角色拥有的资源数组
Set
<
Integer
>
roleResources
=
resourceService
.
getResourcesByTypeAndRoleIds
(
null
,
CollectionUtil
.
asSet
(
id
))
.
stream
().
map
(
ResourceBO:
:
getId
).
collect
(
Collectors
.
toSet
());
// 第二步,获得资源树
List
<
ResourceBO
>
allResources
=
resourceService
.
getResourcesByType
(
null
);
// 创建 AdminMenuTreeNodeVO Map
Map
<
Integer
,
RoleResourceTreeNodeVO
>
treeNodeMap
=
r
esources
.
stream
().
collect
(
Collectors
.
toMap
(
ResourceBO:
:
getId
,
ResourceConvert
.
INSTANCE
::
convert4
));
Map
<
Integer
,
RoleResourceTreeNodeVO
>
treeNodeMap
=
allR
esources
.
stream
().
collect
(
Collectors
.
toMap
(
ResourceBO:
:
getId
,
ResourceConvert
.
INSTANCE
::
convert4
));
// 处理父子关系
treeNodeMap
.
values
().
stream
()
.
filter
(
node
->
!
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
...
...
@@ -104,6 +107,9 @@ public class RoleController {
.
filter
(
node
->
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
sorted
(
Comparator
.
comparing
(
RoleResourceTreeNodeVO:
:
getSort
))
.
collect
(
Collectors
.
toList
());
// 第三步,设置角色是否有该角色
treeNodeMap
.
values
().
forEach
(
nodeVO
->
nodeVO
.
setAssigned
(
roleResources
.
contains
(
nodeVO
.
getId
())));
// 返回结果
return
CommonResult
.
success
(
rootNodes
);
}
...
...
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/AdminConvert.java
浏览文件 @
5b07634c
...
...
@@ -3,14 +3,18 @@ package cn.iocoder.mall.admin.application.convert;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.admin.api.bo.AdminBO
;
import
cn.iocoder.mall.admin.api.bo.AdminPageBO
;
import
cn.iocoder.mall.admin.api.bo.RoleBO
;
import
cn.iocoder.mall.admin.application.vo.AdminInfoVO
;
import
cn.iocoder.mall.admin.application.vo.AdminPageVO
;
import
cn.iocoder.mall.admin.application.vo.AdminRoleVO
;
import
cn.iocoder.mall.admin.application.vo.AdminVO
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContext
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mappings
;
import
org.mapstruct.factory.Mappers
;
import
java.util.List
;
@Mapper
public
interface
AdminConvert
{
...
...
@@ -28,4 +32,7 @@ public interface AdminConvert {
@Mappings
({})
CommonResult
<
AdminPageVO
>
convert
(
CommonResult
<
AdminPageBO
>
result
);
@Mappings
({})
List
<
AdminRoleVO
>
convert
(
List
<
RoleBO
>
roleList
);
}
\ No newline at end of file
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminRoleVO.java
0 → 100644
浏览文件 @
5b07634c
package
cn
.
iocoder
.
mall
.
admin
.
application
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
@ApiModel
(
"管理员拥有的角色 VO"
)
public
class
AdminRoleVO
{
@ApiModelProperty
(
value
=
"角色编号"
,
required
=
true
,
example
=
"1"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"角色名字"
,
required
=
true
,
example
=
"系统管理员"
)
private
String
name
;
@ApiModelProperty
(
value
=
"是否授权"
,
required
=
true
,
example
=
"true"
)
private
Boolean
assigned
;
public
Integer
getId
()
{
return
id
;
}
public
AdminRoleVO
setId
(
Integer
id
)
{
this
.
id
=
id
;
return
this
;
}
public
String
getName
()
{
return
name
;
}
public
AdminRoleVO
setName
(
String
name
)
{
this
.
name
=
name
;
return
this
;
}
public
Boolean
getAssigned
()
{
return
assigned
;
}
public
AdminRoleVO
setAssigned
(
Boolean
assigned
)
{
this
.
assigned
=
assigned
;
return
this
;
}
}
\ No newline at end of file
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/RoleResourceTreeNodeVO.java
浏览文件 @
5b07634c
...
...
@@ -22,6 +22,8 @@ public class RoleResourceTreeNodeVO {
private
String
displayName
;
@ApiModelProperty
(
value
=
"子节点数组"
)
private
List
<
RoleResourceTreeNodeVO
>
children
;
@ApiModelProperty
(
value
=
"是否授权"
,
required
=
true
,
example
=
"true"
)
private
Boolean
assigned
;
public
Integer
getId
()
{
return
id
;
...
...
@@ -77,4 +79,12 @@ public class RoleResourceTreeNodeVO {
return
this
;
}
public
Boolean
getAssigned
()
{
return
assigned
;
}
public
RoleResourceTreeNodeVO
setAssigned
(
Boolean
assigned
)
{
this
.
assigned
=
assigned
;
return
this
;
}
}
\ No newline at end of file
admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/RoleService.java
浏览文件 @
5b07634c
...
...
@@ -14,7 +14,18 @@ public interface RoleService {
CommonResult
<
RolePageBO
>
getRolePage
(
RolePageDTO
rolePageDTO
);
CommonResult
<
List
<
RoleBO
>>
getRoleList
(
Integer
adminId
);
/**
* 获得指定管理员拥有的角色编号数组
*
* @param adminId 指定管理员
* @return 角色编号数组
*/
CommonResult
<
Set
<
Integer
>>
getRoleList
(
Integer
adminId
);
/**
* @return 返回角色列表
*/
CommonResult
<
List
<
RoleBO
>>
getRoleList
();
CommonResult
<
RoleBO
>
addRole
(
Integer
adminId
,
RoleAddDTO
roleAddDTO
);
...
...
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/dao/RoleMapper.java
浏览文件 @
5b07634c
...
...
@@ -24,4 +24,6 @@ public interface RoleMapper {
List
<
RoleDO
>
selectListByIds
(
@Param
(
"ids"
)
Set
<
Integer
>
ids
);
List
<
RoleDO
>
selectList
();
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/RoleServiceImpl.java
浏览文件 @
5b07634c
...
...
@@ -15,6 +15,7 @@ import cn.iocoder.mall.admin.convert.RoleConvert;
import
cn.iocoder.mall.admin.dao.AdminRoleMapper
;
import
cn.iocoder.mall.admin.dao.RoleMapper
;
import
cn.iocoder.mall.admin.dao.RoleResourceMapper
;
import
cn.iocoder.mall.admin.dataobject.AdminRoleDO
;
import
cn.iocoder.mall.admin.dataobject.ResourceDO
;
import
cn.iocoder.mall.admin.dataobject.RoleDO
;
import
cn.iocoder.mall.admin.dataobject.RoleResourceDO
;
...
...
@@ -63,8 +64,15 @@ public class RoleServiceImpl implements RoleService {
}
@Override
public
CommonResult
<
List
<
RoleBO
>>
getRoleList
(
Integer
adminId
)
{
return
null
;
public
CommonResult
<
Set
<
Integer
>>
getRoleList
(
Integer
adminId
)
{
List
<
AdminRoleDO
>
adminRoleDOs
=
adminRoleMapper
.
selectByAdminId
(
adminId
);
return
CommonResult
.
success
(
adminRoleDOs
.
stream
().
map
(
AdminRoleDO:
:
getRoleId
).
collect
(
Collectors
.
toSet
()));
}
@Override
public
CommonResult
<
List
<
RoleBO
>>
getRoleList
()
{
List
<
RoleDO
>
roleList
=
roleMapper
.
selectList
();
return
CommonResult
.
success
(
RoleConvert
.
INSTANCE
.
convert
(
roleList
));
}
@Override
...
...
admin/admin-service-impl/src/main/resources/mapper/RoleMapper.xml
浏览文件 @
5b07634c
...
...
@@ -71,4 +71,11 @@
AND deleted = 0
</select>
<select
id=
"selectList"
resultType=
"RoleDO"
>
SELECT
<include
refid=
"FIELDS"
/>
FROM role
WHERE deleted = 0
</select>
</mapper>
\ No newline at end of file
admin/admin-service-impl/src/main/resources/mapper/RoleResourceMapper.xml
浏览文件 @
5b07634c
...
...
@@ -11,12 +11,12 @@
<!--</insert>-->
<select
id=
"selectByResourceHandler"
parameterType=
"String"
resultType=
"RoleResourceDO"
>
SELECT
rr.id, rr.role_id, rr.resource_id
FROM resource r, role_resource rr
WHERE r.handler = #{resourceHandler}
AND r.id = rr.resource_id
AND rr.deleted = 0;
SELECT
rr.id, rr.role_id, rr.resource_id
FROM resource r, role_resource rr
WHERE r.handler = #{resourceHandler}
AND r.id = rr.resource_id
AND rr.deleted = 0;
</select>
<select
id=
"selectByResourceId"
parameterType=
"Integer"
resultType=
"RoleResourceDO"
>
...
...
common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java
浏览文件 @
5b07634c
package
cn
.
iocoder
.
common
.
framework
.
util
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
CollectionUtil
{
...
...
@@ -8,4 +11,8 @@ public class CollectionUtil {
return
collection
==
null
||
collection
.
isEmpty
();
}
}
public
static
<
T
>
Set
<
T
>
asSet
(
T
...
objs
)
{
return
new
HashSet
<>(
Arrays
.
asList
(
objs
));
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论