/**
* 叶子节点集朝上遍历
* 获取树枝节点直到树根的buId
* @param leafBuIdList
* @return
*/
private List<Long> getParentBuIdList(List<Long> leafBuIdList) {
UnitQueryATO query = new UnitQueryATO();
List<UnitATO> list = queryList(query);
Map<Long, UnitATO> collectMap = list.stream().collect(Collectors.toMap(p -> p.getId(), p->p));
try {
List<Long> collect = leafBuIdList.parallelStream().map(p -> getParentNodeBuId(p, collectMap)).flatMap(
a -> a.stream()).distinct().collect(Collectors.toList());
return collect;
} catch (Exception e) {
logger.error("getParentBuIdList failed: leafBuIdList {}", FastJsonTool.serialize(leafBuIdList));
throw new RuntimeException(e);
}
}
/**
* 叶子节点集朝上遍历
* @param leafId
* @param collectMap
* @return
*/
private List<Long> getParentNodeBuId(Long leafId,Map<Long, UnitATO> collectMap) {
List<Long> parentNodeBuIdList = new ArrayList<>();
if (leafId== null) {
return parentNodeBuIdList;
} else if (collectMap.get(leafId).getParentId() == null) {
parentNodeBuIdList.add(leafId);
return parentNodeBuIdList;
} else {
parentNodeBuIdList.add(leafId);
parentNodeBuIdList.addAll(getParentNodeBuId(collectMap.get(leafId).getParentId(),collectMap));
}
return parentNodeBuIdList;
}