From d0bff7a4d7e0bd53f11ea629df20e48c3f72a0e6 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期一, 14 十月 2024 10:09:00 +0800
Subject: [PATCH] 修改RBD识别算法
---
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java | 5
web/src/views/modules/taskReliability/RBD-edit-img.vue | 27
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/model/RbdTreeNode.java | 1
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java | 1678 +++++++++------------------------------------------------
web/src/views/modules/taskReliability/SimulatAssess.vue | 8
5 files changed, 296 insertions(+), 1,423 deletions(-)
diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/model/RbdTreeNode.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/model/RbdTreeNode.java
index 309745c..0714fdb 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/model/RbdTreeNode.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/model/RbdTreeNode.java
@@ -19,6 +19,7 @@
private String nodeType;
private String algorithmType;
private Integer voteNum;
+ private Long dataId;
private double x;
private double y;
diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java
index eac7dbb..b32146d 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java
@@ -143,6 +143,15 @@
return result;
}
+ @Transactional(rollbackFor = Exception.class)
+ public boolean analyze(ModelRbd modelRbd) {
+ boolean result = true;
+ if (modelRbd == null) return result;
+ Long modelId = modelRbd.getId();
+ result = analyzeRbd(modelRbd, true);
+ return result;
+ }
+
private boolean layoutRbd(ModelRbd modelRbd) {
boolean result = true;
String rbdsonStr = modelRbd.getContent();
@@ -158,11 +167,19 @@
// 1. 瑙f瀽鍑鸿妭鐐逛笌杈�
getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList);
- // 2. 璁$畻鎵�鏈夎妭鐐圭殑鍏ュ彛绾挎暟鍙婂嚭鍙g嚎鏁�
- calcInOutLineNumAllNode(modelNodeList, modelLineList);
-
+ // 2. 杞崲涓烘爲鍨嬬粨鏋�
RbdTreeNode root = recognizeRbd(modelNodeList, modelLineList);
+ // 3. 閫掑綊璁$畻RBD鐨勫竷灞�绌洪棿澶у皬
+ // 4. 閫掑綊璁$畻RBD鐨勫竷灞�绌洪棿鍙傛暟锛坸銆亂鍧愭爣锛�
+
+ // 5. 淇濆瓨鑷姩甯冨眬妯″瀷
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("cells", rbdJsonArray);
+ modelRbd.setContent(jsonObject.toString());
+ modelRbdDao.updateById(modelRbd);
+
+ return result;
/*
// 3. 澶嶅埗浜у搧鑺傜偣(node)鍒發ist
List<ModelNode> modelNodeAndVnodeList = modelNodeList.stream().filter(item ->
@@ -207,8 +224,136 @@
// modelRbd.setAutoLayoutContent("娴嬭瘯鏂囧瓧");
// modelRbdDao.updateById(modelRbd);
*/
+ }
- return result;
+ private void getNodeAndLineFromRbd(Long modelId,
+ JSONArray rbdJsonArray,
+ List<ModelNode> modelNodeList,
+ List<ModelLine> modelLineList,
+ List<ProductImg> productImgList) {
+ Object jsonValue = null;
+ for (int i = 0; i < rbdJsonArray.size(); i++) {
+ JSONObject jsonObject = rbdJsonArray.getJSONObject(i);
+ String shape = jsonObject.get("shape").toString();
+ if ("edge".equals(shape)) {
+ ModelLine modelLine = new ModelLine();
+ modelLine.setId(UUIDUtil.generateId());
+ modelLine.setModelId(modelId);
+ modelLine.setPicId(jsonObject.get("id").toString());
+ modelLine.setBeginCell(JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString());
+ modelLine.setEndCell(JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString());
+ modelLineList.add(modelLine);
+ } else if ("image".equals(shape)) {
+ ModelNode modelNode = new ModelNode();
+ modelNode.setId(UUIDUtil.generateId());
+ modelNode.setModelId(modelId);
+ modelNode.setPicId(jsonObject.get("id").toString());
+ modelNode.setNodeType(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeType".split("/")).toString());
+ modelNode.setPositionX(Double.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "position/x".split("/")).toString()));
+ modelNode.setPositionY(Double.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "position/y".split("/")).toString()));
+ modelNode.setWidth(new Double(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()));
+ modelNode.setHeight(new Double(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()));
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/voteNum".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ modelNode.setVoteNum(Integer.valueOf(jsonValue.toString()));
+ }
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/startNodeId".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ modelNode.setPairStartNodeId(jsonValue.toString());
+ }
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/endNodeId".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ modelNode.setPairEndNodeId(jsonValue.toString());
+ }
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/edgeTopId".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ modelNode.setBridgeEdgeTopId(jsonValue.toString());
+ }
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/edgeBottomId".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ modelNode.setBridgeEdgeBottomId(jsonValue.toString());
+ }
+ if ("dashedBox".equals(modelNode.getNodeType())) {
+ modelNode.setNodeType("node");
+ } else if ("node".equals(modelNode.getNodeType())) {
+ ProductImg productImg = new ProductImg();
+ String dataId = JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString();
+ modelNode.setDataId(Long.valueOf(dataId));
+ modelNode.setNodeTypeExt(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeTypeExt".split("/")).toString());
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/"));
+ modelNode.setName(jsonValue == null ? "" : jsonValue.toString());
+
+ productImg.setDataId(dataId);
+ String productType = JsonUtils2.getJsonValueByPath(jsonObject, "data/productType".split("/")).toString();
+ productImg.setProductType(productType);
+ if ("product_sb".equals(productType)) {
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/reliabDistribType".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ productImg.setReliabDistribType(Integer.valueOf(jsonValue.toString()));
+ if (3 == productImg.getReliabDistribType()) {
+ // 浜岄」鍒嗗竷
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/simulatTimes".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ productImg.setBinomialTotalNum(Integer.valueOf(jsonValue.toString()));
+ modelNode.setBinomialTotalNum(Integer.valueOf(jsonValue.toString()));
+ }
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/successTimes".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ productImg.setBinomialSuccessNum(Integer.valueOf(jsonValue.toString()));
+ modelNode.setBinomialSuccessNum(Integer.valueOf(jsonValue.toString()));
+ }
+ }
+ }
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcf".split("/"));
+ if (null != jsonValue) productImg.setTaskMtbcf(jsonValue.toString());
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcfOtherParams2".split("/"));
+ if (null != jsonValue) productImg.setTaskMtbcfOtherParams2(jsonValue.toString());
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcfOtherParams3".split("/"));
+ if (null != jsonValue) productImg.setTaskMtbcfOtherParams3(jsonValue.toString());
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/isRepair".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString()) && !"null".equals(jsonValue.toString())) {
+ productImg.setIsRepair(Integer.valueOf(jsonValue.toString()));
+ } else {
+ productImg.setIsRepair(0);
+ }
+ if (1 == productImg.getIsRepair()) {
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairDistribType".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ productImg.setRepairDistribType(Integer.valueOf(jsonValue.toString()));
+ }
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcr".split("/"));
+ if (null != jsonValue) productImg.setRepairMttcr(jsonValue.toString());
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcrOtherParams2".split("/"));
+ if (null != jsonValue) productImg.setRepairMttcrOtherParams2(jsonValue.toString());
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcrOtherParams3".split("/"));
+ if (null != jsonValue) productImg.setRepairMttcrOtherParams3(jsonValue.toString());
+ }
+ }
+ productImgList.add(productImg);
+ }
+ modelNodeList.add(modelNode);
+ }
+ }
+ }
+
+ private void saveModel(ModelRbd modelRbd,
+ List<Algorithm> algoList,
+ List<ModelNode> modelNodeAndVnodeList) {
+ // 鍒犻櫎鏃㈡湁鏁版嵁
+ algorithmDao.deleteByModelId(modelRbd.getId());
+ modelNodeAlgorithmDao.deleteByModelId(modelRbd.getId());
+
+ // 鎻掑叆鏁版嵁
+ for (Algorithm algorithm : algoList) {
+ algorithmDao.insert(algorithm);
+ }
+ for (ModelNode modelNode : modelNodeAndVnodeList) {
+ modelNodeAlgorithmDao.insert(ModelNodeAlgorithm.from(modelNode));
+ }
+
+ // 鏇存柊RBD鏁版嵁
+ modelRbd.setPublishedContent(modelRbd.getContent());
+ modelRbdDao.updateById(modelRbd);
}
private RbdTreeNode recognizeRbd(List<ModelNode> modelNodeList,
@@ -264,6 +409,7 @@
treeNode.setName(node.getName());
treeNode.setNodeType(node.getNodeType());
treeNode.setPicId(node.getPicId());
+ treeNode.setDataId(node.getDataId());
treeNode.setMyWidth(node.getWidth());
treeNode.setMyHeight(node.getHeight());
parent.getChildren().add(treeNode);
@@ -309,6 +455,7 @@
counter++;
vnodeCounter.put("vnodeCounter", counter);
subNodeOpe.setNodeType("vnode");
+ subNodeOpe.setVoteNum(node.getVoteNum());
subNode.getChildren().add(subNodeOpe);
treeNode = new RbdTreeNode();
treeNode.setId(node.getId());
@@ -471,26 +618,6 @@
return lines;
}
- private boolean isSingleNode(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList) {
- boolean result = false;
- ModelNode start = modelNodeList.stream().filter(item ->
- "start".equals(item.getNodeType())).collect(Collectors.toList()).get(0);
- ModelNode end = modelNodeList.stream().filter(item ->
- "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0);
- ModelLine line1 = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(start.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode node1 = modelNodeList.stream().filter(item ->
- line1.getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- ModelLine line2 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(end.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode node2 = modelNodeList.stream().filter(item ->
- line2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (node1.getPicId().equals(node2.getPicId()) && "node".equals(node1.getNodeType())) result = true;
-
- return result;
- }
-
private boolean isSeriesBranch(ModelNode rightNode, // rbd涓殑鍙宠妭鐐癸紙鍖呮嫭end鍙�4绉嶈繍绠楃锛�
ModelLine line, // 鍙宠妭鐐圭殑鍏ュ彛绾�
List<ModelNode> modelNodeList,
@@ -537,6 +664,122 @@
}
return result;
+ }
+
+ private boolean analyzeRbd(ModelRbd modelRbd, boolean saveFlag) {
+ boolean result = true;
+ String rbdsonStr = modelRbd.getContent();
+
+ JSONArray rbdJsonArray = new JSONObject(rbdsonStr).getJSONArray("cells");
+ if (rbdJsonArray == null) return result;
+
+ // 瑙f瀽缁撴灉瀛樻斁list
+ List<ModelNode> modelNodeList = new ArrayList<>();
+ List<ModelLine> modelLineList = new ArrayList<>();
+ List<Algorithm> algorithmList = new ArrayList<>();
+ List<ProductImg> productImgList = new ArrayList<>(); // 鏆備笉浣跨敤锛堣�屼娇鐢ㄦ暟鎹簱涓殑鍙潬鎬у弬鏁帮級
+ List<ModelNode> modelNodeAndVnodeList = new ArrayList<>();
+
+ // 1. 瑙f瀽鍑鸿妭鐐逛笌杈�
+ getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList);
+ // 2. 杞崲涓烘爲鍨嬬粨鏋�
+ RbdTreeNode root = recognizeRbd(modelNodeList, modelLineList);
+ // 3. 棰勫鐞�
+ deleteSeriesForAutoArrange(root);
+ deleteStartEnd(root);
+ // 3. 鐢熸垚绠楁硶
+ createAlgorithm(modelRbd.getId(), root, algorithmList, modelNodeAndVnodeList);
+ // 4. 淇濆瓨妯″瀷
+ if (saveFlag) saveModel(modelRbd, algorithmList, modelNodeAndVnodeList);
+
+ return result;
+ }
+
+ private void createAlgorithm(Long modelId,
+ RbdTreeNode root,
+ List<Algorithm> algorithmList,
+ List<ModelNode> modelNodeAndVnodeList) {
+ List<RbdTreeNode> children = root.getChildren();
+ if (children.size() == 0) {
+ ModelNode node = new ModelNode();
+ node.setModelId(modelId);
+ node.setId(root.getId());
+ node.setPicId(root.getPicId());
+ node.setDataId(root.getDataId());
+ node.setNodeType(root.getNodeType());
+ node.setName(root.getName());
+ node.setVoteNum(root.getVoteNum());
+ modelNodeAndVnodeList.add(node);
+ } else {
+ Algorithm algo = new Algorithm();
+ algo.setModelId(modelId);
+ algo.setId(root.getId());
+ algo.setComputerId(algo.getId());
+ algo.setAlgorithmType(root.getAlgorithmType());
+ algo.setModelType(algo.getAlgorithmType());
+ algo.setStep(Integer.valueOf(root.getName().substring(1)));
+ algo.setVoteNum(root.getVoteNum());
+ algo.setObjectList(root.getChildren().stream().map(item ->
+ item.getName()).collect(Collectors.joining(",")));
+ algo.setComputerList(root.getChildren().stream().map(item ->
+ item.getId().toString()).collect(Collectors.joining(",")));
+ algorithmList.add(algo);
+ ModelNode node = new ModelNode();
+ node.setModelId(modelId);
+ node.setId(root.getId());
+ node.setPicId(root.getPicId());
+ node.setDataId(root.getDataId());
+ node.setNodeType(root.getNodeType());
+ node.setName(root.getName());
+ node.setVoteNum(root.getVoteNum());
+ modelNodeAndVnodeList.add(node);
+ for (RbdTreeNode treeNode : root.getChildren()) {
+ createAlgorithm(modelId, treeNode, algorithmList, modelNodeAndVnodeList);
+ }
+ }
+ }
+
+ /**
+ * 瀵规爲褰㈢粨鏋勮繘琛岄澶勭悊锛屽寘鎷細
+ * 1锛夊皢root鐨刟lgorithmType鏇挎崲涓篹nd锛屽苟鍘绘帀start鍜宔nd鑺傜偣
+ * 2锛塻tart涓巈nd闂村彧鏈�1涓�昏緫杩愮畻鍧楋紝鍒欏幓鎺夋渶澶栧眰鐨剆eries
+ * @param root
+ */
+ private void deleteStartEnd(RbdTreeNode root) {
+ root.setAlgorithmType("end");
+ List<RbdTreeNode> children = root.getChildren();
+ children.remove(children.size()-1);
+ children.remove(0);
+ if (children.size()>1 ||
+ !"vnode".equals(children.get(0).getNodeType())) {
+ RbdTreeNode subNode = new RbdTreeNode();
+ subNode.setAlgorithmType("series");
+ subNode.setId(UUIDUtil.generateId());
+ subNode.setName("v0");
+ subNode.setNodeType("vnode");
+ subNode.getChildren().addAll(children);
+ List<RbdTreeNode> list = new ArrayList<>();
+ list.add(subNode);
+ root.setChildren(list);
+ }
+ }
+
+ /**
+ * 瀵规爲褰㈢粨鏋勮繘琛岄澶勭悊锛�
+ * 鍘绘帀閫昏緫杩愮畻鍧椾腑鐢ㄤ簬鎺掔増鐨勫灞俿eries
+ * @param root
+ */
+ private void deleteSeriesForAutoArrange(RbdTreeNode root) {
+ List<RbdTreeNode> children = root.getChildren();
+ for (int i = 0; i < children.size(); i++) {
+ RbdTreeNode treeNode = children.get(i);
+ if ("vnode".equals(treeNode.getNodeType()) &&
+ "series".equals(treeNode.getAlgorithmType()) &&
+ "connect".equals(treeNode.getChildren().get(0).getNodeType())) {
+ children.set(i, treeNode.getChildren().get(1));
+ }
+ deleteSeriesForAutoArrange(children.get(i));
+ }
}
private void setEdgeRouter(JSONArray rbdJsonArray, Map<String, RbdTreeNode> nodeMap) {
@@ -1097,1391 +1340,4 @@
vnode.setVnodeCellNumX(numX);
vnode.setVnodeCellNumY(numY);
}
-
- @Transactional(rollbackFor = Exception.class)
- public boolean analyze(ModelRbd modelRbd) {
- boolean result = true;
- if (modelRbd == null) return result;
- Long modelId = modelRbd.getId();
- result = analyzeRbd(modelRbd, true);
- return result;
- }
-
- private boolean analyzeRbd(ModelRbd modelRbd, boolean saveFlag) {
- boolean result = true;
- String rbdsonStr = modelRbd.getContent();
-
- JSONArray rbdJsonArray = new JSONObject(rbdsonStr).getJSONArray("cells");
- if (rbdJsonArray == null) return result;
-
- // 瑙f瀽缁撴灉瀛樻斁list
- List<ModelNode> modelNodeList = new ArrayList<>();
- List<ModelLine> modelLineList = new ArrayList<>();
- List<Algorithm> algorithmList = new ArrayList<>();
- List<ProductImg> productImgList = new ArrayList<>(); // 鏆備笉浣跨敤锛堣�屼娇鐢ㄦ暟鎹簱涓殑鍙潬鎬у弬鏁帮級
-
- // 1. 瑙f瀽鍑鸿妭鐐逛笌杈�
- getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList);
- // 2. 瀵逛簬鏈夊鏍瑰叆鍙g嚎鐨勪骇鍝佽妭鐐癸紝灏嗗叾涓婄殑琛ㄥ喅銆佹梺鑱斿叧绯诲墺绂绘垚杩愮畻绗﹁妭鐐癸紝娣诲姞鍒拌鑺傜偣鐨勫墠闈紝骞舵坊鍔犵浉搴旂殑杈�
- peelOperationFromProductNode(modelRbd.getId(), modelNodeList, modelLineList);
- // 3. 璁$畻鎵�鏈夎妭鐐圭殑鍏ュ彛绾挎暟鍙婂嚭鍙g嚎鏁�
- calcInOutLineNumAllNode(modelNodeList, modelLineList);
- // 4. 澶嶅埗浜у搧鑺傜偣(node)鍒發ist
- List<ModelNode> modelNodeAndVnodeList = modelNodeList.stream().filter(item ->
- "node".equals(item.getNodeType())).collect(Collectors.toList());
- // 5. 涓嶆柇灏嗗熀鏈ā鍨嬶紙涓茶仈銆佸苟鑱斻�佹梺鑱斻�佽〃鍐炽�佹ˉ鑱旓級鏇挎崲涓鸿櫄鑺傜偣鑰岀畝鍖栧浘褰紝鐩磋嚦鏃犳硶绠�鍖栦负姝€��
- result = getAlgorithmFromRbd(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList);
-
- // 6. 杞崲涓虹畻娉曞簱鎺ュ彛XML
- if (result) {
-// result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList);
- }
-
- // 7. 淇濆瓨妯″瀷
- if (saveFlag) saveModel(modelRbd, modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList);
-
- return result;
- }
-
- private void peelOperationFromProductNode(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList) {
- List<ModelNode> nodesToAdd = new ArrayList<>();
- List<ModelLine> linesToAdd = new ArrayList<>();
- for (ModelNode node : modelNodeList) {
- List<ModelLine> inLineList = modelLineList.stream().filter(item ->
- item.getEndCell().equals(node.getPicId())).collect(Collectors.toList());
- if ("node".equals(node.getNodeType()) &&
- StringUtils.isNotBlank(node.getNodeTypeExt()) &&
- inLineList.size() > 1) {
- // 鏃佽仈or琛ㄥ喅
- ModelNode nodeNew = new ModelNode();
- Long nodeNewId = UUIDUtil.generateId();
- nodeNew.setId(nodeNewId);
- nodeNew.setPicId(nodeNewId.toString());
- nodeNew.setModelId(modelId);
- nodeNew.setNodeType(node.getNodeTypeExt());
- nodeNew.setName(node.getNodeTypeExt());
- nodeNew.setVoteNum(node.getVoteNum());
- nodeNew.setPositionX(node.getPositionX());
- nodeNew.setPositionY(node.getPositionY());
- nodesToAdd.add(nodeNew);
-
- ModelLine lineNew = new ModelLine();
- Long lineNewId = UUIDUtil.generateId();
- lineNew.setId(lineNewId);
- lineNew.setPicId(lineNewId.toString());
- lineNew.setModelId(modelId);
- lineNew.setBeginCell(nodeNewId.toString());
- lineNew.setEndCell(node.getPicId());
- linesToAdd.add(lineNew);
-
- for (ModelLine line : inLineList) {
- line.setEndCell(nodeNewId.toString());
- }
- }
- }
- modelNodeList.addAll(nodesToAdd);
- modelLineList.addAll(linesToAdd);
- }
-
- private boolean getAlgorithmFromRbd(ModelRbd modelRbd,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList) {
- // 鏍规嵁浠ヤ笅鐨勬瀯鍥捐鍒欐潵杩涜绠楁硶鍒嗚В锛�
- // 1銆佽妭鐐圭殑瀹氫箟
- // 1-1) 杩愮畻鑺傜偣锛氬叡2涓細鏃佽仈銆佽〃鍐筹紝涓旇繍绠楄妭鐐归渶鏀惧湪琚繍绠楄妭鐐圭殑鍙充晶銆�
- // 1-2) 浜у搧鑺傜偣锛氫骇鍝佹ā鍨嬩腑鐨勮妭鐐�
- // 1-3) 杩炴帴鑺傜偣锛氬叡3涓細start銆乪nd銆乧onnect
- // 1-4) 铏氳妭鐐癸細浠f浛鍩烘湰妯″瀷锛屾瀯鍥捐鍒欎笂绛夋晥浜庝骇鍝佽妭鐐�
- // 2銆佸熀鏈ā鍨嬬殑瀹氫箟
- // 2-1) 涓茶仈锛氭病鏈変笓闂ㄧ殑琛ㄧず绗﹀彿锛岀敱鑺傜偣闂寸殑杩炴帴鍏崇郴瀹氫箟銆�2涓強浠ヤ笂鐨勮妭鐐癸紙浜у搧鑺傜偣鎴栬櫄鑺傜偣锛夊彧鏋勬垚1鏉¤矾寰勶紝缁堢鑺傜偣鍙湁1涓嚭鍙o紙鍏ュ彛涓暟鏃犻檺鍒讹級銆�
- // 2-2) 骞惰仈锛氭病鏈変笓闂ㄧ殑琛ㄧず绗﹀彿锛岀敱鑺傜偣闂寸殑杩炴帴鍏崇郴瀹氫箟銆�2涓強浠ヤ笂鐨勮妭鐐癸紙浜у搧鑺傜偣鎴栬櫄鑺傜偣锛夐兘鍙湁1涓叆鍙e拰鍑哄彛锛屼笖杩欎簺鑺傜偣鎷ユ湁鍚屼竴涓叆鍙h妭鐐瑰拰鍚屼竴涓嚭鍙h妭鐐广��
- // 2-3) 鏃佽仈锛氱敱涓撻棬鐨勬梺鑱旇繍绠楃琛ㄧず锛屾瘡鏉℃梺鑱旀敮璺彧鏈�1涓妭鐐癸紙浜у搧鑺傜偣鎴栬櫄鑺傜偣锛夛紝杩欎簺鑺傜偣閮戒互璇ユ梺鑱旇妭鐐逛负鍑哄彛鑺傜偣锛屼笖杩欎簺鑺傜偣鎷ユ湁鍚屼竴涓叆鍙h妭鐐广��
- // 2-4) 琛ㄥ喅锛氱敱涓撻棬鐨勮〃鍐宠繍绠楃琛ㄧず锛屾瘡鏉¤〃鍐虫敮璺彧鏈�1涓妭鐐癸紙浜у搧鑺傜偣鎴栬櫄鑺傜偣锛夛紝杩欎簺鑺傜偣閮戒互璇ヨ〃鍐宠妭鐐逛负鍑哄彛鑺傜偣锛屼笖杩欎簺鑺傜偣鎷ユ湁鍚屼竴涓叆鍙h妭鐐广��
- // 2-5) 妗ヨ仈锛氭病鏈変笓闂ㄧ殑琛ㄧず绗﹀彿锛岀敱鑺傜偣闂寸殑杩炴帴鍏崇郴瀹氫箟銆�
- // 3銆佹牴鎹互涓婂熀鏈ā鍨嬬殑瀹氫箟锛屼笉鏂皢鍩烘湰妯″瀷绠�鍖栦负铏氳妭鐐癸紝鐩磋嚦绠�鍖栧畬姣曪紝鎴栬�呮棤娉曠畝鍖栦负姝€��
- boolean isEnd = false; // 鍥惧舰绠�鍖栧畬姣曪紙鍏ㄩ儴绠�鍖栨病浜嗭級
- boolean hasSimplified = false; // 鑷冲皯绠�鍖栦簡涓�澶勫浘褰�
- do {
- hasSimplified = false;
- hasSimplified = simplifySeries(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified);
-// hasSimplified = simplifyParallel(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified);
- hasSimplified = simplifyOperator("parallel", modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified);
- hasSimplified = simplifyOperator("switch", modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified);
- hasSimplified = simplifyOperator("vote", modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified);
- hasSimplified = simplifyBridge(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified);
- isEnd = simplifyEnd(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList);
- } while (!isEnd && hasSimplified);
-
- return isEnd;
- }
-
- private boolean simplifyEnd(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList) {
- ModelNode endNode = modelNodeList.stream().filter(item ->
- "end".equals(item.getNodeType())).collect(Collectors.toList()).get(0);
- if (endNode.getInLineNum() != 1) return false;
-
- ModelLine lineToEnd = modelLineList.stream().filter(item ->
- item.getEndCell().equals(endNode.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode node = modelNodeList.stream().filter(item ->
- lineToEnd.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (node.getInLineNum() != 1 || node.getOutLineNum() != 1) return false;
-
- ModelLine lineToNode = modelLineList.stream().filter(item ->
- item.getEndCell().equals(node.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode startNode = modelNodeList.stream().filter(item ->
- lineToNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (!"start".equals(startNode.getNodeType()) || startNode.getOutLineNum() != 1) return false;
-
- // 鍒犻櫎鑺傜偣鍙婅繛绾�
- modelLineList.remove(lineToEnd);
- modelLineList.remove(lineToNode);
- modelNodeList.remove(endNode);
- modelNodeList.remove(node);
- modelNodeList.remove(startNode);
-
- // 鐢熸垚缁撴潫鐨勭畻娉曟楠�
- // 鏂板algorithm
- Algorithm algorithm = new Algorithm();
- Long id = UUIDUtil.generateId();
- algorithm.setId(id);
- algorithm.setModelId(modelId);
- algorithm.setComputerId(id);
- algorithm.setModelType(endNode.getNodeType());
- algorithm.setAlgorithmType(endNode.getNodeType());
- algorithm.setComputerList(node.getId().toString());
- algorithm.setObjectList(node.getName());
- algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1);
- algorithmList.add(algorithm);
-
- // 鏂板缁撴潫鐨勮櫄鑺傜偣
- ModelNode vnode = new ModelNode();
- vnode.setId(id);
- vnode.setPicId(id.toString());
- vnode.setModelId(modelId);
- vnode.setNodeType("vnode");
- vnode.setName("v" + algorithm.getStep());
- modelNodeAndVnodeList.add(vnode);
-
- return true;
- }
-
- private boolean simplifySeries(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- boolean hasSimplified) {
- List<ModelNode> startNodes = modelNodeList.stream().filter(item ->
- "node,vnode,connect,end".contains(item.getNodeType())).collect(Collectors.toList());
- if (startNodes.size() == 0) return hasSimplified;
-
- for (ModelNode startNode : startNodes) {
- if (startNode.getInLineNum() != 1) continue;
-
- List<ModelNode> result = new ArrayList<>();
- if (!"end".equals(startNode.getNodeType())) result.add(startNode);
- seekPathSeries(modelNodeList, modelLineList, startNode, result);
- if (result.size() < 2) continue;
-
- ModelNode endNode = result.get(result.size() - 1);
- if ("start,parallel,switch,vote,bridge".contains(endNode.getNodeType()) || endNode.getOutLineNum() != 1) {
- result.remove(endNode);
- }
- List<ModelNode> realSeriesNodes = result.stream().filter(item ->
- !"connect".equals(item.getNodeType())).collect(Collectors.toList());
- if (realSeriesNodes.size() < 1) {
- if (result.size() < 2) continue;
- // 鏇挎崲鎴愯繛绾�
- replaceToLineSeries(modelNodeList, modelLineList, result);
- } else if (realSeriesNodes.size() == 1) {
- if (result.size() < 2) continue; // path涓婂彧鏈夎浜у搧鑺傜偣锛坣ode/vnode锛夎嚜宸憋紝鏃犻渶鍋氫粈涔�
- // 灏唒ath鏇挎崲鎴愯鑺傜偣
- replaceToTheNodeSeries(modelNodeList, modelLineList,
- result, realSeriesNodes.get(0));
- } else {
- // 灏唒ath鏇挎崲鎴愯櫄鑺傜偣
- replaceToVnodeSeries(modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, result, realSeriesNodes);
- }
- hasSimplified = true;
- }
-
- return hasSimplified;
- }
-
- private void replaceToLineSeries(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<ModelNode> path) {
- // 鑾峰彇path鐨勮捣鐐圭殑鍑哄彛绾�
- ModelNode finalNodeStart = path.get(0);
- ModelNode finalNodeEnd = path.get(path.size() - 1);
- List<ModelLine> outLines = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(finalNodeStart.getPicId())).collect(Collectors.toList());
-
- // 鍒犻櫎path涓婄殑鎵�鏈変腑闂磋繛绾垮強path鐨勭粨鏉熺偣浠ュ鐨勮妭鐐�
- for (int i = 0; i < path.size(); i++) {
- ModelNode finalNode = path.get(i);
- if (i < path.size() - 1) {
- // 灏嗗叆鍙g嚎鍒犻櫎
- List<ModelLine> lines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList());
- modelLineList.removeAll(lines);
- // 鍒犻櫎鑺傜偣
- modelNodeList.remove(finalNode);
- calcInOutLineNum(finalNode, modelLineList);
- }
- }
-
- // 灏唒ath鐨勮捣鐐圭殑鍑哄彛绾挎敼涓鸿繛鎺ュ埌path鐨勭粨鏉熺偣
- for (ModelLine line : outLines) {
- line.setBeginCell(finalNodeEnd.getPicId());
- }
-
- calcInOutLineNum(finalNodeStart, modelLineList);
- calcInOutLineNum(finalNodeEnd, modelLineList);
- }
-
- private void replaceToTheNodeSeries(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<ModelNode> path,
- ModelNode theNode) {
- // 鑾峰彇path鐨勮捣鐐圭殑鍑哄彛绾�
- ModelNode finalNodeStart = path.get(0);
- List<ModelLine> outLines = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(finalNodeStart.getPicId())).collect(Collectors.toList());
- // 鑾峰彇path鐨勭粨鏉熺偣鐨勫叆鍙g嚎
- ModelNode finalNodeEnd = path.get(path.size() - 1);
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNodeEnd.getPicId())).collect(Collectors.toList());
-
- // 鍒犻櫎path涓婄殑鎵�鏈変腑闂磋繛绾垮強theNode浠ュ鐨勮妭鐐�
- for (int i = 0; i < path.size(); i++) {
- ModelNode finalNode = path.get(i);
- if (i < path.size() - 1) {
- // 灏嗗叆鍙g嚎鍒犻櫎
- List<ModelLine> lines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList());
- modelLineList.removeAll(lines);
- }
- if (!finalNode.getId().equals(theNode.getId())) {
- modelNodeList.remove(finalNode);
- calcInOutLineNum(finalNode, modelLineList);
- }
- }
-
- // 灏唒ath鐨勮捣鐐圭殑鍑哄彛绾挎敼涓鸿繛鎺ュ埌theNode
- for (ModelLine line : outLines) {
- line.setBeginCell(theNode.getPicId());
- }
- // 灏唒ath鐨勭粨鏉熺偣鐨勫叆鍙g嚎鏀逛负杩炴帴鍒皌heNode
- for (ModelLine line : inLines) {
- line.setEndCell(theNode.getPicId());
- }
-
- calcInOutLineNum(finalNodeStart, modelLineList);
- calcInOutLineNum(finalNodeEnd, modelLineList);
- calcInOutLineNum(theNode, modelLineList);
- }
-
- private void replaceToVnodeSeries(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- List<ModelNode> path,
- List<ModelNode> seriesNodes) {
- // 鏂板algorithm
- List<String> computerList = createVnodeComputerList("series", algorithmList, modelNodeAndVnodeList, seriesNodes);
- Algorithm algorithm = new Algorithm();
- Long id = UUIDUtil.generateId();
- algorithm.setId(id);
- algorithm.setModelId(modelId);
- algorithm.setComputerId(id);
- algorithm.setModelType("series");
- algorithm.setAlgorithmType("series");
- algorithm.setComputerList(computerList.get(0));
- algorithm.setObjectList(computerList.get(1));
- algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1);
- algorithmList.add(algorithm);
-
- // 鏂板铏氳妭鐐�
- ModelNode vnode = new ModelNode();
- vnode.setId(id);
- vnode.setPicId(id.toString());
- vnode.setModelId(modelId);
- vnode.setNodeType("vnode");
- vnode.setName("v" + algorithm.getStep());
- vnode.setPositionX(path.get(0).getPositionX());
- vnode.setPositionY(path.get(0).getPositionY());
- modelNodeList.add(vnode);
- modelNodeAndVnodeList.add(vnode);
-
- // 灏唒ath鏇挎崲涓鸿铏氳妭鐐�
- for (int i = 0; i < path.size(); i++) {
- ModelNode finalNode = path.get(i);
- if (i == 0) {
- // 灏嗚鑺傜偣鐨勫嚭鍙g嚎鏀逛负杩炴帴鍒拌櫄鑺傜偣
- List<ModelLine> outLines = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(finalNode.getPicId())).collect(Collectors.toList());
- for (ModelLine line : outLines) {
- line.setBeginCell(vnode.getPicId());
- }
- // 灏嗚鑺傜偣鐨勫叆鍙g嚎鍒犻櫎
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList());
- modelLineList.removeAll(inLines);
- }
- if (i == path.size() - 1) {
- // 灏嗚鑺傜偣鐨勫叆鍙g嚎鏀逛负杩炴帴鍒拌櫄鑺傜偣
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList());
- for (ModelLine line : inLines) {
- line.setEndCell(vnode.getPicId());
- }
- // 灏嗚鑺傜偣鐨勫嚭鍙g嚎鍒犻櫎
- List<ModelLine> outLines = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(finalNode.getPicId())).collect(Collectors.toList());
- modelLineList.removeAll(outLines);
- }
- // 鍒犻櫎璇ヨ妭鐐圭殑鍑哄叆鍙g嚎
- List<ModelLine> inOutLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode.getPicId()) || item.getBeginCell().equals(finalNode.getPicId())
- ).collect(Collectors.toList());
- modelLineList.removeAll(inOutLines);
- // 鍒犻櫎璇ヨ妭鐐�
- modelNodeList.remove(finalNode);
- calcInOutLineNum(finalNode, modelLineList);
- }
-
- calcInOutLineNum(vnode, modelLineList);
- }
-
- private List<String> createVnodeComputerList(String type,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- List<ModelNode> nodes) {
- // 璋冩暣鑺傜偣椤哄簭
- List<ModelNode> sortedNodes = null;
- if ("bridge".equals(type)) {
- if (nodes.get(1).getPositionY() < nodes.get(4).getPositionY()) {
- sortedNodes = nodes;
- } else {
- sortedNodes = new ArrayList<>();
- sortedNodes.add(nodes.get(3));
- sortedNodes.add(nodes.get(4));
- sortedNodes.add(nodes.get(2));
- sortedNodes.add(nodes.get(0));
- sortedNodes.add(nodes.get(1));
- }
- } else if ("parallel".equals(type)) {
- // 鎶婅櫄鑺傜偣鍐呴儴鐨勫苟鑱旇妭鐐瑰叏閮ㄦ嬁鍑烘潵锛岃繘琛屽ぇ鎺掑簭
- sortedNodes = new ArrayList<>();
- for (ModelNode node : nodes) {
- if ("node".equals(node.getNodeType())) {
- sortedNodes.add(node);
- } else {
- // vnode
- Algorithm algorithm = algorithmList.stream().filter(item ->
- item.getId().equals(node.getId())).collect(Collectors.toList()).get(0);
- if (type.equals(algorithm.getAlgorithmType())) {
- String[] pNodesStrArr = algorithm.getComputerList().split(",");
- for (String pNodeStr : pNodesStrArr) {
- sortedNodes.add(modelNodeAndVnodeList.stream().filter(item ->
- pNodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0));
- }
- algorithmList.remove(algorithm);
- modelNodeAndVnodeList.remove(node);
- } else {
- sortedNodes.add(node);
- }
- }
- }
- sortedNodes.sort(Comparator.comparing(ModelNode::getPositionY));
- } else {
- sortedNodes = Arrays.asList(new ModelNode[nodes.size()]);
- Collections.copy(sortedNodes, nodes);
- if ("series".equals(type)) {
- Collections.reverse(sortedNodes);
- } else {
- sortedNodes.sort(Comparator.comparing(ModelNode::getPositionY));
- }
- }
-
- String computerIdList = "";
- String objectList = "";
- if ("parallel".equals(type)) {
- for (ModelNode node : sortedNodes) {
- objectList += "".equals(objectList) ? node.getName() : "," + node.getName();
- computerIdList += "".equals(computerIdList) ? node.getId().toString() : "," + node.getId().toString();
- }
- } else {
- for (ModelNode node : sortedNodes) {
- if ("node".equals(node.getNodeType())) {
- objectList += "".equals(objectList) ? node.getName() : "," + node.getName();
- computerIdList += "".equals(computerIdList) ? node.getId().toString() : "," + node.getId().toString();
- } else {
- // vnode
- Algorithm algorithm = algorithmList.stream().filter(item ->
- item.getId().equals(node.getId())).collect(Collectors.toList()).get(0);
- if ("series".equals(type) && type.equals(algorithm.getAlgorithmType())) {
- objectList += "".equals(objectList) ? algorithm.getObjectList() : "," + algorithm.getObjectList();
- computerIdList += "".equals(computerIdList) ? algorithm.getComputerList() : "," + algorithm.getComputerList();
- algorithmList.remove(algorithm);
- modelNodeAndVnodeList.remove(node);
- } else {
- objectList += "".equals(objectList) ? node.getName() : "," + node.getName();
- computerIdList += "".equals(computerIdList) ? node.getId().toString() : "," + node.getId().toString();
- }
- }
- }
- }
-
- List<String> result = new ArrayList<>();
- result.add(computerIdList);
- result.add(objectList);
- return result;
- }
-
- private void seekPathSeries(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- ModelNode startNode,
- List<ModelNode> result) {
- ModelLine inLine = modelLineList.stream().filter(item ->
- item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList()).get(0);
- if (isBridgeUpperLine(inLine, modelLineList) || isBridgeLowerLine(inLine, modelLineList)) return;
- List<ModelNode> nodes = modelNodeList.stream().filter(item ->
- inLine.getBeginCell().equals(item.getPicId())).collect(Collectors.toList());
- if (0 == nodes.size()) return; // 鍒版ˉ鑱斾腑闂磋妭鐐圭殑绾跨殑璧风偣涓嶆槸Node锛岃�屾槸Line锛屾墍浠ヨ幏鍙栫殑璧风偣鏁板彲鑳戒负0
- ModelNode pathNode = nodes.get(0);
- result.add(pathNode);
- if (pathNode.getOutLineNum() != 1 || pathNode.getInLineNum() != 1) return;
- if ("parallel,switch,vote,bridge".contains(pathNode.getNodeType())) return;
- seekPathSeries(modelNodeList, modelLineList, pathNode, result);
- }
-
- private boolean isBridgeUpperLine(ModelLine line, List<ModelLine> modelLineList) {
- boolean result = false;
- for (ModelLine ln : modelLineList) {
- if (ln.getBeginCell().equals(line.getPicId())) {
- result = true;
- break;
- }
- }
- return result;
- }
-
- private boolean isBridgeLowerLine(ModelLine line, List<ModelLine> modelLineList) {
- boolean result = false;
- for (ModelLine ln : modelLineList) {
- if (ln.getEndCell().equals(line.getPicId())) {
- result = true;
- break;
- }
- }
- return result;
- }
-
- private boolean simplifyParallel(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- boolean hasSimplified) {
- boolean hasSimplifiedMe = false;
- List<ModelNode> startNodes = modelNodeList.stream().filter(item ->
- "node,vnode,connect,end".contains(item.getNodeType())).collect(Collectors.toList());
- if (startNodes.size() == 0) return hasSimplified;
-
- for (ModelNode startNode : startNodes) {
- if (startNode.getInLineNum() < 2) continue;
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList());
- hasSimplifiedMe = simplifyParallelGroup(modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, startNode, inLines);
- if (hasSimplifiedMe) {
- hasSimplified = true;
- }
- }
-
- return hasSimplified;
- }
-
- private boolean simplifyParallelGroup(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- ModelNode startNode,
- List<ModelLine> lines) {
- boolean hasSimplified = false;
- List<List<ModelNode>> pathList = new ArrayList<>();
- for (ModelLine line : lines) {
- List<ModelNode> path = getOneBranchParallel(modelNodeList, modelLineList, line);
- if (path.size() > 0) pathList.add(path);
- }
- Map<ModelNode, List<List<ModelNode>>> endNodePathsMap = groupingPathByEndNode(pathList);
- for (Map.Entry<ModelNode, List<List<ModelNode>>> entry : endNodePathsMap.entrySet()) {
- List<List<ModelNode>> pathOneGroup = entry.getValue();
- if (pathOneGroup.size() > 1) {
- List<ModelNode> branchNodeList = new ArrayList<>();
- ModelNode endNode = getBranchNodesOneParallel(pathOneGroup, branchNodeList);
- if ("connect".equals(startNode.getNodeType()) && pathOneGroup.size() == lines.size()) {
- // 鏇挎崲鎴愯櫄鑺傜偣
- modelNodeAndVnodeList.add(startNode);
- replaceToVnode("parallel", modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, startNode, endNode, branchNodeList);
- } else {
- // 鏂板铏氳妭鐐�
- ModelNode vnode = new ModelNode();
- Long id = UUIDUtil.generateId();
- vnode.setId(id);
- vnode.setPicId(id.toString());
- vnode.setModelId(modelId);
- vnode.setNodeType("vnode");
- // 浣嶇疆璁剧疆涓哄苟鑱斾腑绗竴涓妭鐐圭殑浣嶇疆
- vnode.setPositionX(branchNodeList.get(0).getPositionX());
- vnode.setPositionY(branchNodeList.get(0).getPositionY());
-// vnode.setPositionX(startNode.getPositionX());
-// vnode.setPositionY(startNode.getPositionY());
- modelNodeList.add(vnode);
- modelNodeAndVnodeList.add(vnode);
- ModelLine modelLineNew = new ModelLine();
- Long picId2 = UUIDUtil.generateId();
- modelLineNew.setId(picId2);
- modelLineNew.setPicId(picId2.toString());
- modelLineNew.setModelId(modelId);
- modelLineNew.setBeginCell(vnode.getPicId());
- modelLineNew.setEndCell(startNode.getPicId());
- modelLineList.add(modelLineNew);
- replaceToVnode("parallel", modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, vnode, endNode, branchNodeList);
- calcInOutLineNum(startNode, modelLineList);
- }
- hasSimplified = true;
- }
- }
-
- return hasSimplified;
- }
-
- private List<ModelNode> getOneBranchParallel(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- ModelLine line) {
- List<ModelNode> path = new ArrayList<>();
- ModelNode branchNode = modelNodeList.stream().filter(item ->
- line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(branchNode.getPicId())).collect(Collectors.toList());
- List<ModelLine> outLines = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(branchNode.getPicId())).collect(Collectors.toList());
- if (inLines.size() != 1 || outLines.size() != 1) return path;
- ModelLine lineToBranchNode = inLines.get(0);
- ModelNode endNode = modelNodeList.stream().filter(item ->
- lineToBranchNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- path.add(branchNode);
- path.add(endNode);
-
- return path;
- }
-
- private Map<ModelNode, List<List<ModelNode>>> groupingPathByEndNode(List<List<ModelNode>> pathList) {
- Map<ModelNode, List<List<ModelNode>>> endNodePathsMap = new HashMap<>();
- for (List<ModelNode> path : pathList) {
- ModelNode endNode = path.get(path.size() - 1);
- if (endNodePathsMap.containsKey(endNode)) {
- endNodePathsMap.get(endNode).add(path);
- } else {
- List<List<ModelNode>> paths = new ArrayList<>();
- paths.add(path);
- endNodePathsMap.put(endNode, paths);
- }
- }
- return endNodePathsMap;
- }
-
- private ModelNode getBranchNodesOneParallel(List<List<ModelNode>> paths,
- List<ModelNode> branchNodeList) {
- ModelNode endNode = null;
- for (List<ModelNode> path : paths) {
- branchNodeList.add(path.get(0));
- endNode = path.get(path.size() - 1);
- }
- return endNode;
- }
-
- private boolean simplifyBridge(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- boolean hasSimplified) {
- boolean hasSimplifiedMe = false;
- List<ModelNode> startNodes = modelNodeList.stream().filter(item ->
- "bridge".equals(item.getNodeType())).collect(Collectors.toList());
- if (startNodes.size() == 0) return hasSimplified;
-
- for (ModelNode startNode : startNodes) {
- List<ModelLine> lines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList());
- if (lines.size() < 2) continue;
- List<ModelLinePairDto> linePairs = getLinePairs(lines);
- for (ModelLinePairDto linePair : linePairs) {
- hasSimplifiedMe = simplifyBridgeOneLinePair(modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, startNode, linePair);
- if (hasSimplifiedMe) {
- hasSimplified = true;
- break;
- }
- }
- }
-
- return hasSimplified;
- }
-
- private boolean simplifyBridgeOneLinePair(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- ModelNode startNode,
- ModelLinePairDto linePair) {
- ModelNode node1 = null;
- ModelNode node2 = null;
- ModelNode node3 = null;
- ModelNode node4 = null;
- ModelNode node5 = null;
- ModelLine line1To2 = null;
- ModelLine line4To5 = null;
-/*
- ModelNode nodeTmp1 = modelNodeList.stream().filter(item ->
- linePair.getLine1().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode nodeTmp2 = modelNodeList.stream().filter(item ->
- linePair.getLine2().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- calcInOutLineNum(nodeTmp1, modelLineList);
- calcInOutLineNum(nodeTmp2, modelLineList);
- if (nodeTmp1.getOutLineNum()!=1 || nodeTmp2.getOutLineNum()!=1) return false;
- if (nodeTmp1.getInLineNum()<1 || nodeTmp1.getInLineNum()>2) return false;
- if (nodeTmp2.getInLineNum()<1 || nodeTmp2.getInLineNum()>2) return false;
- if ((nodeTmp1.getInLineNum() + nodeTmp2.getInLineNum())!=3) return false;
- if (nodeTmp1.getInLineNum()==1) {
- node2 = nodeTmp1;
- node5 = nodeTmp2;
- } else {
- node2 = nodeTmp2;
- node5 = nodeTmp1;
- }
- ModelNode finalNode = node2;
- ModelLine line1To2 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()).get(0);
- node1 = modelNodeList.stream().filter(item ->
- line1To2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (node1.getInLineNum()!=1 || node1.getOutLineNum()!=2) return false;
- ModelNode finalNode1 = node1;
- List<ModelLine> outLinesFrom1 = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(finalNode1.getPicId())).collect(Collectors.toList());
- if (outLinesFrom1.get(0).getEndCell().equals(node2.getPicId())) {
- node3 = modelNodeList.stream().filter(item ->
- outLinesFrom1.get(1).getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- } else {
- node3 = modelNodeList.stream().filter(item ->
- outLinesFrom1.get(0).getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- }
- if (node3.getId().equals(node5.getId())) return false;
- if (node3.getInLineNum()!=1 || node3.getOutLineNum()!=1) return false;
- ModelNode finalNode2 = node3;
- ModelLine outLineFrom3 = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(finalNode2.getPicId())).collect(Collectors.toList()).get(0);
- if (!outLineFrom3.getEndCell().equals(node5.getPicId())) return false;
- ModelNode finalNode3 = node5;
- List<ModelLine> inLinesTo5 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode3.getPicId())).collect(Collectors.toList());
- if (inLinesTo5.get(0).getBeginCell().equals(node3.getPicId())) {
- node4 = modelNodeList.stream().filter(item ->
- inLinesTo5.get(1).getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- } else {
- node4 = modelNodeList.stream().filter(item ->
- inLinesTo5.get(0).getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- }
- if (node4.getId().equals(node1.getId())) return false;
- if (node4.getId().equals(node2.getId())) return false;
- if (node4.getInLineNum()!=1 || node4.getOutLineNum()!=1) return false;
- ModelNode finalNode4 = node1;
- ModelLine lineTo1 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode4.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode finalNode5 = node4;
- ModelLine lineTo4 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode5.getPicId())).collect(Collectors.toList()).get(0);
- nodeTmp1 = modelNodeList.stream().filter(item ->
- lineTo1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- nodeTmp2 = modelNodeList.stream().filter(item ->
- lineTo4.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (!nodeTmp1.getId().equals(nodeTmp2.getId())) return false;
- ModelNode endNode = nodeTmp1;
-*/
- ModelNode nodeTmp1 = modelNodeList.stream().filter(item ->
- linePair.getLine1().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode nodeTmp2 = modelNodeList.stream().filter(item ->
- linePair.getLine2().getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (nodeTmp1.getInLineNum() != 1 || nodeTmp1.getOutLineNum() != 1) return false;
- if (nodeTmp2.getInLineNum() != 1 || nodeTmp2.getOutLineNum() != 1) return false;
- ModelNode finalNode = nodeTmp1;
- ModelLine lineToNodeTmp1 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode finalNode1 = nodeTmp2;
- ModelLine lineToNodeTmp2 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode1.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode nodeTmp3 = modelNodeList.stream().filter(item ->
- lineToNodeTmp1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode nodeTmp4 = modelNodeList.stream().filter(item ->
- lineToNodeTmp2.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (nodeTmp3.getId().equals(nodeTmp4.getId())) return false;
- boolean isBridgeUpperLine1 = isBridgeUpperLine(lineToNodeTmp1, modelLineList);
- boolean isBridgeUpperLine2 = isBridgeUpperLine(lineToNodeTmp2, modelLineList);
- if (!isBridgeUpperLine1 && !isBridgeUpperLine2) return false;
- if (isBridgeUpperLine1 && isBridgeUpperLine2) return false;
- boolean isBridgeLowerLine1 = isBridgeLowerLine(lineToNodeTmp1, modelLineList);
- boolean isBridgeLowerLine2 = isBridgeLowerLine(lineToNodeTmp2, modelLineList);
- if (!isBridgeLowerLine1 && !isBridgeLowerLine2) return false;
- if (isBridgeLowerLine1 && isBridgeLowerLine2) return false;
- if (isBridgeUpperLine1) {
- line1To2 = lineToNodeTmp1;
- line4To5 = lineToNodeTmp2;
- node2 = nodeTmp1;
- node5 = nodeTmp2;
- } else {
- line1To2 = lineToNodeTmp2;
- line4To5 = lineToNodeTmp1;
- node2 = nodeTmp2;
- node5 = nodeTmp1;
- }
- ModelLine finalLine = line1To2;
- ModelLine lineTo3 = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(finalLine.getPicId())).collect(Collectors.toList()).get(0);
- ModelLine finalLine1 = line4To5;
- ModelLine lineFrom3 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalLine1.getPicId())).collect(Collectors.toList()).get(0);
- ModelLine finalLine2 = lineTo3;
- ModelNode node3Candidate1 = modelNodeList.stream().filter(item ->
- finalLine2.getEndCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- ModelLine finalLine3 = lineFrom3;
- ModelNode node3Candidate2 = modelNodeList.stream().filter(item ->
- finalLine3.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (!node3Candidate1.getId().equals(node3Candidate2.getId())) return false;
- node3 = node3Candidate1;
- if (node3.getInLineNum() != 1 || node3.getOutLineNum() != 1) return false;
- ModelLine finalLine4 = line1To2;
- node1 = modelNodeList.stream().filter(item ->
- finalLine4.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (node1.getInLineNum() != 1 || node1.getOutLineNum() != 1) return false;
- ModelLine finalLine5 = line4To5;
- node4 = modelNodeList.stream().filter(item ->
- finalLine5.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (node4.getInLineNum() != 1 || node4.getOutLineNum() != 1) return false;
- ModelNode finalNode3 = node1;
- ModelLine lineTo1 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode3.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode finalNode4 = node4;
- ModelLine lineTo4 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(finalNode4.getPicId())).collect(Collectors.toList()).get(0);
- nodeTmp1 = modelNodeList.stream().filter(item ->
- lineTo1.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- nodeTmp2 = modelNodeList.stream().filter(item ->
- lineTo4.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- if (!nodeTmp1.getId().equals(nodeTmp2.getId())) return false;
- ModelNode endNode = nodeTmp1;
-
- List<ModelNode> branchNodeList = new ArrayList<>();
- branchNodeList.add(node1);
- branchNodeList.add(node2);
- branchNodeList.add(node3);
- branchNodeList.add(node4);
- branchNodeList.add(node5);
-
- modelNodeAndVnodeList.add(startNode);
- replaceToVnode("bridge", modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, startNode, endNode, branchNodeList);
-
-/*
- if ("connect".equals(startNode.getNodeType()) && startNode.getInLineNum()==2) {
- // 鏇挎崲鎴愯櫄鑺傜偣
- modelNodeAndVnodeList.add(startNode);
- replaceToVnode("bridge", modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, startNode, endNode, branchNodeList);
- } else {
- // 鏂板铏氳妭鐐�
- ModelNode vnode = new ModelNode();
- Long id = UUIDUtil.generateId();
- vnode.setId(id);
- vnode.setPicId(id.toString());
- vnode.setModelId(modelId);
- vnode.setNodeType("vnode");
- // 灏嗕綅缃缃负绗竴涓垎鏀殑
- vnode.setPositionX(node2.getPositionX());
- vnode.setPositionY(node2.getPositionY());
-// vnode.setPositionX(startNode.getPositionX());
-// vnode.setPositionY(startNode.getPositionY());
- modelNodeList.add(vnode);
- modelNodeAndVnodeList.add(vnode);
- ModelLine modelLineNew = new ModelLine();
- Long picId2 = UUIDUtil.generateId();
- modelLineNew.setId(picId2);
- modelLineNew.setPicId(picId2.toString());
- modelLineNew.setModelId(modelId);
- modelLineNew.setBeginCell(vnode.getPicId());
- modelLineNew.setEndCell(startNode.getPicId());
- modelLineList.add(modelLineNew);
- replaceToVnode("bridge", modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, vnode, endNode, branchNodeList);
- calcInOutLineNum(startNode, modelLineList);
- }
-*/
-
- return true;
- }
-
- private void calcInOutLineNumAllNode(List<ModelNode> modelNodeList, List<ModelLine> modelLineList) {
- for (ModelNode node : modelNodeList) {
- calcInOutLineNum(node, modelLineList);
- }
- }
-
- private void calcInOutLineNum(ModelNode node, List<ModelLine> modelLineList) {
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(node.getPicId())).collect(Collectors.toList());
- List<ModelLine> outLines = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(node.getPicId())).collect(Collectors.toList());
- node.setInLineNum(inLines.size());
- node.setOutLineNum(outLines.size());
- }
-
- // 鎵惧嚭鎵�鏈�2鏍圭嚎鐨勭粍鍚�
- private List<ModelLinePairDto> getLinePairs(List<ModelLine> lines) {
- List<ModelLinePairDto> linePairs = new ArrayList<>();
- for (int i = 0; i < lines.size() - 1; i++) {
- for (int j = i + 1; j < lines.size(); j++) {
- ModelLinePairDto linePair = new ModelLinePairDto();
- linePair.setLine1(lines.get(i));
- linePair.setLine2(lines.get(j));
- linePairs.add(linePair);
- }
- }
- return linePairs;
- }
-
- private boolean simplifyOperator(String operator,
- Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- boolean hasSimplified) {
- List<ModelNode> opNodes = modelNodeList.stream().filter(item ->
- operator.equals(item.getNodeType())).collect(Collectors.toList());
- if (opNodes.size() == 0) return hasSimplified;
-
- for (ModelNode opNode : opNodes) {
- List<ModelLine> lines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(opNode.getPicId())).collect(Collectors.toList());
- boolean thisNodeSuccess = true;
- ModelNode endNode = null;
- List<ModelNode> branchNodeList = new ArrayList<>();
- for (ModelLine line : lines) {
- ModelNode curEndNode = handleOneBranch(modelNodeList, modelLineList, line, branchNodeList);
- if (curEndNode == null) {
- thisNodeSuccess = false;
- break;
- }
- if (endNode == null) {
- endNode = curEndNode;
- } else {
- if (!endNode.getId().equals(curEndNode.getId())) {
- thisNodeSuccess = false;
- break;
- }
- }
- }
- if (thisNodeSuccess) {
- modelNodeAndVnodeList.add(opNode);
- replaceToVnode(opNode.getNodeType(), modelId, modelNodeList, modelLineList,
- algorithmList, modelNodeAndVnodeList, opNode, endNode, branchNodeList);
- hasSimplified = true;
- }
- }
-
- return hasSimplified;
- }
-
- private void replaceToVnode(String type,
- Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- ModelNode startNode,
- ModelNode endNode,
- List<ModelNode> branchNodeList) {
- // 鏂板algorithm
- List<String> computerList = createVnodeComputerList(type, algorithmList, modelNodeAndVnodeList, branchNodeList);
- Algorithm algorithm = new Algorithm();
- Long id = UUIDUtil.generateId();
- algorithm.setId(id);
- algorithm.setModelId(modelId);
- algorithm.setComputerId(id);
- algorithm.setModelType(type);
- algorithm.setAlgorithmType(type);
- algorithm.setComputerList(computerList.get(0));
- algorithm.setObjectList(computerList.get(1));
- if ("vote".equals(type)) algorithm.setVoteNum(startNode.getVoteNum());
- algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1);
- algorithmList.add(algorithm);
-
- // 鏇挎崲涓鸿櫄鑺傜偣
- for (ModelNode node : branchNodeList) {
- List<ModelLine> branchNodeLineList = modelLineList.stream().filter(item ->
- item.getEndCell().equals(node.getPicId()) || item.getBeginCell().equals(node.getPicId())
- ).collect(Collectors.toList());
- modelLineList.removeAll(branchNodeLineList);
- modelNodeList.remove(node);
- calcInOutLineNum(node, modelLineList);
- }
- startNode.setId(id);
- startNode.setNodeType("vnode");
- startNode.setName("v" + algorithm.getStep());
-
- ModelLine modelLineNew = new ModelLine();
- Long picId2 = UUIDUtil.generateId();
- modelLineNew.setId(picId2);
- modelLineNew.setPicId(picId2.toString());
- modelLineNew.setModelId(modelId);
- modelLineNew.setBeginCell(endNode.getPicId());
- modelLineNew.setEndCell(startNode.getPicId());
- modelLineList.add(modelLineNew);
-
- calcInOutLineNum(startNode, modelLineList);
- calcInOutLineNum(endNode, modelLineList);
- }
-
- private ModelNode handleOneBranch(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- ModelLine line,
- List<ModelNode> branchNodeList
- ) {
- ModelNode branchNode = modelNodeList.stream().filter(item ->
- line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(branchNode.getPicId())).collect(Collectors.toList());
- List<ModelLine> outLines = modelLineList.stream().filter(item ->
- item.getBeginCell().equals(branchNode.getPicId())).collect(Collectors.toList());
- if (inLines.size() != 1 || outLines.size() != 1) return null;
- ModelLine lineToBranchNode = inLines.get(0);
- ModelNode endNode = modelNodeList.stream().filter(item ->
- lineToBranchNode.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
-
- branchNodeList.add(branchNode);
- return endNode;
- }
-
- private void getNodeAndLineFromRbd(Long modelId,
- JSONArray rbdJsonArray,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<ProductImg> productImgList) {
- Object jsonValue = null;
- for (int i = 0; i < rbdJsonArray.size(); i++) {
- JSONObject jsonObject = rbdJsonArray.getJSONObject(i);
- String shape = jsonObject.get("shape").toString();
- if ("edge".equals(shape)) {
- ModelLine modelLine = new ModelLine();
- modelLine.setId(UUIDUtil.generateId());
- modelLine.setModelId(modelId);
- modelLine.setPicId(jsonObject.get("id").toString());
- modelLine.setBeginCell(JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString());
- modelLine.setEndCell(JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString());
- modelLineList.add(modelLine);
- } else if ("image".equals(shape)) {
- ModelNode modelNode = new ModelNode();
- modelNode.setId(UUIDUtil.generateId());
- modelNode.setModelId(modelId);
- modelNode.setPicId(jsonObject.get("id").toString());
- modelNode.setNodeType(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeType".split("/")).toString());
- modelNode.setPositionX(Double.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "position/x".split("/")).toString()));
- modelNode.setPositionY(Double.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "position/y".split("/")).toString()));
- modelNode.setWidth(new Double(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()));
- modelNode.setHeight(new Double(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()));
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/voteNum".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- modelNode.setVoteNum(Integer.valueOf(jsonValue.toString()));
- }
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/startNodeId".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- modelNode.setPairStartNodeId(jsonValue.toString());
- }
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/endNodeId".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- modelNode.setPairEndNodeId(jsonValue.toString());
- }
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/edgeTopId".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- modelNode.setBridgeEdgeTopId(jsonValue.toString());
- }
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/edgeBottomId".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- modelNode.setBridgeEdgeBottomId(jsonValue.toString());
- }
- if ("dashedBox".equals(modelNode.getNodeType())) {
- modelNode.setNodeType("node");
- } else if ("node".equals(modelNode.getNodeType())) {
- ProductImg productImg = new ProductImg();
- String dataId = JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString();
- modelNode.setDataId(Long.valueOf(dataId));
- modelNode.setNodeTypeExt(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeTypeExt".split("/")).toString());
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/"));
- modelNode.setName(jsonValue == null ? "" : jsonValue.toString());
-
- productImg.setDataId(dataId);
- String productType = JsonUtils2.getJsonValueByPath(jsonObject, "data/productType".split("/")).toString();
- productImg.setProductType(productType);
- if ("product_sb".equals(productType)) {
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/reliabDistribType".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- productImg.setReliabDistribType(Integer.valueOf(jsonValue.toString()));
- if (3 == productImg.getReliabDistribType()) {
- // 浜岄」鍒嗗竷
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/simulatTimes".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- productImg.setBinomialTotalNum(Integer.valueOf(jsonValue.toString()));
- modelNode.setBinomialTotalNum(Integer.valueOf(jsonValue.toString()));
- }
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/successTimes".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- productImg.setBinomialSuccessNum(Integer.valueOf(jsonValue.toString()));
- modelNode.setBinomialSuccessNum(Integer.valueOf(jsonValue.toString()));
- }
- }
- }
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcf".split("/"));
- if (null != jsonValue) productImg.setTaskMtbcf(jsonValue.toString());
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcfOtherParams2".split("/"));
- if (null != jsonValue) productImg.setTaskMtbcfOtherParams2(jsonValue.toString());
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcfOtherParams3".split("/"));
- if (null != jsonValue) productImg.setTaskMtbcfOtherParams3(jsonValue.toString());
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/isRepair".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString()) && !"null".equals(jsonValue.toString())) {
- productImg.setIsRepair(Integer.valueOf(jsonValue.toString()));
- } else {
- productImg.setIsRepair(0);
- }
- if (1 == productImg.getIsRepair()) {
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairDistribType".split("/"));
- if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
- productImg.setRepairDistribType(Integer.valueOf(jsonValue.toString()));
- }
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcr".split("/"));
- if (null != jsonValue) productImg.setRepairMttcr(jsonValue.toString());
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcrOtherParams2".split("/"));
- if (null != jsonValue) productImg.setRepairMttcrOtherParams2(jsonValue.toString());
- jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcrOtherParams3".split("/"));
- if (null != jsonValue) productImg.setRepairMttcrOtherParams3(jsonValue.toString());
- }
- }
- productImgList.add(productImg);
- }
- modelNodeList.add(modelNode);
- }
- }
-// calcLineSortAll(modelNodeList, modelLineList);
- }
-
-/*
- private void calcLineSortAll(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList) {
- for (ModelNode node : modelNodeList) {
- List<ModelLine> inLines = modelLineList.stream().filter(item ->
- item.getEndCell().equals(node.getPicId())).collect(Collectors.toList());
- if (inLines.size() < 1) continue;
- for (ModelLine line : inLines) {
- ModelNode beginNode = modelNodeList.stream().filter(item ->
- line.getBeginCell().equals(item.getPicId())).collect(Collectors.toList()).get(0);
- line.setLineSort(beginNode.getPositionY());
- }
- }
- }
-*/
-
- private void saveModel(ModelRbd modelRbd,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algoList,
- List<ModelNode> modelNodeAndVnodeList) {
- // 鍒犻櫎鏃㈡湁鏁版嵁
- modelNodeDao.deleteByModelId(modelRbd.getId());
- modelLineDao.deleteByModelId(modelRbd.getId());
- algorithmDao.deleteByModelId(modelRbd.getId());
- modelNodeAlgorithmDao.deleteByModelId(modelRbd.getId());
-
- // 鎻掑叆鏁版嵁
- for (ModelNode modelNode : modelNodeList) {
- modelNodeDao.insert(modelNode);
- }
- for (ModelLine modelLine : modelLineList) {
- modelLineDao.insert(modelLine);
- }
- for (Algorithm algorithm : algoList) {
- algorithmDao.insert(algorithm);
- }
- for (ModelNode modelNode : modelNodeAndVnodeList) {
- modelNodeAlgorithmDao.insert(ModelNodeAlgorithm.from(modelNode));
- }
-
- // 鏇存柊RBD鏁版嵁
- modelRbd.setPublishedContent(modelRbd.getContent());
- modelRbdDao.updateById(modelRbd);
- }
-
-/* ============瑙f瀽妯″瀷鐨勭1鐗堬紝宸蹭笉浣跨敤============
- private void analyzeRbdAndSave(Long modelId, String content, boolean saveFlag) {
- String diagramJsonStr = content;
-// String diagramJsonStr = "{\"cells\":[{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"26d1a5a6-0be8-4890-86a0-a33d429e6673\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"31585e99-58c7-4a98-8824-8000743b364d\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"f2286e46-84c7-4702-8670-d7cda22c34e5\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"5123ad82-18bb-46fe-9d93-138b24b54a15\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"2ab8b7f8-7fe2-490f-89c5-4250d4a62a78\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"31585e99-58c7-4a98-8824-8000743b364d\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"port\":\"f93ccd2f-dedd-47b1-9ad0-9be20c5db8a4\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"700c05a5-f151-4b28-8135-705ccf013522\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"5123ad82-18bb-46fe-9d93-138b24b54a15\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"port\":\"f93ccd2f-dedd-47b1-9ad0-9be20c5db8a4\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"feef2a57-3c72-4d69-92a6-c828c736b61a\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"port\":\"80d3bd61-1ed3-493a-b4e8-d4576e6fbfda\"},\"target\":{\"cell\":\"da634b2e-5ffc-4e1b-a636-f86ace9eb082\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"49e36d6f-6a94-4edc-9894-6dd825091706\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"2b6df966-4e19-4055-bb13-c4c083b18e58\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"ed8c1bfa-c0a6-4e9b-8697-862aef109bcf\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"port\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},\"target\":{\"cell\":\"323f5abe-05ed-419d-9d81-d25c7d3b19f3\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"70c6b5fb-1b48-4a2f-bacd-be0284134818\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"2b6df966-4e19-4055-bb13-c4c083b18e58\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"6a134969-623b-428e-9b0c-436bae2d6608\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"323f5abe-05ed-419d-9d81-d25c7d3b19f3\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"port\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#5F95FF\"}},\"id\":\"51de5faf-1766-4dd1-abd0-eec2e867a322\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"0bb2ba89-a92d-4b32-b3cd-45df2300fa34\",\"port\":\"61eaafd2-095b-41d6-8e34-862fb470b7a6\"}},{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#A2B1C3\"}},\"id\":\"161f78dc-1f44-4e43-9ced-e39d345aac78\",\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"#5F95FF\"},\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.5,\"angle\":180,\"options\":{\"keepGradient\":true,\"ensureLegibility\":true}}}],\"zIndex\":0,\"source\":{\"cell\":\"da634b2e-5ffc-4e1b-a636-f86ace9eb082\",\"port\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},\"target\":{\"cell\":\"0bb2ba89-a92d-4b32-b3cd-45df2300fa34\",\"port\":\"61eaafd2-095b-41d6-8e34-862fb470b7a6\"}},{\"position\":{\"x\":-350,\"y\":-280},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"31585e99-58c7-4a98-8824-8000743b364d\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":1,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":-350,\"y\":-180},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"5123ad82-18bb-46fe-9d93-138b24b54a15\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":2,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":-620,\"y\":-200},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"start\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/start.88f586e1.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"f91765b1-af48-4396-84ba-eb16e3476aa5\",\"data\":{\"dataId\":\"\",\"nodeType\":\"start\",\"nodeTypeExt\":\"\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"2ad6a8d5-d86d-49e6-908a-d317b61997c1\"},{\"group\":\"right\",\"id\":\"839cb2d9-59ca-4a39-a63c-26bf60cc6989\"},{\"group\":\"bottom\",\"id\":\"7048578f-94d9-4f75-b653-eb5f43ff55db\"},{\"group\":\"left\",\"id\":\"e7bb1134-4b4c-401d-89ea-e77ae24cbd03\"}]},\"zIndex\":3,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":-153,\"y\":-240},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"switchRight\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/switchRight.74768797.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"6df9adc8-cb83-405c-8482-633db0f3644f\",\"data\":{\"dataId\":\"\",\"nodeType\":\"switchRight\",\"nodeTypeExt\":\"\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"adceedb7-f842-4d1e-be3a-8b3cb0a7e3ce\"},{\"group\":\"right\",\"id\":\"80d3bd61-1ed3-493a-b4e8-d4576e6fbfda\"},{\"group\":\"bottom\",\"id\":\"8fa84779-80b2-4c91-8366-7dd4fa0d93ff\"},{\"group\":\"left\",\"id\":\"f93ccd2f-dedd-47b1-9ad0-9be20c5db8a4\"}]},\"zIndex\":4},{\"position\":{\"x\":-21,\"y\":-240},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"da634b2e-5ffc-4e1b-a636-f86ace9eb082\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":5,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]},{\"position\":{\"x\":170,\"y\":-100},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"end\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/end.814a7041.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"0bb2ba89-a92d-4b32-b3cd-45df2300fa34\",\"data\":{\"dataId\":\"\",\"nodeType\":\"end\",\"nodeTypeExt\":\"\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"223c9b3a-6baa-4bb8-99ba-c3300db9a942\"},{\"group\":\"right\",\"id\":\"2806bc8a-4e11-4657-9af9-089907985671\"},{\"group\":\"bottom\",\"id\":\"c56eed35-95fa-4e3c-adba-9847ef705e1c\"},{\"group\":\"left\",\"id\":\"61eaafd2-095b-41d6-8e34-862fb470b7a6\"}]},\"zIndex\":6},{\"position\":{\"x\":-350,\"y\":-54},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"2b6df966-4e19-4055-bb13-c4c083b18e58\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":7},{\"position\":{\"x\":-330,\"y\":40},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"323f5abe-05ed-419d-9d81-d25c7d3b19f3\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":8},{\"position\":{\"x\":-153,\"y\":-20},\"size\":{\"width\":60,\"height\":60},\"attrs\":{\"text\":{\"refY\":\"100%\",\"textVerticalAnchor\":\"top\",\"text\":\"logo\",\"style\":{\"color\":\"#080808\"},\"refY2\":4},\"image\":{\"xlink:href\":\"dist/img/logo.36cbc06d.png\"},\"body\":{\"stroke\":\"#5F95FF\"},\"line\":{\"stroke\":\"orange\"}},\"visible\":true,\"shape\":\"image\",\"id\":\"1f378f5e-066d-49bb-a6cc-de24a8882d65\",\"data\":{\"dataId\":\"123456\",\"nodeType\":\"node\",\"nodeTypeExt\":\"aaa\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":4,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"bc0336ec-7912-4720-aea7-e5869de77692\"},{\"group\":\"right\",\"id\":\"a977d555-b8c8-4578-9a8b-3097c405c1a8\"},{\"group\":\"bottom\",\"id\":\"fef0f533-9581-4831-ba65-427f097a3d17\"},{\"group\":\"left\",\"id\":\"01eb49d9-4b1c-466f-8263-935542436c7e\"}]},\"zIndex\":9,\"labels\":[{\"attrs\":{\"body\":{\"stroke\":\"orange\"}}}]}]}";
-
- JSONObject diagramJson = new JSONObject(diagramJsonStr);
- JSONArray diagramJsonArray = diagramJson.getJSONArray("cells");
- if (diagramJsonArray == null) return;
-
- List<ModelLine> modelLineList = new ArrayList<>();
- List<ModelNode> modelNodeList = new ArrayList<>();
- // 1. 瑙f瀽鍑鸿妭鐐逛笌杈�
- for (int i = 0; i < diagramJsonArray.size(); i++) {
- JSONObject jsonObject = diagramJsonArray.getJSONObject(i);
- String shape = jsonObject.get("shape").toString();
- if (shape.equals("edge")) {
- ModelLine modelLine = new ModelLine();
- modelLine.setId(UUIDUtil.generateId());
- modelLine.setPicId(jsonObject.get("id").toString());
- modelLine.setModelId(modelId);
- modelLine.setBeginCell(JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString());
- modelLine.setEndCell(JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString());
- modelLineList.add(modelLine);
- } else if (shape.equals("image")){
- ModelNode modelNode = new ModelNode();
- modelNode.setId(UUIDUtil.generateId());
- modelNode.setPicId(jsonObject.get("id").toString());
- modelNode.setModelId(modelId);
- modelNode.setNodeType(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeType".split("/")).toString());
- if ("node".equals(modelNode.getNodeType())) {
- modelNode.setDataId(Long.valueOf(JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString()));
- modelNode.setNodeTypeExt(JsonUtils2.getJsonValueByPath(jsonObject, "data/nodeTypeExt".split("/")).toString());
- modelNode.setName(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/label/textWrap/text".split("/")).toString());
- }
- modelNodeList.add(modelNode);
- }
- }
-
- // 2. 瀵逛簬鏈夊鏍瑰叆鍙g嚎鐨勪骇鍝佽妭鐐癸紝灏嗗叾涓婄殑琛ㄥ喅銆佹梺鑱斻�佸苟鑱斿叧绯诲墺绂绘垚杩愮畻绗﹁妭鐐癸紝娣诲姞鍒拌浜у搧鑺傜偣鐨勫墠闈紝骞舵坊鍔犵浉搴旂殑杈�
- List<ModelNode> nodesToAdd = new ArrayList<>();
- List<ModelLine> linesToAdd = new ArrayList<>();
- for (ModelNode modelNode: modelNodeList) {
- String picId = modelNode.getPicId();
- List<ModelLine> lineList = modelLineList.stream().filter(item->item.getEndCell().equals(picId)).collect(Collectors.toList());
- if (lineList.size()>1){
- if ("node,end".contains(modelNode.getNodeType())){
- String nodeTypeExt = "";
- if ("node".equals(modelNode.getNodeType())) {
- nodeTypeExt = modelNode.getNodeTypeExt();
- } else if ("end".equals(modelNode.getNodeType())) {
- nodeTypeExt = "parallel";
- }
- if (StringUtils.isNotBlank(nodeTypeExt)){
- ModelNode modelNodeNew = new ModelNode();
- Long nodeNewId = UUIDUtil.generateId();
- modelNodeNew.setId(nodeNewId);
- modelNodeNew.setPicId(nodeNewId.toString());
- modelNodeNew.setModelId(modelId);
- modelNodeNew.setNodeType(nodeTypeExt);
- nodesToAdd.add(modelNodeNew);
-
- ModelLine modelLineNew = new ModelLine();
- Long lineNewId = UUIDUtil.generateId();
- modelLineNew.setId(lineNewId);
- modelLineNew.setPicId(lineNewId.toString());
- modelLineNew.setModelId(modelId);
- modelLineNew.setBeginCell(nodeNewId.toString());
- modelLineNew.setEndCell(modelNode.getPicId());
- linesToAdd.add(modelLineNew);
-
- for(ModelLine nodelLine: lineList){
- nodelLine.setEndCell(nodeNewId.toString());
- }
- }
- }
- }
- }
- modelNodeList.addAll(nodesToAdd);
- modelLineList.addAll(linesToAdd);
-
- // 3. 灏嗘渶鍩烘湰鐨勪覆銆佸苟銆佹梺鑱斻�佽〃鍐虫浛鎹负铏氳妭鐐癸紝涓嶆柇绠�鍖栧浘褰紝鐩磋嚦鏃犳硶绠�鍖栦负姝�
- List<Algorithm> algoList = new ArrayList<>();
- boolean hasLeastOne = false;
- int stepNo = 0;
- do {
- List<ModelNode> opNodeList = modelNodeList.stream().filter(item ->
- "parallel,switch,vote,end".contains(item.getNodeType())).collect(Collectors.toList());
- if (opNodeList.size() <= 0) break;
-
- hasLeastOne = false; // 鑷冲皯鑳界畝鍖�1涓浘褰�
- for (ModelNode opNode: opNodeList) {
- // 鍙宠竟杩愮畻绗﹀惊鐜�
- List<ModelLine> lineToOpNodeList = modelLineList.stream().filter(item ->
- item.getEndCell().equals(opNode.getPicId())).collect(Collectors.toList());
- List<List<ModelNode>> listPath = new ArrayList<>();
- ModelNode lastNode = null;
- boolean thisNodeSucc= true;
- for (ModelLine modelLine: lineToOpNodeList) {
- // 鍙宠竟杩愮畻绗︾殑閫愪釜璺緞寰幆
- List<ModelNode> result = new ArrayList<>();
- handleOneLine(modelLineList, modelNodeList, modelLine, result);
- listPath.add(result);
- ModelNode curLastNode = result.get(result.size()-1);
- if (lastNode == null) {
- lastNode = curLastNode;
- } else {
- if (!lastNode.getId().equals(curLastNode.getId())){
- thisNodeSucc = false;
- break;
- }
- }
- }
- if (thisNodeSucc) {
- //褰㈡垚铏氳妭鐐圭畻娉�
- stepNo = replaceToVNode(modelId, modelNodeList, modelLineList, opNode, listPath, lastNode, algoList, stepNo);
- hasLeastOne = true;
- }
- } // end for
- } while (hasLeastOne);
-
-// if (saveFlag) saveModel(modelId, modelNodeList, modelLineList, algoList);
- }
-
- private void handleOneLine(List<ModelLine> modelLineList,
- List<ModelNode> modelNodeList,
- ModelLine modelLine,
- List<ModelNode> result) {
- ModelNode modelNode = modelNodeList.stream().filter(item ->
- item.getPicId().equals(modelLine.getBeginCell())).collect(Collectors.toList()).get(0);
- result.add(modelNode);
- if ("start".equals(modelNode.getNodeType())) {
- return;
- }
- List<ModelLine> lines =modelLineList.stream().filter(item ->
- item.getBeginCell().equals(modelNode.getPicId())).collect(Collectors.toList());
- List<ModelLine> lines2 =modelLineList.stream().filter(item ->
- item.getEndCell().equals(modelNode.getPicId())).collect(Collectors.toList());
- if (lines.size()>1 || lines2.size()>1) {
- return;
- } else {
- handleOneLine(modelLineList, modelNodeList, lines2.get(0), result);
- }
- }
-
- private int replaceToVNode(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- ModelNode opNode,
- List<List<ModelNode>> listPath,
- ModelNode lastNode,
- List<Algorithm> algoList,
- int stepNo) {
- String computerList = "";
- String objectList = "";
- for (List<ModelNode> path : listPath) {
- path.remove(path.get(path.size()-1));
- Long id = null;
- String name = "";
- if (path.size()==0) {
- return stepNo;
- } else if (path.size()==1) {
- if ("end".equals(opNode.getNodeType()) && !"start".equals(lastNode.getNodeType())) return stepNo;
- id = path.get(path.size()-1).getId();
- name = path.get(path.size()-1).getName();
- } else {
- id = UUIDUtil.generateId();
- name = id.toString();
- Algorithm algo = new Algorithm();
- algo.setId(id);
- algo.setModelId(modelId);
- algo.setComputerId(id);
- algo.setModelType("series");
- algo.setAlgorithmType("series");
- algo.setComputerList(joinNodeId(path, ","));
- algo.setObjectList(joinNodeName(path, ","));
- algo.setStep(stepNo);
- stepNo++;
- algoList.add(algo);
- name = "v"+ algo.getStep();
- }
- computerList = computerList.equals("") ? id.toString() : computerList + "," + id.toString();
- objectList = objectList.equals("") ? name : objectList + "," + name;
- for (ModelNode node : path) {
- List<ModelLine> lineList4 = modelLineList.stream().filter(item ->
- item.getEndCell().equals(node.getPicId()) || item.getBeginCell().equals(node.getPicId())).collect(Collectors.toList());
- modelLineList.removeAll(lineList4);
- modelNodeList.remove(node);
- }
- }
- Algorithm algo = new Algorithm();
- Long id = UUIDUtil.generateId();
- algo.setId(id);
- algo.setModelId(modelId);
- algo.setComputerId(id);
- algo.setModelType(opNode.getNodeType());
- algo.setAlgorithmType(opNode.getNodeType());
- algo.setComputerList(computerList);
- algo.setObjectList(objectList);
- algo.setStep(stepNo);
- stepNo++;
- algoList.add(algo);
-
- //灏嗗師杩愮畻鑺傜偣鏀规垚铏氳妭鐐�
- opNode.setId(id);
- opNode.setNodeType("vnode");
- opNode.setName("v"+algo.getStep());
-
- ModelLine modelLineNew = new ModelLine();
- Long picId2 = UUIDUtil.generateId();
- modelLineNew.setId(picId2);
- modelLineNew.setPicId(picId2.toString());
- modelLineNew.setModelId(modelId);
- modelLineNew.setBeginCell(lastNode.getPicId());
- modelLineNew.setEndCell(opNode.getPicId());
- modelLineList.add(modelLineNew);
-
- return stepNo;
- }
-
- private String joinNodeId(List<ModelNode> nodeList, String sep) {
- String result = "";
- for (int i = 0; i < nodeList.size(); i++) {
- if (i > 0) result = result + sep;
- result = result + nodeList.get(i).getId().toString();
- }
- return result;
- }
-
- private String joinNodeName(List<ModelNode> nodeList, String sep) {
- String result = "";
- for (int i = 0; i < nodeList.size(); i++) {
- if (i > 0) result = result + sep;
- result = result + nodeList.get(i).getName();
- }
- return result;
- }
-============瑙f瀽妯″瀷鐨勭1鐗堬紝宸蹭笉浣跨敤============ */
-
}
diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java
index e3f3517..8609219 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java
@@ -612,8 +612,8 @@
List<TaskModelCheckResultDto> chkResult = taskService.checkTaskModel(simulatAssess.getProductId(),
simulatAssess.getTaskModelId());
if (chkResult.size() > 0) {
-// result = Result.error("妯″瀷涓嶅畬鏁达紝璇锋鏌ユā鍨嬪畾涔夊強鍙傛暟閰嶇疆銆�");
- result = Result.ok(chkResult);
+ result = Result.error("妯″瀷涓嶅畬鏁达紝璇锋鏌ユā鍨嬪畾涔夊強鍙傛暟閰嶇疆銆�");
+// result = Result.ok(chkResult);
return result;
}
@@ -1066,6 +1066,7 @@
element.addAttribute("k", algo.getVoteNum().toString());
} else if ("switch".equals(algo.getAlgorithmType())) {
element.addAttribute("type", "standby");
+ element.addAttribute("k", algo.getVoteNum().toString());
} else if ("bridge".equals(algo.getAlgorithmType())) {
element.addAttribute("type", "bridge");
}
diff --git a/web/src/views/modules/taskReliability/RBD-edit-img.vue b/web/src/views/modules/taskReliability/RBD-edit-img.vue
index b92bdab..b96eb43 100644
--- a/web/src/views/modules/taskReliability/RBD-edit-img.vue
+++ b/web/src/views/modules/taskReliability/RBD-edit-img.vue
@@ -1487,14 +1487,29 @@
const nodes = this.graph.getNodes()
for (const node of nodes) {
if (node.getData().nodeType === 'dashedBox') {
- this.$message({message: '璇ユā鍨嬩腑瀛樺湪铏氭锛屾棤娉曚繚瀛�', type: 'warning'})
- return false; // 鍙栨秷娣诲姞鑺傜偣鎿嶄綔
+ this.$message({message: '璇ユā鍨嬩腑瀛樺湪铏氭锛屾棤娉曟彁浜�', type: 'warning'})
+ return false;
}
if (node.getData().nodeType === 'vote') {
- const edges = this.graph.getConnectedEdges(node);
+ if (node.getData().voteNum === null || node.getData().voteNum === '') {
+ this.$message({message: '琛ㄥ喅鑺傜偣鐨勮〃鍐虫暟閲忔湭璁剧疆', type: 'warning'})
+ return false;
+ }
+ const edges = this.graph.getIncomingEdges(node);
if (node.getData().voteNum >= edges.length) {
- this.$message({message: '琛ㄥ喅鏁伴噺涓嶈兘楂樹簬璇ヨ妭鐐圭殑杩涚嚎鏁伴噺', type: 'warning'})
- return false; // 鍙栨秷娣诲姞鑺傜偣鎿嶄綔
+ this.$message({message: '琛ㄥ喅鑺傜偣鐨勮〃鍐虫暟閲忓繀椤诲皬浜庤鑺傜偣鐨勮繘绾挎暟閲�', type: 'warning'})
+ return false;
+ }
+ }
+ if (node.getData().nodeType === 'switch') {
+ if (node.getData().voteNum === null || node.getData().voteNum === '') {
+ this.$message({message: '鏃佽仈鑺傜偣鐨勫浠芥暟閲忔湭璁剧疆', type: 'warning'})
+ return false;
+ }
+ const edges = this.graph.getIncomingEdges(node);
+ if (node.getData().voteNum >= edges.length) {
+ this.$message({message: '鏃佽仈鑺傜偣鐨勫浠芥暟閲忓繀椤诲皬浜庤鑺傜偣鐨勮繘绾挎暟閲�', type: 'warning'})
+ return false;
}
}
}
@@ -1503,7 +1518,7 @@
await this.$http['post'](`/taskReliability/ModelLine/analyze`, this.dataForm).then(async res => {
if (res.msg === 'success') {
this.$emit('refreshDataList')
- this.$alert('瑙f瀽鎴愬姛', '鎻愮ず', {
+ this.$alert('鎻愪氦鎴愬姛', '鎻愮ず', {
confirmButtonText: '纭畾'
})
}
diff --git a/web/src/views/modules/taskReliability/SimulatAssess.vue b/web/src/views/modules/taskReliability/SimulatAssess.vue
index 752e256..e8c100b 100644
--- a/web/src/views/modules/taskReliability/SimulatAssess.vue
+++ b/web/src/views/modules/taskReliability/SimulatAssess.vue
@@ -137,11 +137,11 @@
this.dataForm.id = result.data
let res = await this.$http.post('/taskReliability/SimulatAssess/analyze', this.dataForm)
if (res.success) {
- let chkResult = res.data
- console.log(chkResult)
- if (chkResult.length == 0) {
+ // let chkResult = res.data
+ // console.log(chkResult)
+ // if (chkResult.length == 0) {
this.timers = window.setInterval(this.getStroke, 1000)
- }
+ // }
}
}
}
--
Gitblit v1.9.1