Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
814ca633
提交
814ca633
authored
3月 01, 2019
作者:
sin
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
7a7ebde4
3b97b58d
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
340 行增加
和
44 行删除
+340
-44
ResourceController.java
...mall/admin/application/controller/ResourceController.java
+69
-21
ResourceConvert.java
...coder/mall/admin/application/convert/ResourceConvert.java
+14
-1
AdminMenuTreeNodeVO.java
...ocoder/mall/admin/application/vo/AdminMenuTreeNodeVO.java
+35
-20
ResourceTreeNodeVO.java
...iocoder/mall/admin/application/vo/ResourceTreeNodeVO.java
+113
-0
ResourceVO.java
...java/cn/iocoder/mall/admin/application/vo/ResourceVO.java
+101
-0
ResourceServiceImpl.java
...va/cn/iocoder/mall/admin/service/ResourceServiceImpl.java
+2
-0
ResourceMapper.xml
...service-impl/src/main/resources/mapper/ResourceMapper.xml
+6
-2
没有找到文件。
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/ResourceController.java
浏览文件 @
814ca633
...
...
@@ -8,16 +8,17 @@ import cn.iocoder.mall.admin.api.dto.ResourceAddDTO;
import
cn.iocoder.mall.admin.api.dto.ResourceUpdateDTO
;
import
cn.iocoder.mall.admin.application.convert.ResourceConvert
;
import
cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO
;
import
cn.iocoder.mall.admin.application.vo.ResourceTreeNodeVO
;
import
cn.iocoder.mall.admin.application.vo.ResourceVO
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder
;
import
com.alibaba.dubbo.config.annotation.Reference
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@RestController
...
...
@@ -30,6 +31,7 @@ public class ResourceController {
// =========== 当前管理员相关的资源 API ===========
@SuppressWarnings
(
"Duplicates"
)
@GetMapping
(
"/admin_menu_tree"
)
@ApiOperation
(
value
=
"获得当前登陆的管理员拥有的菜单权限"
,
notes
=
"以树结构返回"
)
public
CommonResult
<
List
<
AdminMenuTreeNodeVO
>>
adminMenuTree
()
{
...
...
@@ -37,21 +39,22 @@ public class ResourceController {
// 创建 AdminMenuTreeNodeVO Map
Map
<
Integer
,
AdminMenuTreeNodeVO
>
treeNodeMap
=
resources
.
stream
().
collect
(
Collectors
.
toMap
(
ResourceBO:
:
getId
,
ResourceConvert
.
INSTANCE
::
convert
));
// 处理父子关系
treeNodeMap
.
values
().
stream
()
.
filter
(
node
->
{
return
node
.
getPid
()
!=
0
;
// TODO magic number
})
.
forEach
((
childNode
)
->
{
// 获得父节点
AdminMenuTreeNodeVO
parentNode
=
treeNodeMap
.
get
(
childNode
.
getPid
());
if
(
parentNode
.
getChildren
()
==
null
)
{
// 初始化 children 数组
parentNode
.
setChildren
(
new
ArrayList
<>());
}
// 将自己添加到父节点中
parentNode
.
getChildren
().
add
(
childNode
);
});
treeNodeMap
.
values
().
stream
()
.
filter
(
node
->
!
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
forEach
((
childNode
)
->
{
// 获得父节点
AdminMenuTreeNodeVO
parentNode
=
treeNodeMap
.
get
(
childNode
.
getPid
());
if
(
parentNode
.
getChildren
()
==
null
)
{
// 初始化 children 数组
parentNode
.
setChildren
(
new
ArrayList
<>());
}
// 将自己添加到父节点中
parentNode
.
getChildren
().
add
(
childNode
);
});
// 获得到所有的根节点
List
<
AdminMenuTreeNodeVO
>
rootNodes
=
treeNodeMap
.
values
().
stream
().
filter
(
node
->
{
return
node
.
getPid
()
==
0
;
// TODO magic number
}).
collect
(
Collectors
.
toList
());
List
<
AdminMenuTreeNodeVO
>
rootNodes
=
treeNodeMap
.
values
().
stream
()
.
filter
(
node
->
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
sorted
(
Comparator
.
comparing
(
AdminMenuTreeNodeVO:
:
getSort
))
.
collect
(
Collectors
.
toList
());
return
CommonResult
.
success
(
rootNodes
);
}
...
...
@@ -65,10 +68,44 @@ public class ResourceController {
// =========== 资源管理 API ===========
// TODO 芋艿,注释
@SuppressWarnings
(
"Duplicates"
)
@GetMapping
(
"/tree"
)
@ApiOperation
(
value
=
"获得所有资源,按照树形结构返回"
)
public
CommonResult
<
List
<
ResourceTreeNodeVO
>>
tree
()
{
List
<
ResourceBO
>
resources
=
resourceService
.
getResourcesByType
(
null
);
// 创建 AdminMenuTreeNodeVO Map
Map
<
Integer
,
ResourceTreeNodeVO
>
treeNodeMap
=
resources
.
stream
().
collect
(
Collectors
.
toMap
(
ResourceBO:
:
getId
,
ResourceConvert
.
INSTANCE
::
convert2
));
// 处理父子关系
treeNodeMap
.
values
().
stream
()
.
filter
(
node
->
!
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
forEach
((
childNode
)
->
{
// 获得父节点
ResourceTreeNodeVO
parentNode
=
treeNodeMap
.
get
(
childNode
.
getPid
());
if
(
parentNode
.
getChildren
()
==
null
)
{
// 初始化 children 数组
parentNode
.
setChildren
(
new
ArrayList
<>());
}
// 将自己添加到父节点中
parentNode
.
getChildren
().
add
(
childNode
);
});
// 获得到所有的根节点
List
<
ResourceTreeNodeVO
>
rootNodes
=
treeNodeMap
.
values
().
stream
()
.
filter
(
node
->
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
sorted
(
Comparator
.
comparing
(
ResourceTreeNodeVO:
:
getSort
))
.
collect
(
Collectors
.
toList
());
return
CommonResult
.
success
(
rootNodes
);
}
@PostMapping
(
"/add"
)
@ApiOperation
(
value
=
"创建资源"
,
notes
=
"例如说,菜单资源,Url 资源"
)
public
CommonResult
<
ResourceBO
>
add
(
@RequestParam
(
"name"
)
String
name
,
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"name"
,
value
=
"资源名字(标识)"
,
required
=
true
,
example
=
"admin/info"
),
@ApiImplicitParam
(
name
=
"type"
,
value
=
"资源类型。1 代表【菜单】;2 代表【Url】"
,
required
=
true
,
example
=
"1"
),
@ApiImplicitParam
(
name
=
"sort"
,
value
=
"排序"
,
required
=
true
,
example
=
"1"
),
@ApiImplicitParam
(
name
=
"displayName"
,
value
=
"菜单展示名"
,
required
=
true
,
example
=
"商品管理"
),
@ApiImplicitParam
(
name
=
"pid"
,
value
=
"父级资源编号"
,
required
=
true
,
example
=
"1"
),
@ApiImplicitParam
(
name
=
"handler"
,
value
=
"操作"
,
required
=
true
,
example
=
"/order/list"
),
})
public
CommonResult
<
ResourceVO
>
add
(
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
"type"
)
Integer
type
,
@RequestParam
(
"sort"
)
Integer
sort
,
@RequestParam
(
"displayName"
)
String
displayName
,
...
...
@@ -76,10 +113,19 @@ public class ResourceController {
@RequestParam
(
"handler"
)
String
handler
)
{
ResourceAddDTO
resourceAddDTO
=
new
ResourceAddDTO
().
setName
(
name
).
setType
(
type
).
setSort
(
sort
)
.
setDisplayName
(
displayName
).
setPid
(
pid
).
setHandler
(
handler
);
return
resourceService
.
addResource
(
AdminSecurityContextHolder
.
getContext
().
getAdminId
(),
resourceAddDTO
);
return
ResourceConvert
.
INSTANCE
.
convert3
(
resourceService
.
addResource
(
AdminSecurityContextHolder
.
getContext
().
getAdminId
(),
resourceAddDTO
)
);
}
@PostMapping
(
"/update"
)
@ApiOperation
(
value
=
"更新资源"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"id"
,
value
=
"资源编号"
,
required
=
true
,
example
=
"1"
),
@ApiImplicitParam
(
name
=
"name"
,
value
=
"资源名字(标识)"
,
required
=
true
,
example
=
"admin/info"
),
@ApiImplicitParam
(
name
=
"sort"
,
value
=
"排序"
,
required
=
true
,
example
=
"1"
),
@ApiImplicitParam
(
name
=
"displayName"
,
value
=
"菜单展示名"
,
required
=
true
,
example
=
"商品管理"
),
@ApiImplicitParam
(
name
=
"pid"
,
value
=
"父级资源编号"
,
required
=
true
,
example
=
"1"
),
@ApiImplicitParam
(
name
=
"handler"
,
value
=
"操作"
,
required
=
true
,
example
=
"/order/list"
),
})
public
CommonResult
<
Boolean
>
update
(
@RequestParam
(
"id"
)
Integer
id
,
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
"sort"
)
Integer
sort
,
...
...
@@ -91,6 +137,8 @@ public class ResourceController {
}
@PostMapping
(
"/delete"
)
@ApiOperation
(
value
=
"删除资源"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"资源编号"
,
required
=
true
,
example
=
"1"
)
public
CommonResult
<
Boolean
>
delete
(
@RequestParam
(
"id"
)
Integer
id
)
{
return
resourceService
.
deleteResource
(
AdminSecurityContextHolder
.
getContext
().
getAdminId
(),
id
);
}
...
...
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/convert/ResourceConvert.java
浏览文件 @
814ca633
package
cn
.
iocoder
.
mall
.
admin
.
application
.
convert
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.admin.api.bo.ResourceBO
;
import
cn.iocoder.mall.admin.application.vo.AdminMenuTreeNodeVO
;
import
cn.iocoder.mall.admin.application.vo.ResourceTreeNodeVO
;
import
cn.iocoder.mall.admin.application.vo.ResourceVO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mappings
;
import
org.mapstruct.factory.Mappers
;
...
...
@@ -14,4 +17,13 @@ public interface ResourceConvert {
@Mappings
({})
AdminMenuTreeNodeVO
convert
(
ResourceBO
resourceBO
);
}
@Mappings
({})
ResourceTreeNodeVO
convert2
(
ResourceBO
resourceBO
);
@Mappings
({})
ResourceVO
convert3
(
ResourceBO
resourceBO
);
@Mappings
({})
CommonResult
<
ResourceVO
>
convert3
(
CommonResult
<
ResourceBO
>
resourceBO
);
}
\ No newline at end of file
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/AdminMenuTreeNodeVO.java
浏览文件 @
814ca633
...
...
@@ -10,13 +10,17 @@ public class AdminMenuTreeNodeVO {
@ApiModelProperty
(
value
=
"菜单编号"
,
required
=
true
,
example
=
"1"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"菜单名"
,
required
=
true
,
example
=
"商品管理"
)
private
String
name
;
//
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
//
private String name;
@ApiModelProperty
(
value
=
"菜单操作"
,
required
=
true
,
example
=
"/order/list"
)
private
String
handler
;
@ApiModelProperty
(
value
=
"父菜单编号"
,
required
=
true
,
example
=
"1"
,
notes
=
"如果无父菜单,则值为 0"
)
private
Integer
pid
;
@ApiModelProperty
(
value
=
"子节点数组"
,
example
=
"[1, 2, 3]"
)
@ApiModelProperty
(
value
=
"排序"
,
required
=
true
,
example
=
"1"
)
private
Integer
sort
;
@ApiModelProperty
(
value
=
"菜单展示名"
,
required
=
true
,
example
=
"商品管理"
)
private
String
displayName
;
@ApiModelProperty
(
value
=
"子节点数组"
)
private
List
<
AdminMenuTreeNodeVO
>
children
;
public
Integer
getId
()
{
...
...
@@ -28,39 +32,49 @@ public class AdminMenuTreeNodeVO {
return
this
;
}
public
String
get
Name
()
{
return
name
;
public
String
get
Handler
()
{
return
handler
;
}
public
AdminMenuTreeNodeVO
set
Name
(
String
name
)
{
this
.
name
=
name
;
public
AdminMenuTreeNodeVO
set
Handler
(
String
handler
)
{
this
.
handler
=
handler
;
return
this
;
}
public
String
getHandler
()
{
return
handler
;
public
Integer
getPid
()
{
return
pid
;
}
public
AdminMenuTreeNodeVO
set
Handler
(
String
handler
)
{
this
.
handler
=
handler
;
public
AdminMenuTreeNodeVO
set
Pid
(
Integer
pid
)
{
this
.
pid
=
pid
;
return
this
;
}
public
List
<
AdminMenuTreeNodeVO
>
getChildren
()
{
return
children
;
public
Integer
getSort
()
{
return
sort
;
}
public
AdminMenuTreeNodeVO
set
Children
(
List
<
AdminMenuTreeNodeVO
>
children
)
{
this
.
children
=
children
;
public
AdminMenuTreeNodeVO
set
Sort
(
Integer
sort
)
{
this
.
sort
=
sort
;
return
this
;
}
public
Integer
getPid
()
{
return
pid
;
public
String
getDisplayName
()
{
return
displayName
;
}
public
AdminMenuTreeNodeVO
set
Pid
(
Integer
pid
)
{
this
.
pid
=
pid
;
public
AdminMenuTreeNodeVO
set
DisplayName
(
String
displayName
)
{
this
.
displayName
=
displayName
;
return
this
;
}
}
public
List
<
AdminMenuTreeNodeVO
>
getChildren
()
{
return
children
;
}
public
AdminMenuTreeNodeVO
setChildren
(
List
<
AdminMenuTreeNodeVO
>
children
)
{
this
.
children
=
children
;
return
this
;
}
}
\ No newline at end of file
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceTreeNodeVO.java
0 → 100644
浏览文件 @
814ca633
package
cn
.
iocoder
.
mall
.
admin
.
application
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.Date
;
import
java.util.List
;
@ApiModel
(
"资源树结构 VO"
)
public
class
ResourceTreeNodeVO
{
@ApiModelProperty
(
value
=
"资源编号"
,
required
=
true
,
example
=
"1"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"资源名字(标识)"
,
required
=
true
,
example
=
"商品管理"
)
private
String
name
;
@ApiModelProperty
(
value
=
"资源类型"
,
required
=
true
,
example
=
"1"
)
private
Integer
type
;
@ApiModelProperty
(
value
=
"排序"
,
required
=
true
,
example
=
"1"
)
private
Integer
sort
;
@ApiModelProperty
(
value
=
"菜单展示名"
,
required
=
true
,
example
=
"商品管理"
)
private
String
displayName
;
@ApiModelProperty
(
value
=
"创建时间"
,
required
=
true
,
example
=
"时间戳格式"
)
private
Date
createTime
;
@ApiModelProperty
(
value
=
"父级资源编号"
,
required
=
true
,
example
=
"1"
,
notes
=
"如果无父资源,则值为 0"
)
private
Integer
pid
;
@ApiModelProperty
(
value
=
"操作"
,
required
=
true
,
example
=
"/order/list"
)
private
String
handler
;
@ApiModelProperty
(
value
=
"子节点数组"
)
private
List
<
ResourceTreeNodeVO
>
children
;
public
Integer
getId
()
{
return
id
;
}
public
ResourceTreeNodeVO
setId
(
Integer
id
)
{
this
.
id
=
id
;
return
this
;
}
public
String
getName
()
{
return
name
;
}
public
ResourceTreeNodeVO
setName
(
String
name
)
{
this
.
name
=
name
;
return
this
;
}
public
Integer
getType
()
{
return
type
;
}
public
ResourceTreeNodeVO
setType
(
Integer
type
)
{
this
.
type
=
type
;
return
this
;
}
public
Integer
getSort
()
{
return
sort
;
}
public
ResourceTreeNodeVO
setSort
(
Integer
sort
)
{
this
.
sort
=
sort
;
return
this
;
}
public
String
getDisplayName
()
{
return
displayName
;
}
public
ResourceTreeNodeVO
setDisplayName
(
String
displayName
)
{
this
.
displayName
=
displayName
;
return
this
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
ResourceTreeNodeVO
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
return
this
;
}
public
Integer
getPid
()
{
return
pid
;
}
public
ResourceTreeNodeVO
setPid
(
Integer
pid
)
{
this
.
pid
=
pid
;
return
this
;
}
public
String
getHandler
()
{
return
handler
;
}
public
ResourceTreeNodeVO
setHandler
(
String
handler
)
{
this
.
handler
=
handler
;
return
this
;
}
public
List
<
ResourceTreeNodeVO
>
getChildren
()
{
return
children
;
}
public
ResourceTreeNodeVO
setChildren
(
List
<
ResourceTreeNodeVO
>
children
)
{
this
.
children
=
children
;
return
this
;
}
}
\ No newline at end of file
admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/vo/ResourceVO.java
0 → 100644
浏览文件 @
814ca633
package
cn
.
iocoder
.
mall
.
admin
.
application
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.util.Date
;
@ApiModel
(
"资源 VO"
)
public
class
ResourceVO
{
@ApiModelProperty
(
value
=
"资源编号"
,
required
=
true
,
example
=
"1"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"资源名字(标识)"
,
required
=
true
,
example
=
"商品管理"
)
private
String
name
;
@ApiModelProperty
(
value
=
"资源类型"
,
required
=
true
,
example
=
"1"
)
private
Integer
type
;
@ApiModelProperty
(
value
=
"排序"
,
required
=
true
,
example
=
"1"
)
private
Integer
sort
;
@ApiModelProperty
(
value
=
"菜单展示名"
,
required
=
true
,
example
=
"商品管理"
)
private
String
displayName
;
@ApiModelProperty
(
value
=
"创建时间"
,
required
=
true
,
example
=
"时间戳格式"
)
private
Date
createTime
;
@ApiModelProperty
(
value
=
"父级资源编号"
,
required
=
true
,
example
=
"1"
,
notes
=
"如果无父资源,则值为 0"
)
private
Integer
pid
;
@ApiModelProperty
(
value
=
"操作"
,
required
=
true
,
example
=
"/order/list"
)
private
String
handler
;
public
Integer
getId
()
{
return
id
;
}
public
ResourceVO
setId
(
Integer
id
)
{
this
.
id
=
id
;
return
this
;
}
public
String
getName
()
{
return
name
;
}
public
ResourceVO
setName
(
String
name
)
{
this
.
name
=
name
;
return
this
;
}
public
Integer
getType
()
{
return
type
;
}
public
ResourceVO
setType
(
Integer
type
)
{
this
.
type
=
type
;
return
this
;
}
public
Integer
getSort
()
{
return
sort
;
}
public
ResourceVO
setSort
(
Integer
sort
)
{
this
.
sort
=
sort
;
return
this
;
}
public
String
getDisplayName
()
{
return
displayName
;
}
public
ResourceVO
setDisplayName
(
String
displayName
)
{
this
.
displayName
=
displayName
;
return
this
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
ResourceVO
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
return
this
;
}
public
Integer
getPid
()
{
return
pid
;
}
public
ResourceVO
setPid
(
Integer
pid
)
{
this
.
pid
=
pid
;
return
this
;
}
public
String
getHandler
()
{
return
handler
;
}
public
ResourceVO
setHandler
(
String
handler
)
{
this
.
handler
=
handler
;
return
this
;
}
}
\ No newline at end of file
admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/ResourceServiceImpl.java
浏览文件 @
814ca633
...
...
@@ -71,6 +71,8 @@ public class ResourceServiceImpl implements ResourceService {
ResourceDO
resource
=
ResourceConvert
.
INSTANCE
.
convert
(
resourceAddDTO
);
if
(
ResourceConstants
.
PID_ROOT
.
equals
(
resourceAddDTO
.
getPid
()))
{
// 根节点,必须没有操作
resource
.
setHandler
(
null
);
}
else
if
(!
resource
.
getHandler
().
startsWith
(
"/"
))
{
resource
.
setHandler
(
"/"
+
resource
.
getHandler
());
}
resource
.
setCreateTime
(
new
Date
());
resource
.
setDeleted
(
BaseDO
.
DELETED_NO
);
...
...
admin/admin-service-impl/src/main/resources/mapper/ResourceMapper.xml
浏览文件 @
814ca633
...
...
@@ -29,8 +29,12 @@
SELECT
<include
refid=
"FIELDS"
/>
FROM resource
WHERE type = #{type}
AND deleted = 0
<where>
<if
test=
"type != null"
>
type = #{type}
</if>
AND deleted = 0
</where>
</select>
<select
id=
"selectListByTypeAndRoleIds"
resultType=
"ResourceDO"
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论