Skip to content

Commit 00f7f25

Browse files
committed
代码优化,避免【菜单、部门】移动节点时出现PID数据环形问题
close elunez#803
1 parent 484785c commit 00f7f25

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

eladmin-system/src/main/java/me/zhengjie/modules/system/rest/DeptController.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,23 @@ public ResponseEntity<PageResult<DeptDto>> queryDept(DeptQueryCriteria criteria)
6767
@ApiOperation("查询部门:根据ID获取同级与上级数据")
6868
@PostMapping("/superior")
6969
@PreAuthorize("@el.check('user:list','dept:list')")
70-
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids) {
70+
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids,
71+
@RequestParam(defaultValue = "false") Boolean exclude) {
7172
Set<DeptDto> deptSet = new LinkedHashSet<>();
7273
for (Long id : ids) {
7374
DeptDto deptDto = deptService.findById(id);
7475
List<DeptDto> depts = deptService.getSuperior(deptDto, new ArrayList<>());
75-
for (DeptDto dept : depts) {
76-
if(dept.getId().equals(deptDto.getPid())) {
77-
dept.setSubCount(dept.getSubCount() - 1);
76+
if(exclude){
77+
for (DeptDto dept : depts) {
78+
if(dept.getId().equals(deptDto.getPid())) {
79+
dept.setSubCount(dept.getSubCount() - 1);
80+
}
7881
}
82+
// 编辑部门时不显示自己以及自己下级的数据,避免出现PID数据环形问题
83+
depts = depts.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toList());
7984
}
8085
deptSet.addAll(depts);
8186
}
82-
// 编辑部门时不显示自己以及自己下级的数据,避免出现PID数据环形问题
83-
deptSet = deptSet.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet());
8487
return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptSet)),HttpStatus.OK);
8588
}
8689

0 commit comments

Comments
 (0)