抽出方法
This commit is contained in:
+7
-36
@@ -6,6 +6,7 @@ import com.adc.da.slrs.sarInstitution.entity.SyncInstitution;
|
|||||||
import com.adc.da.slrs.sarInstitution.entity.TsInstitution;
|
import com.adc.da.slrs.sarInstitution.entity.TsInstitution;
|
||||||
import com.adc.da.slrs.sarInstitution.entity.TsUserVO;
|
import com.adc.da.slrs.sarInstitution.entity.TsUserVO;
|
||||||
import com.adc.da.slrs.sarInstitution.service.ITsInstitutionService;
|
import com.adc.da.slrs.sarInstitution.service.ITsInstitutionService;
|
||||||
|
import com.adc.da.slrs.sarInstitution.util.TreeUtil;
|
||||||
import com.adc.da.sync.service.SyncUserService;
|
import com.adc.da.sync.service.SyncUserService;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
@@ -38,48 +39,18 @@ public class TsInstitutionServiceImpl extends ServiceImpl<TsInstitutionDao, TsIn
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<TsInstitution> getInstitution() {
|
public List<TsInstitution> getInstitution() {
|
||||||
|
List<TsInstitution> institutionList = this.list();//查询所有的的数据
|
||||||
|
|
||||||
//查询第一层机构
|
//查询第一层机构
|
||||||
List<TsInstitution> institutionRoot=tsInstitutionDao.selectRoot();
|
List<TsInstitution> root=tsInstitutionDao.selectRoot();
|
||||||
|
|
||||||
//转换为hashSet
|
TreeUtil treeUtil = new TreeUtil();
|
||||||
List<String> root = institutionRoot.stream()
|
List<TsInstitution> institutionTree = treeUtil.treeAsList(institutionList, root);
|
||||||
.map(item -> item.getId())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
HashSet<String> rootSet = new HashSet<>(root);
|
|
||||||
|
|
||||||
List<TsInstitution> institutionList = this.list();//查询所有的的数据
|
return institutionTree;
|
||||||
//获取父节点,0表示父节点
|
|
||||||
List<TsInstitution> collect = institutionList.stream()
|
|
||||||
.filter(e -> rootSet.contains(e.getId()))
|
|
||||||
.map(e -> {
|
|
||||||
|
|
||||||
List<TsInstitution> childNode = getChildNode(e, institutionList);
|
|
||||||
|
|
||||||
e.setChildren(new ArrayList<>(childNode));
|
|
||||||
return e;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
return collect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归查询子节点
|
|
||||||
* @param root
|
|
||||||
* @param contentKnowledgeList
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private List<TsInstitution> getChildNode(TsInstitution root, List<TsInstitution> contentKnowledgeList) {
|
|
||||||
List<TsInstitution> childrenList = contentKnowledgeList.stream().filter(e -> Objects.equals(e.getParentId(), root.getId())).map(
|
|
||||||
e -> {
|
|
||||||
List<TsInstitution> childNode = getChildNode(e, contentKnowledgeList);
|
|
||||||
e.setChildren(new ArrayList<>(childNode));
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
).collect(Collectors.toList());
|
|
||||||
return childrenList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.adc.da.slrs.sarInstitution.util;
|
||||||
|
|
||||||
|
import com.adc.da.slrs.sarInstitution.entity.TsInstitution;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class TreeUtil {
|
||||||
|
|
||||||
|
public List<TsInstitution> treeAsList(List<TsInstitution> institutionList,List<TsInstitution> rootList){
|
||||||
|
|
||||||
|
//转换为hashSet
|
||||||
|
List<String> root = rootList.stream()
|
||||||
|
.map(item -> item.getId())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
HashSet<String> rootSet = new HashSet<>(root);
|
||||||
|
|
||||||
|
//获取父节点,0表示父节点
|
||||||
|
List<TsInstitution> tree = institutionList.stream()
|
||||||
|
.filter(e -> rootSet.contains(e.getId()))
|
||||||
|
.map(e -> {
|
||||||
|
|
||||||
|
List<TsInstitution> childNode = getChildNode(e, institutionList);
|
||||||
|
|
||||||
|
e.setChildren(new ArrayList<>(childNode));
|
||||||
|
return e;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归查询子节点
|
||||||
|
* @param root
|
||||||
|
* @param contentKnowledgeList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<TsInstitution> getChildNode(TsInstitution root, List<TsInstitution> contentKnowledgeList) {
|
||||||
|
List<TsInstitution> childrenList = contentKnowledgeList.stream().filter(e -> Objects.equals(e.getParentId(), root.getId())).map(
|
||||||
|
e -> {
|
||||||
|
List<TsInstitution> childNode = getChildNode(e, contentKnowledgeList);
|
||||||
|
e.setChildren(new ArrayList<>(childNode));
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
).collect(Collectors.toList());
|
||||||
|
return childrenList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user