做网站需要交钱吗,哪里有好的免费成品网站程序,可以访问的国外网站,平台网站开发价格一般组织架构都会有层级关系#xff0c;根部门的parentId一般设置为null或者0等特殊字符#xff0c;而次级部门及以下的parentId则指向他们父节点的id。 以此为基础#xff0c;业务上经常会有查询整个组织架构层级关系的需求#xff0c;返回对象中的children属性用来存储子… 一般组织架构都会有层级关系根部门的parentId一般设置为null或者0等特殊字符而次级部门及以下的parentId则指向他们父节点的id。 以此为基础业务上经常会有查询整个组织架构层级关系的需求返回对象中的children属性用来存储子机构的集合从而形成树型结构。 这种情况一般使用递归写法能快速完成需求。 1、获取所有根节点根节点的集合就是最终返回对象的集合的元素数量size 2、设置根节点的子节点集合。 3、递归设置子节点的子节点集合。 public RListBankBranchInfo getBankBranchInfo() {String sql select ORG_ID, ORG_NAME, PARENT_ID from auth_org WHERE TENANT_ID 100001 ;ListOrgEntity listAll beanCruder.selectList(OrgEntity.class, sql);ListBankBranchInfo bankBranchInfos new ArrayList();listAll.forEach(org - {BankBranchInfo bankBranchInfo new BankBranchInfo();bankBranchInfo.setId(String.valueOf(org.getOrgId()));bankBranchInfo.setBankName(org.getOrgName());bankBranchInfo.setParentId(org.getParentId() null ? null : Long.valueOf(org.getParentId()));bankBranchInfos.add(bankBranchInfo);});//一级ListBankBranchInfo rootList bankBranchInfos.stream().filter(e - e.getParentId() null).collect(Collectors.toList());//其他级ListBankBranchInfo other bankBranchInfos.stream().filter(e - e.getParentId() ! null).collect(Collectors.toList());setTree(rootList, other);return R.ok(rootList, 查询完成);}private void setTree(ListBankBranchInfo children, ListBankBranchInfo other) {children.forEach(root - {ListBankBranchInfo childrenList new ArrayList();root.setBankBranchInfos(childrenList);//该级子级ListBankBranchInfo temp other.stream().filter(e - root.getId().equals(e.getParentId().toString())).collect(Collectors.toList());childrenList.addAll(temp);if (!childrenList.isEmpty()) {setTree(childrenList, other);}});}