Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
484785c2
Commit
484785c2
authored
Jul 07, 2023
by
Zheng Jie
Browse files
代码优化,避免【菜单、部门】移动节点时出现PID数据环形问题
close
https://github.com/elunez/eladmin/issues/803
parent
3aab1567
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/DeptController.java
View file @
484785c2
...
...
@@ -34,6 +34,7 @@ import org.springframework.validation.annotation.Validated;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author Zheng Jie
...
...
@@ -71,8 +72,15 @@ public class DeptController {
for
(
Long
id
:
ids
)
{
DeptDto
deptDto
=
deptService
.
findById
(
id
);
List
<
DeptDto
>
depts
=
deptService
.
getSuperior
(
deptDto
,
new
ArrayList
<>());
for
(
DeptDto
dept
:
depts
)
{
if
(
dept
.
getId
().
equals
(
deptDto
.
getPid
()))
{
dept
.
setSubCount
(
dept
.
getSubCount
()
-
1
);
}
}
deptSet
.
addAll
(
depts
);
}
// 编辑部门时不显示自己以及自己下级的数据,避免出现PID数据环形问题
deptSet
=
deptSet
.
stream
().
filter
(
i
->
!
ids
.
contains
(
i
.
getId
())).
collect
(
Collectors
.
toSet
());
return
new
ResponseEntity
<>(
deptService
.
buildTree
(
new
ArrayList
<>(
deptSet
)),
HttpStatus
.
OK
);
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/MenuController.java
View file @
484785c2
...
...
@@ -24,6 +24,7 @@ import me.zhengjie.modules.system.domain.Menu;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.system.domain.vo.MenuVo
;
import
me.zhengjie.modules.system.service.MenuService
;
import
me.zhengjie.modules.system.service.dto.DeptDto
;
import
me.zhengjie.modules.system.service.dto.MenuDto
;
import
me.zhengjie.modules.system.service.dto.MenuQueryCriteria
;
import
me.zhengjie.modules.system.service.mapstruct.MenuMapper
;
...
...
@@ -43,7 +44,6 @@ import java.util.stream.Collectors;
* @author Zheng Jie
* @date 2018-12-03
*/
@RestController
@RequiredArgsConstructor
@Api
(
tags
=
"系统:菜单管理"
)
...
...
@@ -104,8 +104,16 @@ public class MenuController {
if
(
CollectionUtil
.
isNotEmpty
(
ids
)){
for
(
Long
id
:
ids
)
{
MenuDto
menuDto
=
menuService
.
findById
(
id
);
menuDtos
.
addAll
(
menuService
.
getSuperior
(
menuDto
,
new
ArrayList
<>()));
List
<
MenuDto
>
menuDtoList
=
menuService
.
getSuperior
(
menuDto
,
new
ArrayList
<>());
for
(
MenuDto
menu
:
menuDtoList
)
{
if
(
menu
.
getId
().
equals
(
menuDto
.
getPid
()))
{
menu
.
setSubCount
(
menu
.
getSubCount
()
-
1
);
}
}
menuDtos
.
addAll
(
menuDtoList
);
}
// 编辑菜单时不显示自己以及自己下级的数据,避免出现PID数据环形问题
menuDtos
=
menuDtos
.
stream
().
filter
(
i
->
!
ids
.
contains
(
i
.
getId
())).
collect
(
Collectors
.
toSet
());
return
new
ResponseEntity
<>(
menuService
.
buildTree
(
new
ArrayList
<>(
menuDtos
)),
HttpStatus
.
OK
);
}
return
new
ResponseEntity
<>(
menuService
.
getMenus
(
null
),
HttpStatus
.
OK
);
...
...
Write
Preview
Supports
Markdown
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