From 895528617b4300ce2ed2a271aabf8938d35b3e66 Mon Sep 17 00:00:00 2001 From: dxfeng Date: Tue, 1 Nov 2022 10:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=83=A8=E3=80=81=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E3=80=81=E5=B2=97=E4=BD=8D=E3=80=81=E4=BA=BA=E5=91=98=20?= =?UTF-8?q?=E5=88=86=E6=9D=83=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/脚本/Mysql/表结构、初始化数据.sql | 18 +++++++++- docs/脚本/SqlServer/表结构、基础数据.sql | 27 +++++++++++++- docs/表结构SQL/SqlServer.sql | 6 ++-- .../entity/job/dto/JobListDTO.java | 1 + .../entity/searchtree/SearchTree.java | 15 ++++++++ .../organization/mapper/comp/CompMapper.java | 2 ++ .../organization/mapper/comp/CompMapper.xml | 7 ++++ .../mapper/hrmresource/SystemDataMapper.java | 2 ++ .../mapper/hrmresource/SystemDataMapper.xml | 7 ++++ .../service/impl/HrmResourceServiceImpl.java | 25 +++++++++---- .../service/impl/JobServiceImpl.java | 19 ++++++---- .../impl/ManagerDetachServiceImpl.java | 5 ++- .../organization/util/detach/DetachUtil.java | 36 +++++++++++++++---- .../util/relation/EcHrmRelationUtil.java | 14 ++++++++ .../util/tree/SearchTreeUtil.java | 9 +++-- 15 files changed, 161 insertions(+), 32 deletions(-) diff --git a/docs/脚本/Mysql/表结构、初始化数据.sql b/docs/脚本/Mysql/表结构、初始化数据.sql index 7f0f6bcd..3aa21471 100644 --- a/docs/脚本/Mysql/表结构、初始化数据.sql +++ b/docs/脚本/Mysql/表结构、初始化数据.sql @@ -698,4 +698,20 @@ BEGIN; INSERT INTO `JCL_INFO` (`id`, `fname`, `fvalue`) VALUES (1, '董事长人员i', '36'); COMMIT; -SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file +SET FOREIGN_KEY_CHECKS = 1; + + +CREATE TABLE `jcl_org_detach` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `manager_type` int(11) NULL DEFAULT NULL, + `ec_manager` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `jcl_manager` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `ec_rolelevel` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `jcl_rolelevel` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `manage_module` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `creator` int(11) NULL DEFAULT NULL, + `delete_type` int(11) NULL DEFAULT NULL, + `create_time` date NULL DEFAULT NULL, + `update_time` date NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; diff --git a/docs/脚本/SqlServer/表结构、基础数据.sql b/docs/脚本/SqlServer/表结构、基础数据.sql index a9551f1f..b494cfa5 100644 --- a/docs/脚本/SqlServer/表结构、基础数据.sql +++ b/docs/脚本/SqlServer/表结构、基础数据.sql @@ -1087,4 +1087,29 @@ GO ALTER TABLE [dbo].[jcl_info] ADD CONSTRAINT [PK_jcl_info] PRIMARY KEY CLUSTERED ([id]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] -GO \ No newline at end of file +GO + +CREATE TABLE [dbo].[JCL_ORG_DETACH] ( + [id] int IDENTITY(1,1) NOT NULL, + [manager_type] int NULL, + [ec_manager] int NOT NULL, + [jcl_manager] int NOT NULL, + [ec_rolelevel] varchar(4000) COLLATE Chinese_PRC_CI_AS NOT NULL, + [jcl_rolelevel] varchar(4000) COLLATE Chinese_PRC_CI_AS NOT NULL, + [manage_module] varchar(4000) COLLATE Chinese_PRC_CI_AS NOT NULL, + [creator] int NULL, + [delete_type] int NULL, + [create_time] date NULL, + [update_time] date NULL + ) +GO + +ALTER TABLE [dbo].[JCL_ORG_DETACH] SET (LOCK_ESCALATION = TABLE) +GO + + + +ALTER TABLE [dbo].[JCL_ORG_DETACH] ADD CONSTRAINT [JCL_ORG_DETACH_PK] PRIMARY KEY CLUSTERED ([id]) +WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) + ON [PRIMARY] +GO diff --git a/docs/表结构SQL/SqlServer.sql b/docs/表结构SQL/SqlServer.sql index 93a84834..77fe7efc 100644 --- a/docs/表结构SQL/SqlServer.sql +++ b/docs/表结构SQL/SqlServer.sql @@ -524,9 +524,9 @@ create table JCL_ORG_DETACH ( manager_type int null, ec_manager int not null, jcl_manager int not null, - ec_rolelevel text not null, - jcl_rolelevel text not null, - manage_module text not null, + ec_rolelevel varchar(4000) not null, + jcl_rolelevel varchar(4000) not null, + manage_module varchar(4000) not null, creator int null, delete_type int null, create_time date null, diff --git a/src/com/engine/organization/entity/job/dto/JobListDTO.java b/src/com/engine/organization/entity/job/dto/JobListDTO.java index 63582224..be769e5f 100644 --- a/src/com/engine/organization/entity/job/dto/JobListDTO.java +++ b/src/com/engine/organization/entity/job/dto/JobListDTO.java @@ -68,6 +68,7 @@ public class JobListDTO { //@TableTitle(title = "上级岗位", dataIndex = "parentJobName", key = "parentJobName") private String parentJobName; private Long parentJob; + private Long parentComp; /** * 是否关键岗 */ diff --git a/src/com/engine/organization/entity/searchtree/SearchTree.java b/src/com/engine/organization/entity/searchtree/SearchTree.java index b279b3e2..1c05c440 100644 --- a/src/com/engine/organization/entity/searchtree/SearchTree.java +++ b/src/com/engine/organization/entity/searchtree/SearchTree.java @@ -3,6 +3,8 @@ package com.engine.organization.entity.searchtree; import com.api.hrm.bean.TreeNode; import lombok.Data; +import java.util.Objects; + /** * @description: * @author:dxfeng @@ -19,4 +21,17 @@ public class SearchTree extends TreeNode { private String requestParams; private String parentComp; private Integer orderNum; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SearchTree that = (SearchTree) o; + return isCanceled == that.isCanceled && Objects.equals(this.getId(), that.getId()) &&Objects.equals(companyid, that.companyid) && Objects.equals(isVirtual, that.isVirtual) && Objects.equals(psubcompanyid, that.psubcompanyid) && Objects.equals(displayType, that.displayType) && Objects.equals(requestParams, that.requestParams) && Objects.equals(parentComp, that.parentComp) && Objects.equals(orderNum, that.orderNum); + } + + @Override + public int hashCode() { + return Objects.hash(this.getId(),companyid, isVirtual, psubcompanyid, displayType, isCanceled, requestParams, parentComp, orderNum); + } } \ No newline at end of file diff --git a/src/com/engine/organization/mapper/comp/CompMapper.java b/src/com/engine/organization/mapper/comp/CompMapper.java index 919b0cdc..5642ba8e 100644 --- a/src/com/engine/organization/mapper/comp/CompMapper.java +++ b/src/com/engine/organization/mapper/comp/CompMapper.java @@ -174,4 +174,6 @@ public interface CompMapper { CompPO getCompanyByNo(@Param("companyNo") String companyNo); + List getCompanyIdsByUuid(@Param("uuids") List uuids); + } diff --git a/src/com/engine/organization/mapper/comp/CompMapper.xml b/src/com/engine/organization/mapper/comp/CompMapper.xml index ac0acd15..12d4a722 100644 --- a/src/com/engine/organization/mapper/comp/CompMapper.xml +++ b/src/com/engine/organization/mapper/comp/CompMapper.xml @@ -435,6 +435,13 @@ where forbidden_tag = 0 and delete_type = 0 + update jcl_org_comp diff --git a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java index 25f5cc8e..4e6353a6 100644 --- a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java +++ b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.java @@ -59,4 +59,6 @@ public interface SystemDataMapper { Long getHrmResourceMaxId(); + List getBatchUuidByIds(@Param("tableName") String tableName,@Param("ecIds") List ecIds); + } diff --git a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml index 906461df..bf7783c0 100644 --- a/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml +++ b/src/com/engine/organization/mapper/hrmresource/SystemDataMapper.xml @@ -159,5 +159,12 @@ where department_id = #{departmentId} + + \ No newline at end of file diff --git a/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java index d6b2040b..36ed1fb7 100644 --- a/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java +++ b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java @@ -55,6 +55,7 @@ import com.engine.organization.util.OrganizationFormItemUtil; import com.engine.organization.util.coderule.CodeRuleUtil; import com.engine.organization.util.db.DBType; import com.engine.organization.util.db.MapperProxyFactory; +import com.engine.organization.util.detach.DetachUtil; import com.engine.organization.util.page.PageUtil; import com.engine.organization.util.tree.SearchTreeUtil; import org.apache.commons.collections.CollectionUtils; @@ -520,6 +521,13 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic sqlWhere += " AND t.job_title = '" + jobTitle + "'"; } + // 分权查询 + List jclRoleLevels = new DetachUtil(user.getUID()).getJclRoleLevels(); + String parentCompanyIds = StringUtils.join(jclRoleLevels, ","); + if (StringUtils.isNotBlank(parentCompanyIds)) { + sqlWhere += " And t.company_id in(" + parentCompanyIds + ")"; + } + return sqlWhere; } @@ -562,7 +570,9 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic */ private List buildTreeByCompAndDept(DepartmentPO departmentBuild, CompPO compBuild, JobPO jobBuild) { List jobPOS = getJobMapper().listPOsByFilter(jobBuild); + new DetachUtil(user.getUID()).filterJobList(jobPOS); List filterDeparts = getDepartmentMapper().listByFilter(departmentBuild, "show_order"); + new DetachUtil(user.getUID()).filterDepartmentList(filterDeparts); // 添加父级岗位 Set builderJobs = new HashSet<>(); for (JobPO jobPO : jobPOS) { @@ -592,6 +602,7 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic // 查询分部信息 List filterComps = getCompMapper().listByFilter(compBuild, "show_order"); + new DetachUtil(user.getUID()).filterCompanyList(filterComps); Set builderDeparts = new HashSet<>(); for (DepartmentPO departmentPO : filterDeparts) { buildParentDepts(departmentPO, builderDeparts); @@ -607,9 +618,12 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic filterComps.addAll(compsByIds); } } + List allCompanys = getCompMapper().list("show_order"); + new DetachUtil(user.getUID()).filterCompanyList(allCompanys); + Map allMaps = allCompanys.stream().collect(Collectors.toMap(CompPO::getId, item -> item, (k1, k2) -> k1)); Set builderComps = new HashSet<>(); for (CompPO compPO : filterComps) { - buildParentComps(compPO, builderComps); + buildParentComps(compPO, builderComps,allMaps); } return SearchTreeUtil.builderTreeMode(CompBO.buildSetToSearchTree(builderComps), searchTrees); } @@ -684,14 +698,11 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic * @param compPO * @param builderComps */ - private void buildParentComps(CompPO compPO, Set builderComps) { + private void buildParentComps(CompPO compPO, Set builderComps,Map allMaps) { builderComps.add(compPO); - if (SearchTreeUtil.isTop(compPO.getParentCompany())) { - return; - } - CompPO parentComp = getCompMapper().listById(compPO.getParentCompany()); + CompPO parentComp = allMaps.get(compPO.getParentCompany()); if (null != parentComp) { - buildParentComps(parentComp, builderComps); + buildParentComps(parentComp, builderComps,allMaps); } } diff --git a/src/com/engine/organization/service/impl/JobServiceImpl.java b/src/com/engine/organization/service/impl/JobServiceImpl.java index 230baf9c..892763c4 100644 --- a/src/com/engine/organization/service/impl/JobServiceImpl.java +++ b/src/com/engine/organization/service/impl/JobServiceImpl.java @@ -50,6 +50,7 @@ import com.engine.organization.thread.OrganizationSyncEc; import com.engine.organization.util.*; import com.engine.organization.util.coderule.CodeRuleUtil; import com.engine.organization.util.db.MapperProxyFactory; +import com.engine.organization.util.detach.DetachUtil; import com.engine.organization.util.page.Column; import com.engine.organization.util.page.PageInfo; import com.engine.organization.util.page.PageUtil; @@ -164,10 +165,12 @@ public class JobServiceImpl extends Service implements JobService { PageInfo pageInfos; String orderSql = PageInfoSortUtil.getSortSql(param.getSortParams()); List allList = getJobMapper().listNoFilter(orderSql); + new DetachUtil(user.getUID()).filterJobDTOList(allList); // 通过子级遍历父级元素 if (filter) { // 根据条件获取元素 List filterJobPOs = getJobMapper().listByFilter(jobPO, orderSql); + new DetachUtil(user.getUID()).filterJobDTOList(allList); // 添加父级元素 List jobListDTOS = JobBO.buildJobDTOList(allList, filterJobPOs); List subList = PageUtil.subList(param.getCurrent(), param.getPageSize(), jobListDTOS); @@ -639,14 +642,11 @@ public class JobServiceImpl extends Service implements JobService { * @param compPO * @param builderComps */ - private void buildParentComps(CompPO compPO, Set builderComps) { + private void buildParentComps(CompPO compPO, Set builderComps,Map allMaps) { builderComps.add(compPO); - if (SearchTreeUtil.isTop(compPO.getParentCompany())) { - return; - } - CompPO parentComp = getCompMapper().listById(compPO.getParentCompany()); + CompPO parentComp = allMaps.get(compPO.getParentCompany()); if (null != parentComp && 0 == parentComp.getForbiddenTag()) { - buildParentComps(parentComp, builderComps); + buildParentComps(parentComp, builderComps,allMaps); } } @@ -689,8 +689,10 @@ public class JobServiceImpl extends Service implements JobService { */ private List buildTreeByCompAndDept(DepartmentPO departmentBuild, CompPO compBuild) { List filterDeparts = getDepartmentMapper().listByFilter(departmentBuild, "show_order"); + new DetachUtil(user.getUID()).filterDepartmentList(filterDeparts); // 查询分部信息 List filterComps = getCompMapper().listByFilter(compBuild, "show_order"); + new DetachUtil(user.getUID()).filterCompanyList(filterComps); Set builderDeparts = new HashSet<>(); for (DepartmentPO departmentPO : filterDeparts) { buildParentDepts(departmentPO, builderDeparts); @@ -704,9 +706,12 @@ public class JobServiceImpl extends Service implements JobService { filterComps.addAll(compsByIds); } } + List allCompanys = getCompMapper().list("show_order"); + new DetachUtil(user.getUID()).filterCompanyList(allCompanys); + Map allMaps = allCompanys.stream().collect(Collectors.toMap(CompPO::getId, item -> item, (k1, k2) -> k1)); Set builderComps = new HashSet<>(); for (CompPO compPO : filterComps) { - buildParentComps(compPO, builderComps); + buildParentComps(compPO, builderComps,allMaps); } return SearchTreeUtil.builderTreeMode(CompBO.buildSetToSearchTree(builderComps), deptTrees); } diff --git a/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java b/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java index 69fb1065..3a329c5a 100644 --- a/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java +++ b/src/com/engine/organization/service/impl/ManagerDetachServiceImpl.java @@ -125,8 +125,7 @@ public class ManagerDetachServiceImpl extends Service implements ManagerDetachSe .ecManager(param.getEcManager()) .jclManager(getHrmResourceMapper().getJclResourceId(String.valueOf(param.getEcManager())).intValue()) .ecRolelevel(param.getEcRolelevel()) - // TODO 遍历存储 - .jclRolelevel(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()) != null ? String.valueOf(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()).getId()) : null) + .jclRolelevel(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()) != null ? String.valueOf(EcHrmRelationUtil.getBatchJclCompanyId(param.getEcRolelevel())) : null) .manageModule("组织管理") .creator((long)user.getUID()) .deleteType(0) @@ -144,7 +143,7 @@ public class ManagerDetachServiceImpl extends Service implements ManagerDetachSe .ecManager(param.getEcManager()) .jclManager(getHrmResourceMapper().getJclResourceId(String.valueOf(param.getEcManager())).intValue()) .ecRolelevel(param.getEcRolelevel()) - .jclRolelevel(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()) != null ? String.valueOf(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()).getId()) : null) + .jclRolelevel(EcHrmRelationUtil.getJclCompanyId(param.getEcRolelevel()) != null ? String.valueOf(EcHrmRelationUtil.getBatchJclCompanyId(param.getEcRolelevel())) : null) .build(); return getMangeDetachMapper().updateDetach(managerDetachPO); } diff --git a/src/com/engine/organization/util/detach/DetachUtil.java b/src/com/engine/organization/util/detach/DetachUtil.java index 13b40b04..ec0fd254 100644 --- a/src/com/engine/organization/util/detach/DetachUtil.java +++ b/src/com/engine/organization/util/detach/DetachUtil.java @@ -2,10 +2,13 @@ package com.engine.organization.util.detach; import com.engine.organization.entity.company.po.CompPO; import com.engine.organization.entity.department.po.DepartmentPO; +import com.engine.organization.entity.job.dto.JobListDTO; import com.engine.organization.entity.job.po.JobPO; import com.engine.organization.service.impl.ManagerDetachServiceImpl; +import com.weaver.general.BaseBean; import org.apache.commons.collections.CollectionUtils; +import java.util.ArrayList; import java.util.List; /** @@ -14,13 +17,19 @@ import java.util.List; * @version: 1.0 */ public class DetachUtil { - // private static final boolean IS_DETACH = "true".equals(new BaseBean().getPropValue("", "")); - private boolean IS_DETACH = true; + private boolean IS_DETACH = "true".equals(new BaseBean().getPropValue("hrmOrganization", "detach")); - private static List ecRoleLevels = null; + private final List jclRoleLevels; public DetachUtil(Integer uId) { - ecRoleLevels = ManagerDetachServiceImpl.getJclRoleLevels(uId); + if (1 == uId) { + IS_DETACH = false; + } + if (IS_DETACH) { + jclRoleLevels = ManagerDetachServiceImpl.getJclRoleLevels(uId); + } else { + jclRoleLevels = new ArrayList<>(); + } } /** @@ -28,7 +37,7 @@ public class DetachUtil { */ public void filterCompanyList(List companyList) { if (IS_DETACH && CollectionUtils.isNotEmpty(companyList)) { - companyList.removeIf(item -> !ecRoleLevels.contains(item.getId())); + companyList.removeIf(item -> !jclRoleLevels.contains(item.getId())); } } @@ -37,7 +46,16 @@ public class DetachUtil { */ public void filterDepartmentList(List departmentList) { if (IS_DETACH && CollectionUtils.isNotEmpty(departmentList)) { - departmentList.removeIf(item -> !ecRoleLevels.contains(item.getParentComp())); + departmentList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); + } + } + + /** + * 根据分权配置过滤分部 + */ + public void filterJobDTOList(List jobList) { + if (IS_DETACH && CollectionUtils.isNotEmpty(jobList)) { + jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); } } @@ -46,7 +64,11 @@ public class DetachUtil { */ public void filterJobList(List jobList) { if (IS_DETACH && CollectionUtils.isNotEmpty(jobList)) { - jobList.removeIf(item -> !ecRoleLevels.contains(item.getParentComp())); + jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); } } + + public List getJclRoleLevels() { + return jclRoleLevels; + } } diff --git a/src/com/engine/organization/util/relation/EcHrmRelationUtil.java b/src/com/engine/organization/util/relation/EcHrmRelationUtil.java index d46c789b..eca283eb 100644 --- a/src/com/engine/organization/util/relation/EcHrmRelationUtil.java +++ b/src/com/engine/organization/util/relation/EcHrmRelationUtil.java @@ -12,6 +12,7 @@ import com.engine.organization.util.db.MapperProxyFactory; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; +import java.util.Arrays; import java.util.List; /** @@ -80,6 +81,19 @@ public class EcHrmRelationUtil { return getCompMapper().getCompanyByUUID(uuid); } + public static String getBatchJclCompanyId(String ecBatchCompanyId) { + if (StringUtils.isBlank(ecBatchCompanyId)) { + return null; + } + List strings = Arrays.asList(ecBatchCompanyId.split(",")); + List uuids = getSystemDataMapper().getBatchUuidByIds(HRM_COMPANY, strings); + List companyIdsByUuid = getCompMapper().getCompanyIdsByUuid(uuids); + if (CollectionUtils.isNotEmpty(companyIdsByUuid)) { + return StringUtils.join(companyIdsByUuid, ","); + } + return ""; + } + public static DepartmentPO getJclDepartmentId(String ecDepartmentId) { if (StringUtils.isBlank(ecDepartmentId)) { diff --git a/src/com/engine/organization/util/tree/SearchTreeUtil.java b/src/com/engine/organization/util/tree/SearchTreeUtil.java index d15b88e1..3bc9891a 100644 --- a/src/com/engine/organization/util/tree/SearchTreeUtil.java +++ b/src/com/engine/organization/util/tree/SearchTreeUtil.java @@ -111,7 +111,8 @@ public class SearchTreeUtil { Map> parentMap = treeList.stream().collect(Collectors.groupingBy(TreeNode::getPid)); Map> childMap = deptTrees.stream().collect(Collectors.groupingBy(SearchTree::getParentComp)); boolean isAdd = !childMap.isEmpty(); - return treeList.stream().peek(e -> { + Set leafIds = new HashSet<>(); + List collect = treeList.stream().peek(e -> { Set treeNodes = new HashSet<>(); List nodes = parentMap.get(e.getId()); if (CollectionUtils.isNotEmpty(nodes)) { @@ -124,11 +125,13 @@ public class SearchTreeUtil { treeNodes.addAll(e.getSubs()); } e.setSubs(new ArrayList<>(treeNodes)); - }).peek(item -> { + leafIds.add(e.getId()); + }).collect(Collectors.toList()); + return collect.stream().peek(item -> { if (CollectionUtils.isNotEmpty(item.getSubs())) { item.setIsParent(true); } - }).filter(item -> isTop(item.getPid())).collect(Collectors.toList()); + }).filter(item -> !leafIds.contains(item.getPid())).collect(Collectors.toList()); } /**