部门结构树递归方式改为循环方式,提升性能
This commit is contained in:
parent
c8c57b545a
commit
0f2f0372e6
7
pom.xml
7
pom.xml
@ -33,6 +33,7 @@
|
|||||||
<poi.version>4.1.2</poi.version>
|
<poi.version>4.1.2</poi.version>
|
||||||
<velocity.version>2.3</velocity.version>
|
<velocity.version>2.3</velocity.version>
|
||||||
<jwt.version>0.9.1</jwt.version>
|
<jwt.version>0.9.1</jwt.version>
|
||||||
|
<hutool.version>5.7.13</hutool.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- 依赖声明 -->
|
<!-- 依赖声明 -->
|
||||||
@ -199,6 +200,12 @@
|
|||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-core</artifactId>
|
||||||
|
<version>${hutool.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package com.ruoyi.web.controller.system;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.TreeSelect;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -82,10 +84,10 @@ public class SysDeptController extends BaseController
|
|||||||
* 获取部门下拉树列表
|
* 获取部门下拉树列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/treeselect")
|
@GetMapping("/treeselect")
|
||||||
public AjaxResult treeselect(SysDept dept)
|
public AjaxResult treeselect(SysDept dept){
|
||||||
{
|
|
||||||
List<SysDept> depts = deptService.selectDeptList(dept);
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
||||||
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
|
List<TreeSelect> treeSelects = deptService.buildDeptTreeSelect(depts);
|
||||||
|
return AjaxResult.success(treeSelects);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,6 +125,11 @@
|
|||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -3,6 +3,8 @@ package com.ruoyi.common.core.domain;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||||
import com.ruoyi.common.core.domain.entity.SysMenu;
|
import com.ruoyi.common.core.domain.entity.SysMenu;
|
||||||
@ -44,6 +46,16 @@ public class TreeSelect implements Serializable
|
|||||||
this.label = menu.getMenuName();
|
this.label = menu.getMenuName();
|
||||||
this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
public TreeSelect(Tree<Long> dept) {
|
||||||
|
this.id = dept.getId();
|
||||||
|
this.label = dept.getName().toString();
|
||||||
|
List<Tree<Long>> children = dept.getChildren();
|
||||||
|
if (children != null && !children.isEmpty()) {
|
||||||
|
this.children = children.stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Long getId()
|
public Long getId()
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.ruoyi.system.service;
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
import com.ruoyi.common.core.domain.TreeSelect;
|
import com.ruoyi.common.core.domain.TreeSelect;
|
||||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ public interface ISysDeptService
|
|||||||
* @param depts 部门列表
|
* @param depts 部门列表
|
||||||
* @return 树结构列表
|
* @return 树结构列表
|
||||||
*/
|
*/
|
||||||
public List<SysDept> buildDeptTree(List<SysDept> depts);
|
public List<Tree<Long>> buildDeptTree(List<SysDept> depts, Long parentId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建前端所需要下拉树结构
|
* 构建前端所需要下拉树结构
|
||||||
|
@ -4,6 +4,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||||
|
import cn.hutool.core.lang.tree.TreeUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.common.annotation.DataScope;
|
import com.ruoyi.common.annotation.DataScope;
|
||||||
@ -55,28 +59,20 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||||||
* @return 树结构列表
|
* @return 树结构列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysDept> buildDeptTree(List<SysDept> depts)
|
public List<Tree<Long>> buildDeptTree(List<SysDept> depts,Long parentId)
|
||||||
{
|
{
|
||||||
List<SysDept> returnList = new ArrayList<SysDept>();
|
//配置
|
||||||
List<Long> tempList = new ArrayList<Long>();
|
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
|
||||||
for (SysDept dept : depts)
|
treeNodeConfig.setNameKey("label");
|
||||||
{
|
// 自定义属性名 都要默认值的
|
||||||
tempList.add(dept.getDeptId());
|
List<Tree<Long>> treeList = TreeUtil.build(depts, parentId, treeNodeConfig,
|
||||||
}
|
(treeNode, tree) -> {
|
||||||
for (SysDept dept : depts)
|
tree.setId(treeNode.getDeptId());
|
||||||
{
|
tree.setParentId(treeNode.getParentId());
|
||||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
tree.setName(treeNode.getDeptName());
|
||||||
if (!tempList.contains(dept.getParentId()))
|
tree.putExtra("value", treeNode.getDeptId());
|
||||||
{
|
});
|
||||||
recursionFn(depts, dept);
|
return treeList;
|
||||||
returnList.add(dept);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (returnList.isEmpty())
|
|
||||||
{
|
|
||||||
returnList = depts;
|
|
||||||
}
|
|
||||||
return returnList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,7 +84,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||||||
@Override
|
@Override
|
||||||
public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts)
|
public List<TreeSelect> buildDeptTreeSelect(List<SysDept> depts)
|
||||||
{
|
{
|
||||||
List<SysDept> deptTrees = buildDeptTree(depts);
|
List<Tree<Long>> deptTrees = buildDeptTree(depts, 0L);
|
||||||
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user