Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG:查询部门:根据ID获取同级与上级数据 #842

Open
NM1024 opened this issue Apr 22, 2024 · 0 comments
Open

BUG:查询部门:根据ID获取同级与上级数据 #842

NM1024 opened this issue Apr 22, 2024 · 0 comments

Comments

@NM1024
Copy link

NM1024 commented Apr 22, 2024

system/dept.js

export function getDeptSuperior(ids, exclude) {
  exclude = exclude !== undefined ? exclude : false
  
  // 修改后
  const data = Array.isArray(ids) || ids.length === 0 ? ids : Array.of(ids)
  // 原来的,再某些情况下参数无法以数组的形式传递给后端
  // const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
  debugger
  return request({
    url: 'api/dept/superior?exclude=' + exclude,
    method: 'post',
    data
  })
}

对应的后端APIsystem/rest/DeptController

   @ApiOperation("查询部门:根据ID获取同级与上级数据")
    @PostMapping("/superior")
    @PreAuthorize("@el.check('user:list','dept:list','coreuser:list')")
    public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids,
                                                  @RequestParam(defaultValue = "false") Boolean exclude) {
        Set<Dept> deptSet = new LinkedHashSet<>();
        for (Long id : ids) {
            Dept dept = deptService.findById(id);
            List<Dept> depts = deptService.getSuperior(dept, new ArrayList<>());
            if (exclude) {
                for (Dept data : depts) {
                    if (data.getId().equals(dept.getPid())) {
                        data.setSubCount(data.getSubCount() - 1);
                    }
                }
                // 编辑部门时不显示自己以及自己下级的数据,避免出现PID数据环形问题
                depts = depts.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toList());
            }
            deptSet.addAll(depts);
        }
        return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptSet)), HttpStatus.OK);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant