From 7d0216aacac3bb1f6e9d1ea0d88a6bd5dd1c138c Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 25 Oct 2021 21:27:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=B3=E7=B3=BB=E5=9B=BE=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/RelationshipGraphData.java | 1 + .../service/RelationshipEdgeService.java | 77 +++++++++++++++++++ backend/src/main/java/io/metersphere/xpack | 2 +- frontend/package.json | 2 +- frontend/src/business/components/xpack | 2 +- 5 files changed, 81 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/dto/RelationshipGraphData.java b/backend/src/main/java/io/metersphere/dto/RelationshipGraphData.java index a3185b7720..0e6fd4bccc 100644 --- a/backend/src/main/java/io/metersphere/dto/RelationshipGraphData.java +++ b/backend/src/main/java/io/metersphere/dto/RelationshipGraphData.java @@ -37,6 +37,7 @@ public class RelationshipGraphData { public static class Edge { private Integer source; private Integer target; + private float curveness; } /** diff --git a/backend/src/main/java/io/metersphere/service/RelationshipEdgeService.java b/backend/src/main/java/io/metersphere/service/RelationshipEdgeService.java index a5678c5b77..fc9b7ac07d 100644 --- a/backend/src/main/java/io/metersphere/service/RelationshipEdgeService.java +++ b/backend/src/main/java/io/metersphere/service/RelationshipEdgeService.java @@ -3,6 +3,7 @@ package io.metersphere.service; import io.metersphere.base.domain.RelationshipEdge; import io.metersphere.base.domain.RelationshipEdgeExample; +import io.metersphere.base.domain.RelationshipEdgeKey; import io.metersphere.base.mapper.RelationshipEdgeMapper; import io.metersphere.base.mapper.ext.ExtRelationshipEdgeMapper; import io.metersphere.commons.exception.MSException; @@ -41,9 +42,85 @@ public class RelationshipEdgeService { example.createCriteria() .andSourceIdEqualTo(sourceId) .andTargetIdEqualTo(targetId); + + String graphId = relationshipEdgeMapper.selectByExample(example).get(0).getGraphId(); + updateGraphId(graphId, sourceId, targetId); + relationshipEdgeMapper.deleteByExample(example); } + /** + * 删除边后,若形成两个不连通子图,则拆分图 + * @param graphId + * @param sourceId + * @param targetId + */ + public void updateGraphId(String graphId, String sourceId, String targetId) { + RelationshipEdgeExample graphExample = new RelationshipEdgeExample(); + graphExample.createCriteria() + .andGraphIdEqualTo(graphId); + List edges = relationshipEdgeMapper.selectByExample(graphExample); + + // 去掉要删除的边 + edges = edges.stream() + .filter(i -> i.getSourceId() != sourceId || i.getTargetId() != targetId) + .collect(Collectors.toList()); + + Set nodes = new HashSet<>(); + Set markSet = new HashSet<>(); + nodes.addAll(edges.stream().map(RelationshipEdgeKey::getSourceId).collect(Collectors.toSet())); + nodes.addAll(edges.stream().map(RelationshipEdgeKey::getTargetId).collect(Collectors.toSet())); + + dfsForMark(sourceId, edges, markSet, true); + dfsForMark(sourceId, edges, markSet, false); + + // 如果连通的点减少,说明形成了两个不连通子图,重新设置graphId + if (markSet.size() != nodes.size()) { + List updateIds = new ArrayList<>(markSet); + RelationshipEdgeExample updateGraphExample = new RelationshipEdgeExample(); + updateGraphExample.createCriteria() + .andSourceIdIn(updateIds); + updateGraphExample.or( + updateGraphExample.createCriteria().andTargetIdIn(updateIds) + ); + RelationshipEdge edge = new RelationshipEdge(); + edge.setGraphId(UUID.randomUUID().toString()); + relationshipEdgeMapper.updateByExampleSelective(edge, updateGraphExample); + } + } + + /** + * 遍历标记经过的节点 + * @param node + * @param edges + * @param markSet + * @param isForwardDirection + */ + public void dfsForMark(String node, List edges, Set markSet, boolean isForwardDirection) { + markSet.add(node); + + Set nextLevelNodes = new HashSet<>(); + + for (RelationshipEdge edge : edges) { + if (isForwardDirection) { + if (node.equals(edge.getSourceId())) { + nextLevelNodes.add(edge.getTargetId()); + } + } else { + if (node.equals(edge.getTargetId())) { + nextLevelNodes.add(edge.getSourceId()); + } + } + } + + nextLevelNodes.forEach(nextNode -> { + if (!markSet.contains(node)) { + dfsForMark(nextNode, edges, markSet, true); + dfsForMark(nextNode, edges, markSet, false); + } + }); + } + public void delete(String sourceIdOrTargetId) { RelationshipEdgeExample example = new RelationshipEdgeExample(); example.createCriteria() diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index dfc1f22ca4..d9804d8c3d 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit dfc1f22ca4a189ae8d91d5570acf56697cecd933 +Subproject commit d9804d8c3d0496423403794f0997b3b596871a27 diff --git a/frontend/package.json b/frontend/package.json index 7c306cf3fa..9e9269e7cc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -20,7 +20,7 @@ "axios": "^0.21.1", "core-js": "^3.4.3", "diffable-html": "^4.0.0", - "echarts": "^4.6.0", + "echarts": "^5.0.2", "el-table-infinite-scroll": "^1.0.10", "el-tree-transfer": "^2.4.7", "element-ui": "^2.13.0", diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index d51827047f..1ccb9d2795 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit d51827047ff85c2711cb1fe034ea7f1c67b99189 +Subproject commit 1ccb9d2795a51f6dc49aaf9fd9960818bca005e3