Browse Source

组织机构初始化树构建

master
21819 2 years ago
parent
commit
138b66240b
  1. 29
      mailbox-lan/src/test/java/com/biutag/lan/DeptTreeTreeBuild.java
  2. 1
      mailbox-lan/src/test/java/com/biutag/lan/entity/TmpDept.java
  3. 2
      mailbox-lan/src/test/java/com/biutag/lan/mapper/TmpDeptMapper.java

29
mailbox-lan/src/test/java/com/biutag/lan/DeptTreeTreeBuild.java

@ -4,51 +4,50 @@ package com.biutag.lan;
import com.alibaba.excel.EasyExcel;
import com.biutag.lan.entity.DeptTree;
import com.biutag.lan.entity.DeptNode;
import com.biutag.lan.mapper.DeptTreeMapper;
import com.biutag.lan.entity.TmpDept;
import com.biutag.lan.mapper.TmpDeptMapper;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@SpringBootTest
public class DeptTreeTreeBuild {
@Resource
private DeptTreeMapper deptTreeMapper;
private TmpDeptMapper tmpDeptMapper;
private List<DeptTree> processedNodes = new ArrayList<>();
public List<DeptNode> tree() {
List<DeptTree> list = deptTreeMapper.selectList(null);
List<TmpDept> list = tmpDeptMapper.selectList(null);
return buildTree(list);
}
private List<DeptNode> buildTree(List<DeptTree> list) {
private List<DeptNode> buildTree(List<TmpDept> list) {
List<DeptNode> threeNode = list.stream()
.filter(item -> item.getLevel() == 3)
.map(item -> new DeptNode()
.setCategory(item.getCategory())
.setCategory(item.getDeptType())
.setLevel(3)
.setId(item.getId())
.setPid(item.getPid())
.setName(item.getName())
.setFullName(item.getFullName())
.setName(item.getThird())
.setFullName(item.getDeptFullName())
)
.collect(Collectors.toList());
// 二级
List<DeptNode> secondNode = list.stream()
.filter(item -> item.getLevel() == 2)
.map(item -> new DeptNode()
.setCategory(item.getCategory())
.setCategory(item.getDeptType())
.setLevel(2)
.setId(item.getId())
.setPid(item.getPid())
.setName(item.getName())
.setFullName(item.getFullName())
.setName(item.getSecond())
.setFullName(item.getDeptFullName())
.setChildren(threeNode.stream().filter(node -> item.getId().equals(node.getPid())).collect(Collectors.toList()))
)
.collect(Collectors.toList());
@ -56,12 +55,12 @@ public class DeptTreeTreeBuild {
return list.stream()
.filter(item -> item.getLevel() == 1)
.map(item -> new DeptNode()
.setCategory(item.getCategory())
.setCategory(item.getDeptType())
.setLevel(1)
.setId(item.getId())
.setPid(item.getPid())
.setName(item.getName())
.setFullName(item.getFullName())
.setName(item.getFirst())
.setFullName(item.getDeptFullName())
.setChildren(secondNode.stream().filter(node -> item.getId().equals(node.getPid())).collect(Collectors.toList()))
)
.collect(Collectors.toList());

1
mailbox-lan/src/test/java/com/biutag/lan/entity/TmpDept.java

@ -9,7 +9,6 @@ public class TmpDept {
private Integer id;
private Integer pid;
private Integer level;
private String name;
private String deptFullName;
private String deptType;
private String first;

2
mailbox-lan/src/test/java/com/biutag/lan/mapper/TmpDeptMapper.java

@ -2,6 +2,8 @@ package com.biutag.lan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.biutag.lan.entity.TmpDept;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TmpDeptMapper extends BaseMapper<TmpDept> {
}

Loading…
Cancel
Save