|
|
|
@ -7,6 +7,7 @@ import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.nacos.common.utils.UuidUtils;
|
|
|
|
|
import com.supervision.dao.*;
|
|
|
|
|
import com.supervision.domain.*;
|
|
|
|
|
import com.supervision.enums.TagEnum;
|
|
|
|
@ -245,7 +246,7 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public GraphVO queryGraph(String processId) {
|
|
|
|
|
public GraphVO queryGraph(String processId, Integer level) {
|
|
|
|
|
Process process = Optional.ofNullable(processService.getById(processId)).orElseThrow(() -> new BusinessException("未找到对应的问诊流程"));
|
|
|
|
|
// 如果图谱ID为空,则创建图谱
|
|
|
|
|
if (StrUtil.isEmpty(process.getGraphId())) {
|
|
|
|
@ -287,7 +288,14 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nodeList.add(nodeVO);
|
|
|
|
|
// 校验级别(根据参数的级别来进行判断)
|
|
|
|
|
if (ObjectUtil.isNotEmpty(level)) {
|
|
|
|
|
if (level >= nodeVO.getNodeLevel()) {
|
|
|
|
|
nodeList.add(nodeVO);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
nodeList.add(nodeVO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 构建边
|
|
|
|
|
List<NgEdge<String>> edges = subgraph.getEdges();
|
|
|
|
@ -295,21 +303,28 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
|
|
|
|
|
EdgeVO edgeVO = new EdgeVO();
|
|
|
|
|
edgeVO.setSource(edge.getSrcID());
|
|
|
|
|
edgeVO.setTarget(edge.getDstID());
|
|
|
|
|
|
|
|
|
|
Map<String, Object> properties = edge.getProperties();
|
|
|
|
|
Object nameObject = properties.get("edgeValue");
|
|
|
|
|
if (ObjectUtil.isNotEmpty(nameObject)) {
|
|
|
|
|
edgeVO.setName(String.valueOf(nameObject));
|
|
|
|
|
edgeVO.setLabel(edgeVO.getName());
|
|
|
|
|
}
|
|
|
|
|
edgeVO.setParams(properties);
|
|
|
|
|
edgeList.add(edgeVO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 这里,需要遍历,把重点不存在的节点连线给删掉
|
|
|
|
|
Set<String> nodeIdSet = nodeList.stream().map(NodeVO::getId).collect(Collectors.toSet());
|
|
|
|
|
// 如果指向的节点不存在,那么这个边也不存在
|
|
|
|
|
edgeList.removeIf(edgeVO -> !nodeIdSet.contains(edgeVO.getTarget()));
|
|
|
|
|
|
|
|
|
|
return new GraphVO(nodeList, edgeList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TreeNodeVO> queryTreeGraph(String processId) {
|
|
|
|
|
GraphVO graphVO = queryGraph(processId);
|
|
|
|
|
public List<TreeNodeVO> queryTreeGraph(String processId, Integer level) {
|
|
|
|
|
GraphVO graphVO = queryGraph(processId, level);
|
|
|
|
|
List<TreeNodeVO> treeNodeList = graphVO.getNodes().stream().map(node -> BeanUtil.toBean(node, TreeNodeVO.class)).collect(Collectors.toList());
|
|
|
|
|
// 首先找到第一级节点
|
|
|
|
|
List<TreeNodeVO> firstNodeList = treeNodeList.stream().filter(node -> node.getNodeLevel() == 1).collect(Collectors.toList());
|
|
|
|
@ -321,9 +336,25 @@ public class GraphNebulaServiceImpl implements GraphNebulaService {
|
|
|
|
|
for (TreeNodeVO nodeVO : firstNodeList) {
|
|
|
|
|
recursionBuildTree(nodeVO, treeNodeMap, graphVO.getEdges());
|
|
|
|
|
}
|
|
|
|
|
// 为所有节点分配新的唯一ID(前端需要ID字段为唯一ID)
|
|
|
|
|
recursionGenerateSingleId(firstNodeList);
|
|
|
|
|
return firstNodeList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 为属性结构构建新的唯一ID,把原先的ID迁移到GraphId
|
|
|
|
|
*/
|
|
|
|
|
private void recursionGenerateSingleId(List<TreeNodeVO> firstNodeList) {
|
|
|
|
|
for (TreeNodeVO treeNodeVO : firstNodeList) {
|
|
|
|
|
String uuid = UuidUtils.generateUuid();
|
|
|
|
|
treeNodeVO.setGraphId(treeNodeVO.getId());
|
|
|
|
|
treeNodeVO.setId(uuid);
|
|
|
|
|
if (CollUtil.isNotEmpty(treeNodeVO.getChildren())) {
|
|
|
|
|
recursionGenerateSingleId(treeNodeVO.getChildren());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recursionBuildTree(TreeNodeVO preNode, Map<String, TreeNodeVO> treeNodeMap, List<EdgeVO> edgeList) {
|
|
|
|
|
// 通过preNode的ID找到所有的子节点
|
|
|
|
|
List<TreeNodeVO> childNode = new ArrayList<>();
|
|
|
|
|