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