From c3395b65092412186b87a9b68ebc93eb0fadef80 Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Thu, 26 May 2022 10:04:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E6=9F=A5=E9=83=A8=E9=97=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/department/bo/DepartmentBO.java | 37 +++++-------------- .../param/QuerySingleDeptListParam.java | 2 +- .../department/vo/SingleDeptTreeVO.java | 4 ++ .../mapper/department/DepartmentMapper.java | 2 +- .../mapper/department/DepartmentMapper.xml | 3 +- .../service/impl/DepartmentServiceImpl.java | 6 +-- 6 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/com/engine/organization/entity/department/bo/DepartmentBO.java b/src/com/engine/organization/entity/department/bo/DepartmentBO.java index d07d15ab..18fced97 100644 --- a/src/com/engine/organization/entity/department/bo/DepartmentBO.java +++ b/src/com/engine/organization/entity/department/bo/DepartmentBO.java @@ -72,23 +72,28 @@ public class DepartmentBO { .creator(employeeId).build(); } - public static List buildSingleDeptTreeVOS(List departmentPOs) { + public static List buildSingleDeptTreeVOS(List departmentPOs,Long parentComp) { if (CollectionUtils.isEmpty(departmentPOs)) { return Collections.emptyList(); } - List singleDeptTreeVOS = departmentPOs.stream().map(e -> SingleDeptTreeVO.builder() .id(e.getId()) .deptName(e.getDeptName()) - .parentDeptName(getDeptNameById(e.getParentDept().intValue())) + .parentComp(e.getParentComp()) + .parentDept(e.getParentDept()) + .parentDeptName(e.getParentDept() == null ? "" : getDeptNameById(e.getParentDept().intValue())) .deptPrincipalName(getEmployeeNameById((long) e.getDeptPrincipal())) - .children(recursiveData(e.getId())) .build() ).collect(Collectors.toList()); + //获取非一级部门 + Map> collects = singleDeptTreeVOS.stream().filter(item -> !parentComp.equals(item.getParentComp()) && null != item.getParentDept()).collect(Collectors.groupingBy(SingleDeptTreeVO :: getParentDept)); - return singleDeptTreeVOS; + return singleDeptTreeVOS.stream().map(e -> { + e.setChildren(collects.get(e.getId())); + return e; + }).filter(item -> parentComp.equals(item.getParentComp())).collect(Collectors.toList()); } @@ -119,29 +124,7 @@ public class DepartmentBO { } } - /** - * 递归获取 - * - * @param parentDeptId - * @return - */ - public static List recursiveData(long parentDeptId) { - List departmentPOS = MapperProxyFactory.getProxy(DepartmentMapper.class).getDeptListByPId(parentDeptId); - if (CollectionUtils.isEmpty(departmentPOS)) { - return Collections.emptyList(); - } - - List singleDeptTreeVOS = departmentPOS.stream().map(e -> SingleDeptTreeVO.builder() - .id(e.getId()) - .deptName(e.getDeptName()) - .parentDeptName(getDeptNameById(e.getParentDept().intValue())) - .deptPrincipalName(getEmployeeNameById((long) e.getDeptPrincipal())) - .children(recursiveData(e.getId())) - .build() - ).collect(Collectors.toList()); - return singleDeptTreeVOS; - } } diff --git a/src/com/engine/organization/entity/department/param/QuerySingleDeptListParam.java b/src/com/engine/organization/entity/department/param/QuerySingleDeptListParam.java index a0dd33d0..aee890e3 100644 --- a/src/com/engine/organization/entity/department/param/QuerySingleDeptListParam.java +++ b/src/com/engine/organization/entity/department/param/QuerySingleDeptListParam.java @@ -18,6 +18,6 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class QuerySingleDeptListParam extends BaseQueryParam { - private int parentComp; + private Long parentComp; } diff --git a/src/com/engine/organization/entity/department/vo/SingleDeptTreeVO.java b/src/com/engine/organization/entity/department/vo/SingleDeptTreeVO.java index 5055275b..c1536203 100644 --- a/src/com/engine/organization/entity/department/vo/SingleDeptTreeVO.java +++ b/src/com/engine/organization/entity/department/vo/SingleDeptTreeVO.java @@ -29,6 +29,10 @@ public class SingleDeptTreeVO { @TableTitle(title = "部门名称", dataIndex = "deptName", key = "deptName") private String deptName; + private Long parentComp; //上级分部 + + private Long parentDept; //上级部门id + @TableTitle(title = "上级部门", dataIndex = "parentDeptName", key = "parentDeptName") private String parentDeptName; //上级部门 diff --git a/src/com/engine/organization/mapper/department/DepartmentMapper.java b/src/com/engine/organization/mapper/department/DepartmentMapper.java index f11d7f57..f4eb2d5f 100644 --- a/src/com/engine/organization/mapper/department/DepartmentMapper.java +++ b/src/com/engine/organization/mapper/department/DepartmentMapper.java @@ -14,7 +14,7 @@ import java.util.List; **/ public interface DepartmentMapper { - List getDeptListByCompId(@Param("parentComp") int parentComp); + List getDeptListByCompId(); List getDeptListByPId(@Param("PId") Long PId); diff --git a/src/com/engine/organization/mapper/department/DepartmentMapper.xml b/src/com/engine/organization/mapper/department/DepartmentMapper.xml index d8804f61..11061587 100644 --- a/src/com/engine/organization/mapper/department/DepartmentMapper.xml +++ b/src/com/engine/organization/mapper/department/DepartmentMapper.xml @@ -19,10 +19,9 @@