Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
ae47bf7e
提交
ae47bf7e
authored
7月 09, 2019
作者:
xiaofeng
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
83d8bc4f
f3abed3a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
14 行删除
+33
-14
DeptmentController.java
...min/application/controller/admins/DeptmentController.java
+33
-14
没有找到文件。
system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java
浏览文件 @
ae47bf7e
...
@@ -10,6 +10,7 @@ import cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO;
...
@@ -10,6 +10,7 @@ import cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO
;
import
cn.iocoder.mall.admin.application.convert.DeptmentConvert
;
import
cn.iocoder.mall.admin.application.convert.DeptmentConvert
;
import
cn.iocoder.mall.admin.application.vo.deptment.DeptmentVO
;
import
cn.iocoder.mall.admin.application.vo.deptment.DeptmentVO
;
import
cn.iocoder.mall.admin.application.vo.resource.ResourceTreeNodeVO
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContext
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContext
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
...
@@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -21,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -42,6 +44,19 @@ public class DeptmentController {
...
@@ -42,6 +44,19 @@ public class DeptmentController {
@Autowired
@Autowired
private
DeptmentService
deptmentService
;
private
DeptmentService
deptmentService
;
@GetMapping
(
"tree/all"
)
@ApiOperation
(
value
=
"根部门的部门树"
)
public
CommonResult
<
List
<
DeptmentVO
>>
treeAll
(){
List
<
DeptmentBO
>
list
=
deptmentService
.
getAllDeptments
();
List
<
DeptmentVO
>
voList
=
DeptmentConvert
.
INSTANCE
.
convert
(
list
);
Map
<
Integer
,
DeptmentVO
>
nodeMap
=
calaNodeMap
(
voList
);
// 获得到所有的根节点
List
<
DeptmentVO
>
rootNodes
=
nodeMap
.
values
().
stream
()
.
filter
(
node
->
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
collect
(
Collectors
.
toList
());
return
success
(
rootNodes
);
}
@GetMapping
(
"tree/page"
)
@GetMapping
(
"tree/page"
)
@ApiOperation
(
value
=
"根部门分页的部门树"
)
@ApiOperation
(
value
=
"根部门分页的部门树"
)
public
CommonResult
<
PageResult
<
DeptmentVO
>>
treePage
(
@Validated
DeptmentPageDTO
deptmentPageDTO
){
public
CommonResult
<
PageResult
<
DeptmentVO
>>
treePage
(
@Validated
DeptmentPageDTO
deptmentPageDTO
){
...
@@ -49,20 +64,7 @@ public class DeptmentController {
...
@@ -49,20 +64,7 @@ public class DeptmentController {
PageResult
<
DeptmentVO
>
voPageResult
=
DeptmentConvert
.
INSTANCE
.
convert
(
pageResult
);
PageResult
<
DeptmentVO
>
voPageResult
=
DeptmentConvert
.
INSTANCE
.
convert
(
pageResult
);
List
<
DeptmentBO
>
list
=
deptmentService
.
getAllDeptments
();
List
<
DeptmentBO
>
list
=
deptmentService
.
getAllDeptments
();
List
<
DeptmentVO
>
voList
=
DeptmentConvert
.
INSTANCE
.
convert
(
list
);
List
<
DeptmentVO
>
voList
=
DeptmentConvert
.
INSTANCE
.
convert
(
list
);
Map
<
Integer
,
DeptmentVO
>
nodeMap
=
voList
.
stream
().
collect
(
Collectors
.
toMap
(
e
->
e
.
getId
(),
e
->
e
));
Map
<
Integer
,
DeptmentVO
>
nodeMap
=
calaNodeMap
(
voList
);
nodeMap
.
values
().
stream
()
.
filter
(
node
->
!
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
forEach
((
childNode
)
->
{
// 获得父节点
DeptmentVO
parentNode
=
nodeMap
.
get
(
childNode
.
getPid
());
if
(
parentNode
.
getChildren
()
==
null
)
{
// 初始化 children 数组
parentNode
.
setChildren
(
new
ArrayList
<>());
}
// 将自己添加到父节点中
parentNode
.
getChildren
().
add
(
childNode
);
});
voPageResult
.
getList
().
forEach
(
d
->{
voPageResult
.
getList
().
forEach
(
d
->{
d
.
setChildren
(
nodeMap
.
get
(
d
.
getId
()).
getChildren
());
d
.
setChildren
(
nodeMap
.
get
(
d
.
getId
()).
getChildren
());
});
});
...
@@ -95,5 +97,22 @@ public class DeptmentController {
...
@@ -95,5 +97,22 @@ public class DeptmentController {
));
));
}
}
private
Map
<
Integer
,
DeptmentVO
>
calaNodeMap
(
List
<
DeptmentVO
>
voList
){
Map
<
Integer
,
DeptmentVO
>
nodeMap
=
voList
.
stream
().
collect
(
Collectors
.
toMap
(
e
->
e
.
getId
(),
e
->
e
));
nodeMap
.
values
().
stream
()
.
filter
(
node
->
!
node
.
getPid
().
equals
(
ResourceConstants
.
PID_ROOT
))
.
forEach
((
childNode
)
->
{
// 获得父节点
DeptmentVO
parentNode
=
nodeMap
.
get
(
childNode
.
getPid
());
if
(
parentNode
.
getChildren
()
==
null
)
{
// 初始化 children 数组
parentNode
.
setChildren
(
new
ArrayList
<>());
}
// 将自己添加到父节点中
parentNode
.
getChildren
().
add
(
childNode
);
});
return
nodeMap
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论