Skip to content

Commit

Permalink
代码优化,避免【菜单、部门】移动节点时出现PID数据环形问题
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Jul 7, 2023
1 parent 484785c commit 00f7f25
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,23 @@ public ResponseEntity<PageResult<DeptDto>> queryDept(DeptQueryCriteria criteria)
@ApiOperation("查询部门:根据ID获取同级与上级数据")
@PostMapping("/superior")
@PreAuthorize("@el.check('user:list','dept:list')")
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids) {
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids,
@RequestParam(defaultValue = "false") Boolean exclude) {
Set<DeptDto> deptSet = new LinkedHashSet<>();
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);
if(exclude){
for (DeptDto dept : depts) {
if(dept.getId().equals(deptDto.getPid())) {
dept.setSubCount(dept.getSubCount() - 1);
}
}
// 编辑部门时不显示自己以及自己下级的数据,避免出现PID数据环形问题
depts = depts.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toList());
}
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);
}

Expand Down

0 comments on commit 00f7f25

Please sign in to comment.