From 027f2fdeaab775c235791cd520d96a47edb23a98 Mon Sep 17 00:00:00 2001
From: wente <329538422@qq.com>
Date: 星期六, 12 十月 2024 11:56:25 +0800
Subject: [PATCH] 时序图缩略图
---
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java | 1131 +++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 905 insertions(+), 226 deletions(-)
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 65cdecd..0cea759 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
@@ -1,5 +1,6 @@
package com.zt.life.modules.mainPart.taskReliability.service;
+import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.zt.common.service.BaseService;
@@ -7,24 +8,18 @@
import com.zt.common.utils.UUIDUtil;
import com.zt.life.modules.mainPart.basicInfo.dao.ParamDataDao;
import com.zt.life.modules.mainPart.basicInfo.dao.XhProductModelDao;
-import com.zt.life.modules.mainPart.basicInfo.model.ParamData;
import com.zt.life.modules.mainPart.basicInfo.model.ProductImg;
-import com.zt.life.modules.mainPart.basicInfo.model.XhProductModel;
import com.zt.life.modules.mainPart.taskReliability.dao.*;
-import com.zt.life.modules.mainPart.taskReliability.dto.ModelLinePair;
+import com.zt.life.modules.mainPart.taskReliability.dto.ModelLinePairDto;
import com.zt.life.modules.mainPart.taskReliability.model.*;
import org.apache.commons.lang3.StringUtils;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.XMLWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zt.common.db.query.QueryFilter;
import org.springframework.transaction.annotation.Transactional;
-import java.io.StringWriter;
import java.util.*;
import java.util.stream.Collectors;
@@ -32,11 +27,47 @@
/**
* model_line
*
- * @author zt generator
+ * @author zt generator
* @since 1.0.0 2024-02-28
*/
@Service
-public class ModelLineService extends BaseService<ModelLineDao, ModelLine> {
+public class ModelLineService extends BaseService<ModelLineDao, ModelLine> {
+ private static final Logger logger = LoggerFactory.getLogger(ModelLineService.class);
+
+ // 杩愮畻
+ public static final String OPE_TYPE_SERIES = "series";
+ public static final String OPE_TYPE_PARALLEL = "parallel";
+ public static final String OPE_TYPE_SWITCH = "switch";
+ public static final String OPE_TYPE_VOTE = "vote";
+ public static final String OPE_TYPE_BRIDGE = "bridge";
+
+ // 鑺傜偣
+ /* 鑷姩甯冨眬锛歴tart涓巈nd鐨勫ぇ灏� */
+ public static final int LAYOUT_START_END_SIZE_X = 60;
+ public static final int LAYOUT_START_END_SIZE_Y = 40;
+ /* 鑷姩甯冨眬锛氳櫄妗嗙殑澶у皬 */
+ public static final int LAYOUT_DASHED_BOX_SIZE_X = 60;
+ public static final int LAYOUT_DASHED_BOX_SIZE_Y = 40;
+ /* 鑷姩甯冨眬锛氶�昏緫杩愮畻绗︾殑澶у皬 */
+ public static final int LAYOUT_OPE_NODE_SIZE_X = 50;
+ public static final int LAYOUT_OPE_NODE_SIZE_Y = 50;
+ /* 鑷姩甯冨眬锛氳澶囪妭鐐圭殑澶у皬 */
+ public static final int LAYOUT_DEVICE_NODE_SIZE_X = 60;
+ public static final int LAYOUT_DEVICE_NODE_SIZE_Y = 60;
+ /* 鑷姩甯冨眬锛歝onnect鐨勫ぇ灏� */
+ public static final int LAYOUT_CONNECT_SIZE_X = 10;
+ public static final int LAYOUT_CONNECT_SIZE_Y = 10;
+
+ // 鍗曞厓鏍硷紙瀛樻斁鑺傜偣锛�
+ /* 鑷姩甯冨眬锛氬崟鍏冩牸澶у皬 */
+ public static final int LAYOUT_CELL_SIZE_X = 120;
+ public static final int LAYOUT_CELL_SIZE_Y = 120;
+ /* 鑷姩甯冨眬锛氳妭鐐瑰崰鎹崟鍏冩牸鏁伴噺 */
+ public static final int LAYOUT_CELL_NUM_NODE_X = 1;
+ public static final int LAYOUT_CELL_NUM_NODE_Y = 1;
+ public static final int LAYOUT_CELL_NUM_CONNECT_X = 1;
+ public static final int LAYOUT_CELL_NUM_CONNECT_Y = 1;
+
@Autowired
private ModelLineDao modelLineDao;
@Autowired
@@ -77,8 +108,8 @@
@Transactional(rollbackFor = Exception.class)
public void insert(ModelRbd modelRbd) {
- if (modelRbd==null) return;
- if (modelRbd.getId()==null) return;
+ if (modelRbd == null) return;
+ if (modelRbd.getId() == null) return;
Long modelId = modelRbd.getId();
// 鍒犻櫎鏃㈡湁鏁版嵁
@@ -92,8 +123,8 @@
@Transactional(rollbackFor = Exception.class)
public void update(ModelRbd modelRbd) {
- if (modelRbd==null) return;
- if (modelRbd.getId()==null) return;
+ if (modelRbd == null) return;
+ if (modelRbd.getId() == null) return;
Long modelId = modelRbd.getId();
// 鍒犻櫎鏃㈡湁鏁版嵁
@@ -102,10 +133,644 @@
modelRbdDao.insert(modelRbd);
}
+ // 鑷姩鎺掔増RBD
+ @Transactional(rollbackFor = Exception.class)
+ public boolean layout(ModelRbd modelRbd) {
+ boolean result = true;
+ if (modelRbd == null) return result;
+ Long modelId = modelRbd.getId();
+ result = layoutRbd(modelRbd);
+ return result;
+ }
+
+ private boolean layoutRbd(ModelRbd modelRbd) {
+ 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. 閫掑綊璁$畻RBD鐨勫竷灞�绌洪棿澶у皬
+ calcLayoutSize(modelRbd, algorithmList, modelNodeAndVnodeList);
+ Collections.reverse(algorithmList);
+ RbdTreeNode root2 = listToTree(algorithmList.get(0).getComputerList(), algorithmList, modelNodeAndVnodeList);
+
+ RbdTreeNode root = new RbdTreeNode();
+
+ root.setId(Convert.toLong("20000"));
+
+ root.setName("end");
+ root.setNodeType("vnode");
+ root.setAlgorithmType("parallel");
+ root.setPicId("20000");
+ root.setPairStartNodeId("10000");
+
+ root.setBlockWidthNum(root2.getBlockWidthNum() + 2);
+ root.setBlockHeightNum(root2.getBlockHeightNum());
+ root.getChildren().add(root2);
+
+ // 7. 閫掑綊璁$畻RBD鐨勫竷灞�绌洪棿鍙傛暟锛坸銆亂鍧愭爣锛�
+ root.setBlockX(0);
+ root.setBlockY(0);
+
+ Map<String, RbdTreeNode> nodeMap = new HashMap<>();
+ calcPosition(rbdJsonArray, root, nodeMap);
+ setEdgeRouter(rbdJsonArray, nodeMap);
+
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("cells", rbdJsonArray);
+ modelRbd.setContent(jsonObject.toString());
+ // calcLayoutPosition(modelRbd, algorithmList, modelNodeAndVnodeList);
+
+ // 8. 淇濆瓨鑷姩甯冨眬妯″瀷
+ // 鏇存柊RBD鏁版嵁
+// modelRbd.setAutoLayoutContent("娴嬭瘯鏂囧瓧");
+// modelRbdDao.updateById(modelRbd);
+
+ return result;
+ }
+
+ private void setEdgeRouter(JSONArray rbdJsonArray, Map<String, RbdTreeNode> nodeMap) {
+ for (int i = 0; i < rbdJsonArray.size(); i++
+ ) {
+ JSONObject jsonObject = rbdJsonArray.getJSONObject(i);
+ if (jsonObject.get("shape").equals("edge")) {
+ String sourceId = JsonUtils2.getJsonValueByPath(jsonObject, "source/cell".split("/")).toString();
+ String targetId = JsonUtils2.getJsonValueByPath(jsonObject, "target/cell".split("/")).toString();
+ RbdTreeNode sourceNode = nodeMap.get(sourceId);
+ RbdTreeNode targetNode = nodeMap.get(targetId);
+ if (sourceNode != null) {
+ if ("connect".equals(sourceNode.getNodeType()) && !"10000".equals(sourceId)){
+ if (sourceNode.getY()+sourceNode.getMyHeight()/2 == targetNode.getY()+targetNode.getMyHeight()/2){
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split(","));
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split(","));
+ }else{
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"top,bottom".split(","));
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split(","));
+ }
+ }
+ }
+ if (targetNode != null) {
+ if ("parallel,vote".contains(targetNode.getNodeType())){
+ if (sourceNode.getY()+sourceNode.getMyHeight()/2 == targetNode.getY()+targetNode.getMyHeight()/2){
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split(""));
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"left".split(""));
+ }else{
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/startDirections".split("/"),"right".split(""));
+ JsonUtils2.setJsonValueByPath(jsonObject, "router/args/endDirections".split("/"),"top,bottom".split(""));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void setNodePositionXY(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) {
+ Double x = block.getBlockX() + (block.getBlockWidth() - block.getMyWidth()) / 2;
+ Double y = block.getBlockY() + (block.getBlockHeight() - block.getMyHeight()) / 2;
+ block.setX(x);
+ block.setY(y);
+ nodeMap.put(block.getPicId(),block);
+ setRbdNodePosition(rbdJsonArray, block.getPicId(), x, y);
+ }
+
+ private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block, Map<String, RbdTreeNode> nodeMap) {
+ if (block.getNodeType().equals("node")) {
+ setNodePositionXY(rbdJsonArray, block,nodeMap);
+ } else {
+ double blockWidth = block.getBlockWidthNum() * LAYOUT_CELL_SIZE_X;
+ double blockHeight = block.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y;
+
+ Double descentWidth = block.getDescentWidth();
+ if (descentWidth == null || descentWidth == 0.0) {
+ descentWidth = blockWidth;
+ }
+ Double descentHeight = block.getDescentHeight();
+ if (descentHeight == null || descentHeight == 0.0) {
+ descentHeight = blockHeight;
+ }
+
+ block.setBlockWidth(blockWidth);
+ block.setBlockHeight(blockHeight);
+ List<RbdTreeNode> children = block.getChildren();
+
+ if (OPE_TYPE_SERIES.equals(block.getAlgorithmType())) {
+ Double subBlockX = block.getBlockX();
+ for (RbdTreeNode child : children) {
+
+ child.setDescentWidth(blockWidth);
+ child.setDescentHeight(blockHeight);
+
+ double selfWidth = child.getBlockWidthNum() * LAYOUT_CELL_SIZE_X * descentWidth / blockWidth;
+ child.setBlockWidth(selfWidth);
+ child.setBlockHeight(blockHeight);
+
+ child.setBlockY(block.getBlockY());
+ child.setBlockX(subBlockX);
+ calcPosition(rbdJsonArray, child, nodeMap);
+ subBlockX = subBlockX + selfWidth;
+
+ }
+ } else {
+
+ Double subBlockY = block.getBlockY() + (descentHeight - blockHeight) / 2;
+ Double firstSubBlockY = subBlockY;
+
+ // 璁剧疆connect鐨勪綅缃�
+ RbdTreeNode connectBlock = new RbdTreeNode();
+ connectBlock.setMyWidth(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/width"));
+ connectBlock.setMyHeight(getRbdNodeInfo(rbdJsonArray, block.getPairStartNodeId(), "size/height"));
+ connectBlock.setNodeType("connect");
+ connectBlock.setPicId(block.getPairStartNodeId());
+ connectBlock.setBlockX(block.getBlockX());
+ connectBlock.setBlockY(firstSubBlockY);
+ connectBlock.setBlockWidth(LAYOUT_CELL_SIZE_X);
+ connectBlock.setBlockHeight(blockHeight);
+ setNodePositionXY(rbdJsonArray, connectBlock, nodeMap);
+
+ for (RbdTreeNode child : children) {
+ child.setDescentWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X);
+ child.setDescentHeight(blockHeight);
+
+ child.setBlockWidth(block.getBlockWidth() - 2 * LAYOUT_CELL_SIZE_X);
+ child.setBlockHeight(child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y);
+
+ child.setBlockX(block.getBlockX() + LAYOUT_CELL_SIZE_X);
+ child.setBlockY(subBlockY);
+ subBlockY = subBlockY + child.getBlockHeightNum() * LAYOUT_CELL_SIZE_Y;
+ calcPosition(rbdJsonArray, child, nodeMap);
+ }
+
+ // 璁剧疆杩愮畻绗︾殑浣嶇疆
+ RbdTreeNode opeBlock = new RbdTreeNode();
+
+ opeBlock.setPicId(block.getPicId());
+ opeBlock.setNodeType("parallel");
+ opeBlock.setMyWidth(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/width"));
+ opeBlock.setMyHeight(getRbdNodeInfo(rbdJsonArray, block.getPicId(), "size/height"));
+ opeBlock.setBlockX(block.getBlockX() + blockWidth - LAYOUT_CELL_SIZE_X);
+ opeBlock.setBlockY(firstSubBlockY);
+ opeBlock.setBlockWidth(LAYOUT_CELL_SIZE_X);
+ opeBlock.setBlockHeight(blockHeight);
+ setNodePositionXY(rbdJsonArray, opeBlock, nodeMap);
+ }
+ }
+
+ }
+
+ private RbdTreeNode listToTree(String id,
+ List<Algorithm> algorithmList,
+ List<ModelNode> modelNodeAndVnodeList) {
+
+ List<Algorithm> algos = algorithmList.stream().filter(item ->
+ id.equals(item.getId().toString())).collect(Collectors.toList());
+
+ RbdTreeNode subNode = new RbdTreeNode();
+ subNode.setId(Convert.toLong(id));
+ ModelNode nd = modelNodeAndVnodeList.stream().filter(item ->
+ id.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ subNode.setName(nd.getName());
+ subNode.setNodeType(nd.getNodeType());
+ subNode.setPicId(nd.getPicId());
+
+ if (!"vnode".equals(nd.getNodeType())) {
+ subNode.setMyWidth(nd.getWidth());
+ subNode.setMyHeight(nd.getHeight());
+ }
+ subNode.setBlockWidthNum(nd.getVnodeCellNumX());
+ subNode.setBlockHeightNum(nd.getVnodeCellNumY());
+ subNode.setPairStartNodeId(nd.getPairStartNodeId());
+ subNode.setPairEndNodeId(nd.getPairEndNodeId());
+ if (algos.size() > 0) {
+ Algorithm algo = algos.get(0);
+ subNode.setAlgorithmType(algo.getAlgorithmType());
+ String str = algo.getComputerList();
+ String[] ids = str.split(",");
+ for (String subId : ids) {
+ subNode.getChildren().add(listToTree(subId, algorithmList, modelNodeAndVnodeList));
+ }
+ }
+ return subNode;
+ }
+
+ /*
+ */
+
+ /**
+ * 鏍规嵁椤跺眰RBD鐨勪綅缃紙x锛寉锛夛紝鑷《鍚戜笅閫掑綊璁$畻鍚勪釜鑺傜偣鐨勪綅缃紙x锛寉锛�
+ *
+ * @param modelRbd
+ * @param algorithmList
+ * @param modelNodeAndVnodeList
+ *//*
+
+ private void calcLayoutPosition(ModelRbd modelRbd,
+ List<Algorithm> algorithmList,
+ List<ModelNode> modelNodeAndVnodeList) {
+ String rbdsonStr = modelRbd.getContent();
+ JSONArray rbdJsonArray = new JSONObject(rbdsonStr).getJSONArray("cells");
+ Algorithm endAlgo = algorithmList.stream().filter(item ->
+ "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0);
+ ModelNode topNode = modelNodeAndVnodeList.stream().filter(item ->
+ endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ Algorithm topAlgo = algorithmList.stream().filter(item ->
+ endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ // 灏唗opNode鐨勫潗鏍囧畾涓篊ell(0锛�0)锛屽弽绠楁墍鏈夎妭鐐圭殑鍧愭爣
+ // 1. 璁$畻鑺傜偣鐨凜ell浣嶇疆
+ calcNodeLayoutPositionCell(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo, 0, 0,
+ topNode.getVnodeCellNumX(), topNode.getVnodeCellNumY());
+ // 2. 璁$畻鑺傜偣鐨剎锛寉鍧愭爣浣嶇疆
+ calcNodeLayoutPosition(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo);
+ // 3. 璁剧疆start鐨勪綅缃�
+ double distance = 200.0;
+ double y = (topNode.getPositionCellY() + topNode.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_START_END_SIZE_Y) / 2;
+ setRbdNodePosition(rbdJsonArray, "10000", 0 - distance, y);
+ // 4. 璁剧疆end鐨勪綅缃�
+ double x = topNode.getVnodeCellNumX() * LAYOUT_CELL_SIZE_X + distance - LAYOUT_START_END_SIZE_X;
+ setRbdNodePosition(rbdJsonArray, "20000", x, y);
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("cells", rbdJsonArray);
+ modelRbd.setContent(jsonObject.toString());
+ }
+*/
+
+/*
+ // 閫掑綊鍑芥暟锛堣绠楀悇鑺傜偣鐨剎锛寉鍧愭爣浣嶇疆锛�
+ private void calcNodeLayoutPosition(JSONArray rbdJsonArray,
+ List<Algorithm> algorithmList,
+ List<ModelNode> modelNodeAndVnodeList,
+ ModelNode node,
+ Algorithm algo) {
+ // 鏈娇鐢ㄨ澶囩殑瀹為檯瀹姐�侀珮
+ double x;
+ double y;
+ if ("node".equals(node.getNodeType())) {
+ x = node.getPositionCellX() * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_DEVICE_NODE_SIZE_X) / 2;
+ y = node.getPositionCellY() * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_DEVICE_NODE_SIZE_Y) / 2;
+ node.setPositionX(x);
+ node.setPositionY(y);
+ setRbdNodePosition(rbdJsonArray, node.getPicId(), node.getPositionX(), node.getPositionY());
+ } else if ("vnode".equals(node.getNodeType())) {
+ String[] computerNodeListStr = algo.getComputerList().split(",");
+ switch (algo.getAlgorithmType()) {
+ case OPE_TYPE_SERIES:
+ case OPE_TYPE_PARALLEL:
+ case OPE_TYPE_SWITCH:
+ case OPE_TYPE_VOTE:
+ for (String nodeStr : computerNodeListStr) {
+ ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
+ nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ List<Algorithm> childAlgos = algorithmList.stream().filter(item ->
+ childNode.getId().equals(item.getId())).collect(Collectors.toList());
+ Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null;
+ calcNodeLayoutPosition(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ childNode,
+ childAlgo);
+ }
+ if (OPE_TYPE_PARALLEL.equals(algo.getAlgorithmType())
+ || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType())
+ || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) {
+ // 璁剧疆connect鐨勪綅缃�
+ x = node.getPositionCellX() * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_CONNECT_SIZE_X) / 2;
+ y = (node.getPositionCellY() + node.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_CONNECT_SIZE_Y) / 2;
+ setRbdNodePosition(rbdJsonArray, node.getPairStartNodeId(), x, y);
+ // 璁剧疆杩愮畻绗︾殑浣嶇疆
+ x = (node.getPositionCellX() + node.getVnodeCellNumX() - 1) * LAYOUT_CELL_SIZE_X + (LAYOUT_CELL_SIZE_X - LAYOUT_OPE_NODE_SIZE_X) / 2;
+ y = (node.getPositionCellY() + node.getVnodeCellNumY() / 2) * LAYOUT_CELL_SIZE_Y + (LAYOUT_CELL_SIZE_Y - LAYOUT_OPE_NODE_SIZE_Y) / 2;
+ setRbdNodePosition(rbdJsonArray, node.getPicId(), x, y);
+ }
+ break;
+ case OPE_TYPE_BRIDGE:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ // 閫掑綊鍑芥暟锛堣绠楀悇鑺傜偣鐨凜ell浣嶇疆锛屼互宸︿笂瑙掍负Cell浣嶇疆0锛�0锛�
+ private void calcNodeLayoutPositionCell(JSONArray rbdJsonArray,
+ List<Algorithm> algorithmList,
+ List<ModelNode> modelNodeAndVnodeList,
+ ModelNode node,
+ Algorithm algo,
+ double originCellX,
+ double originCellY,
+ double maxX,
+ double maxY) {
+ if ("node".equals(node.getNodeType())) {
+ //璁剧疆node锛堣澶囪妭鐐癸級Cell浣嶇疆
+ double width = LAYOUT_DEVICE_NODE_SIZE_X * maxX;
+ double hight = LAYOUT_DEVICE_NODE_SIZE_Y * maxY;
+ double x = originCellX + (width - LAYOUT_DEVICE_NODE_SIZE_X) / 2;
+ double y = originCellY + (hight - LAYOUT_DEVICE_NODE_SIZE_Y) / 2;
+ node.setPositionCellX(x);
+ node.setPositionCellY(y);
+ } else if ("vnode".equals(node.getNodeType())) {
+ String[] computerNodeListStr = algo.getComputerList().split(",");
+ switch (algo.getAlgorithmType()) {
+ case OPE_TYPE_SERIES:
+ case OPE_TYPE_PARALLEL:
+ case OPE_TYPE_SWITCH:
+ case OPE_TYPE_VOTE:
+ double preNodeCellX = 0.0;
+ double preNodeCellY = 0.0;
+ for (String nodeStr : computerNodeListStr) {
+ ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
+ nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ List<Algorithm> childAlgos = algorithmList.stream().filter(item ->
+ childNode.getId().equals(item.getId())).collect(Collectors.toList());
+ Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null;
+ if (OPE_TYPE_SERIES.equals(algo.getAlgorithmType())) {
+ calcNodeLayoutPositionCell(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ childNode,
+ childAlgo,
+ originCellX + preNodeCellX,
+ originCellY, node.getVnodeCellNumX(), node.getVnodeCellNumY()
+ );
+ preNodeCellX += childNode.getVnodeCellNumX();
+ } else {
+ calcNodeLayoutPositionCell(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ childNode,
+ childAlgo,
+ originCellX + 1,
+ originCellY + preNodeCellY, node.getVnodeCellNumX(), node.getVnodeCellNumY());
+ preNodeCellY += childNode.getVnodeCellNumY();
+ }
+ }
+*/
+/*
+ // 璁剧疆杩愮畻绗︾殑Cell浣嶇疆
+ if (OPE_TYPE_SERIES.equals(algo.getAlgorithmType())) {
+ node.setPositionCellX(originCellX);
+ } else {
+ node.setPositionCellX(originCellX + node.getVnodeCellNumX() - 1);
+ }
+ node.setPositionCellY(originCellY + node.getVnodeCellNumY()/2);
+*//*
+
+ // 闇�鑺傜偣浠h〃鏁翠釜閫昏緫鍗曞厓锛屽洜姝ゅ叾鍧愭爣涓簅riginCellX鍜宱riginCellX
+ node.setPositionCellX(originCellX);
+ node.setPositionCellY(originCellX);
+ break;
+ case OPE_TYPE_BRIDGE:
+*/
+/*
+ ModelNode node1 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[0].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node2 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[1].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node3 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[2].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node4 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[3].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node5 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[4].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ Algorithm algo1 = algorithmList.stream().filter(item ->
+ node1.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ Algorithm algo2 = algorithmList.stream().filter(item ->
+ node2.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ Algorithm algo3 = algorithmList.stream().filter(item ->
+ node3.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ Algorithm algo4 = algorithmList.stream().filter(item ->
+ node4.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ Algorithm algo5 = algorithmList.stream().filter(item ->
+ node5.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ // 1锛岃绠椾笁琛岀殑鎬婚珮搴�
+ // 1.1 璁$畻绗竴琛屼袱涓妭鐐圭殑楂樺害
+ int firstRowCellNumY = Math.max(node1.getVnodeCellNumY(), node2.getVnodeCellNumY());
+ // 1.2 璁$畻绗簩琛屾ˉ鑱旇妭鐐圭殑楂樺害
+ int secondRowCellNumY = node3.getVnodeCellNumY();
+ // 1.3 璁$畻绗笁琛屼袱涓妭鐐圭殑楂樺害
+ int thirdRowCellNumY = Math.max(node4.getVnodeCellNumY(), node5.getVnodeCellNumY());
+// int totalCellNumY = firstRowCellNumY + secondRowCellNumY + thirdRowCellNumY;
+ // 2. 璁$畻涓夎鍚勮妭鐐圭殑鍧愭爣
+ // 2.1 璁$畻绗竴琛屼袱涓妭鐐圭殑鍧愭爣
+ calcNodeLayoutPositionCell(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ node1,
+ algo1,
+ originCellX + 1,
+ originCellY);
+ calcNodeLayoutPositionCell(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ node2,
+ algo2,
+ originCellX + 1 + node1.getPositionCellX(),
+ originCellY);
+ // 2.2 璁$畻绗簩琛屾ˉ鑱旇妭鐐圭殑鍧愭爣
+ calcNodeLayoutPositionCell(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ node3,
+ algo3,
+ originCellX + 1,
+ originCellY + firstRowCellNumY);
+ // 2.3 璁$畻绗笁琛屼袱涓妭鐐圭殑鍧愭爣
+ calcNodeLayoutPositionCell(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ node4,
+ algo4,
+ originCellX + 1,
+ originCellY + firstRowCellNumY + secondRowCellNumY);
+ calcNodeLayoutPositionCell(rbdJsonArray,
+ algorithmList,
+ modelNodeAndVnodeList,
+ node5,
+ algo5,
+ originCellX + 1 + node4.getPositionCellX(),
+ originCellY + firstRowCellNumY + secondRowCellNumY);
+ // 2.4 璁$畻妗ヨ仈杩愮畻绗︾殑鍧愭爣
+ node.setPositionCellX(originCellX + 1);
+ node.setPositionCellY(originCellY + node.getVnodeCellNumY()/2);
+*//*
+
+ break;
+ default:
+ break;
+ }
+ }
+ }
+*/
+ private void setRbdNodePosition(JSONArray rbdJsonArray,
+ String id,
+ double x,
+ double y) {
+ for (int i = 0; i < rbdJsonArray.size(); i++) {
+ JSONObject jsonObject = rbdJsonArray.getJSONObject(i);
+ if (id.equals(jsonObject.get("id").toString())) {
+ JsonUtils2.setJsonValueByPath(jsonObject, "position/x".split("/"), x);
+ JsonUtils2.setJsonValueByPath(jsonObject, "position/y".split("/"), y);
+ }
+ }
+ }
+
+ private Double getRbdNodeInfo(JSONArray rbdJsonArray,
+ String picId,
+ String path) {
+ for (int i = 0; i < rbdJsonArray.size(); i++) {
+ JSONObject jsonObject = rbdJsonArray.getJSONObject(i);
+ if (picId.equals(jsonObject.get("id").toString())) {
+ return Convert.toDouble(JsonUtils2.getJsonValueByPath(jsonObject, path.split("/")));
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 鑷簳鍚戜笂閫掑綊鍚堣鍑烘暣涓猂BD鐨勫ぇ灏忥紙妯悜鍙婄旱鍚戞墍鍗犲崟鍏冩牸鐨勬暟閲忥級
+ *
+ * @param modelRbd
+ * @param algorithmList
+ * @param modelNodeAndVnodeList
+ */
+ private void calcLayoutSize(
+ ModelRbd modelRbd,
+ List<Algorithm> algorithmList,
+ List<ModelNode> modelNodeAndVnodeList) {
+ Algorithm endAlgo = algorithmList.stream().filter(item ->
+ "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0);
+ ModelNode topNode = modelNodeAndVnodeList.stream().filter(item ->
+ endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ Algorithm topAlgo = algorithmList.stream().filter(item ->
+ endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ calcNodeLayoutSize(algorithmList, modelNodeAndVnodeList, topNode, topAlgo);
+ }
+
+ // 閫掑綊鍑芥暟
+ private void calcNodeLayoutSize(List<Algorithm> algorithmList,
+ List<ModelNode> modelNodeAndVnodeList,
+ ModelNode node,
+ Algorithm algo) {
+ if ("node".equals(node.getNodeType())) {
+ //璁剧疆node锛堣澶囪妭鐐癸級甯冨眬淇℃伅
+// node.setWidth(LAYOUT_DEVICE_NODE_SIZE_X);
+// node.setHeight(LAYOUT_DEVICE_NODE_SIZE_Y);
+ node.setCellNumX(LAYOUT_CELL_NUM_NODE_X);
+ node.setCellNumY(LAYOUT_CELL_NUM_NODE_Y);
+ node.setVnodeCellNumX(node.getCellNumX());
+ node.setVnodeCellNumY(node.getCellNumY());
+ } else if ("vnode".equals(node.getNodeType())) {
+ // 1. 璁剧疆vnode锛堣繍绠楄妭鐐癸級甯冨眬淇℃伅锛堝叾瀹炰覆鑱旀病鏈夎繍绠楃锛屼笉闇�瑕佽缃紝浣嗘槸璁剧疆浜嗕篃娌℃湁鍧忓锛屾墍浠ヤ笉浣滃尯鍒嗭級
+// node.setWidth(LAYOUT_OPE_NODE_SIZE_X);
+// node.setHeight(LAYOUT_OPE_NODE_SIZE_Y);
+ node.setCellNumX(LAYOUT_CELL_NUM_NODE_X);
+ node.setCellNumY(LAYOUT_CELL_NUM_NODE_Y);
+
+ // 2. 璁剧疆铏氳妭鐐瑰竷灞�淇℃伅
+ // 2.1 璁剧疆铏氳妭鐐瑰唴鍚勮繍绠楀璞$殑甯冨眬淇℃伅
+ String[] computerNodeListStr = algo.getComputerList().split(",");
+ for (String nodeStr : computerNodeListStr) {
+ ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
+ nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ List<Algorithm> childAlgos = algorithmList.stream().filter(item ->
+ childNode.getId().equals(item.getId())).collect(Collectors.toList());
+ Algorithm childAlgo = childAlgos.size() > 0 ? childAlgos.get(0) : null;
+ calcNodeLayoutSize(algorithmList,
+ modelNodeAndVnodeList,
+ childNode,
+ childAlgo);
+ }
+ // 2.2 璁剧疆铏氳妭鐐规�荤殑甯冨眬淇℃伅鍒拌繍绠楄妭鐐逛腑
+ setVnodeLayoutNum(computerNodeListStr, modelNodeAndVnodeList, node, algo);
+ }
+ }
+
+ private void setVnodeLayoutNum(String[] computerNodeListStr,
+ List<ModelNode> modelNodeAndVnodeList,
+ ModelNode vnode,
+ Algorithm algo) {
+ int numX = 0;
+ int numY = 0;
+ // 1. 璁$畻涓层�佸苟銆佹梺鑱斻�佽〃鍐�
+ for (String nodeStr : computerNodeListStr) {
+ ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
+ nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ switch (algo.getAlgorithmType()) {
+ case OPE_TYPE_SERIES:
+ numX += childNode.getVnodeCellNumX();
+ numY = childNode.getVnodeCellNumY() > numY ? childNode.getVnodeCellNumY() : numY;
+ break;
+ case OPE_TYPE_PARALLEL:
+ case OPE_TYPE_SWITCH:
+ case OPE_TYPE_VOTE:
+ numX = childNode.getVnodeCellNumX() > numX ? childNode.getVnodeCellNumX() : numX;
+ numY += childNode.getVnodeCellNumY();
+ break;
+ default:
+ break;
+ }
+ }
+ if (OPE_TYPE_PARALLEL.equals(algo.getAlgorithmType())
+ || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType())
+ || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) {
+ // 鍔犱笂connect鐨勫ぇ灏�
+ numX += LAYOUT_CELL_NUM_CONNECT_X;
+ numX += vnode.getCellNumX();
+ }
+ // 2. 璁$畻妗ヨ仈
+ if (OPE_TYPE_BRIDGE.equals(algo.getAlgorithmType())) {
+ // 妗ヨ仈鏀矾绠椾竴琛岋紝鏁翠釜妗ヨ仈鍏�3琛�
+ // 2.1 璁$畻绗竴琛�
+ ModelNode node1 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[0].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node2 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[1].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node3 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[2].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node4 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[3].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ ModelNode node5 = modelNodeAndVnodeList.stream().filter(item ->
+ computerNodeListStr[4].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
+ int numX1 = node1.getCellNumX() + node2.getCellNumX();
+ int numY1 = node1.getCellNumY() > node2.getCellNumY() ? node1.getCellNumY() : node2.getCellNumY();
+ // 2.2 璁$畻绗簩琛岋紙妗ヨ仈鏀矾锛屾í鍚戠敾鍥撅級
+ int numX2 = node3.getCellNumX();
+ int numY2 = node3.getCellNumY();
+ // 2.3 璁$畻绗笁琛�
+ int numX3 = node4.getCellNumX() + node5.getCellNumX();
+ int numY3 = node4.getCellNumY() > node5.getCellNumY() ? node4.getCellNumY() : node5.getCellNumY();
+ numX = Math.max(Math.max(numX1, numX2), numX3);
+ numY = numY1 + numY2 + numY3;
+ // 2.4 鍔犱笂connect鐨勫ぇ灏�
+ numX += LAYOUT_CELL_NUM_CONNECT_X;
+ numX += vnode.getCellNumX();
+ }
+ vnode.setVnodeCellNumX(numX);
+ vnode.setVnodeCellNumY(numY);
+ }
+
@Transactional(rollbackFor = Exception.class)
public boolean analyze(ModelRbd modelRbd) {
boolean result = true;
- if (modelRbd==null) return result;
+ if (modelRbd == null) return result;
Long modelId = modelRbd.getId();
result = analyzeRbd(modelRbd, true);
return result;
@@ -138,7 +803,7 @@
// 6. 杞崲涓虹畻娉曞簱鎺ュ彛XML
if (result) {
- result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList);
+// result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList);
}
// 7. 淇濆瓨妯″瀷
@@ -152,14 +817,14 @@
List<ModelLine> modelLineList) {
List<ModelNode> nodesToAdd = new ArrayList<>();
List<ModelLine> linesToAdd = new ArrayList<>();
- for (ModelNode node: modelNodeList) {
+ 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();
+ ModelNode nodeNew = new ModelNode();
Long nodeNewId = UUIDUtil.generateId();
nodeNew.setId(nodeNewId);
nodeNew.setPicId(nodeNewId.toString());
@@ -180,141 +845,13 @@
lineNew.setEndCell(node.getPicId());
linesToAdd.add(lineNew);
- for(ModelLine line: inLineList){
+ for (ModelLine line : inLineList) {
line.setEndCell(nodeNewId.toString());
}
}
}
modelNodeList.addAll(nodesToAdd);
modelLineList.addAll(linesToAdd);
- }
-
- private boolean createIfXmlFromRbd(ModelRbd modelRbd,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList) {
- boolean result = true;
-
- try {
- Document document = DocumentHelper.createDocument();
- // 娣诲姞root鑺傜偣
- Element root = document.addElement("DES");
- root.addAttribute("Name", "A System");
- // 娣诲姞terminal鑺傜偣鍒皉oot1
- Element terminal = root.addElement("Node");
- terminal.addAttribute("Name", "Terminal");
- terminal.addAttribute("Type", "NODE");
-
- // 灏嗘ā鍨嬭浆鎹负DOM锛屾坊鍔犲埌root
- Algorithm endAlgo = algorithmList.stream().filter(item ->
- "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0);
- ModelNode computerNode = modelNodeAndVnodeList.stream().filter(item ->
- endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
- node2DOM(algorithmList, modelNodeAndVnodeList, computerNode, root);
-
- // 娣诲姞start鑺傜偣鍒皉oot
- Element start = root.addElement("Node");
- start.addAttribute("Name", "Start");
- start.addAttribute("Type", "NODE");
- // 娣诲姞link锛堣矾寰勶級鍒皉oot
- Element link = root.addElement("Link");
- Element block = link.addElement("Block");
- block.addAttribute("Name", "Terminal");
- block = link.addElement("Block");
- block.addAttribute("Name", computerNode.getId().toString());
- block = link.addElement("Block");
- block.addAttribute("Name", "Start");
-
-// document.setXMLEncoding("UTF-8");
-// String xmlString = document.asXML();
- // 杈撳嚭鏍煎紡鍖杧ml
- XMLWriter xmlWriter = null;
- try {
- OutputFormat format = OutputFormat.createPrettyPrint();
- format.setEncoding("UTF-8");
- StringWriter writer = new StringWriter();
- xmlWriter = new XMLWriter(writer, format);
- xmlWriter.write(document);
- modelRbd.setPublishedXml(writer.toString());
- } finally {
- if (xmlWriter!=null) xmlWriter.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- result = false;
- }
-
- return result;
- }
-
- // 閫掑綊鍑芥暟
- private void node2DOM(List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- ModelNode node,
- Element parent) {
- if ("node".equals(node.getNodeType())) {
- Long dataId = node.getDataId();
- XhProductModel xhProductModel = xhProductModelDao.getById(dataId);
- if (xhProductModel == null) return;
- if ("1".equals(xhProductModel.getProductType())) {
- // 璁惧
- ParamData paramData = paramDataDao.getParamData(dataId, "expect");
- if (paramData == null) return;
- Element element = parent.addElement("Node");
- element.addAttribute("Name", dataId.toString());
- element.addAttribute("Type", "NODE");
- Element failureTag = element.addElement("Failure");
- failureTag.addAttribute("Dist", "EXP"); // TODO:闇�璁句负鍏蜂綋鐨勫垎甯�
- Element argsTag = failureTag.addElement("Args");
- Double value = new Double(paramData.getTaskMtbcfRegulate());
- value = 1.0/value;
- argsTag.addAttribute("value", value.toString());
- if (1==paramData.getRepairable()) {
- Element repairTag = element.addElement("Repair");
- repairTag.addAttribute("Dist", "EXP"); // TODO:闇�璁句负鍏蜂綋鐨勫垎甯�
- argsTag = repairTag.addElement("Args");
- value = new Double(paramData.getRepairMttcr());
- value = 1.0/value;
- argsTag.addAttribute("value", value.toString());
- Element repairTimeLimitTag = element.addElement("RepairTimeLimit");
- repairTimeLimitTag.setText(paramData.getRepairMttcr());
- }
- } else if ("10".equals(xhProductModel.getProductType())) {
- // 铏氬崟浣�
- ModelRbd rbdXDY = modelRbdDao.getDiagramOfXDY(dataId);
- if (rbdXDY == null) return;
- List<Algorithm> algorithmListXDY = algorithmDao.getListByModelId(rbdXDY.getId());
- List<ModelNode> modelNodeAndVnodeListXDY =modelNodeAlgorithmDao.getListByModelId(rbdXDY.getId());
- Algorithm endAlgo = algorithmListXDY.stream().filter(item ->
- "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0);
- ModelNode computerNode = modelNodeAndVnodeListXDY.stream().filter(item ->
- endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
- node2DOM(algorithmListXDY, modelNodeAndVnodeListXDY, computerNode, parent);
- }
- } else {
- // vnode锛堣繍绠楄妭鐐癸級
- Algorithm algo = algorithmList.stream().filter(item ->
- node.getId().equals(item.getId())).collect(Collectors.toList()).get(0);
- Element element = parent.addElement("Logic");
- element.addAttribute("Name", algo.getId().toString());
- if ("series".equals(algo.getAlgorithmType())) {
- element.addAttribute("Type", "SERIES");
- } else if ("parallel".equals(algo.getAlgorithmType())) {
- element.addAttribute("Type", "PARALLEL");
- } else if ("vote".equals(algo.getAlgorithmType())) {
- element.addAttribute("Type", "VOTE");
- element.addAttribute("VoteValue", algo.getVoteNum().toString());
- } else if ("switch".equals(algo.getAlgorithmType())) {
- element.addAttribute("Type", "STANDBY");
- } else if ("bridge".equals(algo.getAlgorithmType())) {
- element.addAttribute("Type", "BRIDGE");
- }
- String[] computerNodeListStr = algo.getComputerList().split(",");
- for (String nodeStr : computerNodeListStr) {
- ModelNode nd = modelNodeAndVnodeList.stream().filter(item ->
- nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
- node2DOM(algorithmList, modelNodeAndVnodeList, nd, element);
- }
- }
}
private boolean getAlgorithmFromRbd(ModelRbd modelRbd,
@@ -340,7 +877,8 @@
do {
hasSimplified = false;
hasSimplified = simplifySeries(modelRbd.getId(), modelNodeList, modelLineList, algorithmList, modelNodeAndVnodeList, hasSimplified);
- hasSimplified = simplifyParallel(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);
@@ -357,19 +895,19 @@
List<ModelNode> modelNodeAndVnodeList) {
ModelNode endNode = modelNodeList.stream().filter(item ->
"end".equals(item.getNodeType())).collect(Collectors.toList()).get(0);
- if (endNode.getInLineNum()!=1) return false;
+ 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;
+ 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;
+ if (!"start".equals(startNode.getNodeType()) || startNode.getOutLineNum() != 1) return false;
// 鍒犻櫎鑺傜偣鍙婅繛绾�
modelLineList.remove(lineToEnd);
@@ -389,7 +927,7 @@
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);
+ algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1);
algorithmList.add(algorithm);
// 鏂板缁撴潫鐨勮櫄鑺傜偣
@@ -398,7 +936,7 @@
vnode.setPicId(id.toString());
vnode.setModelId(modelId);
vnode.setNodeType("vnode");
- vnode.setName("v"+algorithm.getStep());
+ vnode.setName("v" + algorithm.getStep());
modelNodeAndVnodeList.add(vnode);
return true;
@@ -412,27 +950,27 @@
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;
+ if (startNodes.size() == 0) return hasSimplified;
for (ModelNode startNode : startNodes) {
- if (startNode.getInLineNum()!=1) continue;
+ 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;
+ if (result.size() < 2) continue;
- ModelNode endNode = result.get(result.size()-1);
- if ("start,switch,vote".contains(endNode.getNodeType()) || endNode.getOutLineNum()!=1) {
+ 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 (realSeriesNodes.size() < 1) {
if (result.size() < 2) continue;
// 鏇挎崲鎴愯繛绾�
replaceToLineSeries(modelNodeList, modelLineList, result);
- } else if (realSeriesNodes.size()==1) {
+ } else if (realSeriesNodes.size() == 1) {
if (result.size() < 2) continue; // path涓婂彧鏈夎浜у搧鑺傜偣锛坣ode/vnode锛夎嚜宸憋紝鏃犻渶鍋氫粈涔�
// 灏唒ath鏇挎崲鎴愯鑺傜偣
replaceToTheNodeSeries(modelNodeList, modelLineList,
@@ -453,12 +991,12 @@
List<ModelNode> path) {
// 鑾峰彇path鐨勮捣鐐圭殑鍑哄彛绾�
ModelNode finalNodeStart = path.get(0);
- ModelNode finalNodeEnd = path.get(path.size()-1);
+ 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++) {
+ for (int i = 0; i < path.size(); i++) {
ModelNode finalNode = path.get(i);
if (i < path.size() - 1) {
// 灏嗗叆鍙g嚎鍒犻櫎
@@ -481,20 +1019,20 @@
}
private void replaceToTheNodeSeries(List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<ModelNode> path,
- ModelNode theNode) {
+ 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);
+ 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++) {
+ for (int i = 0; i < path.size(); i++) {
ModelNode finalNode = path.get(i);
if (i < path.size() - 1) {
// 灏嗗叆鍙g嚎鍒犻櫎
@@ -540,7 +1078,7 @@
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);
+ algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1);
algorithmList.add(algorithm);
// 鏂板铏氳妭鐐�
@@ -549,16 +1087,16 @@
vnode.setPicId(id.toString());
vnode.setModelId(modelId);
vnode.setNodeType("vnode");
- vnode.setName("v"+algorithm.getStep());
+ 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++) {
+ for (int i = 0; i < path.size(); i++) {
ModelNode finalNode = path.get(i);
- if (i==0) {
+ if (i == 0) {
// 灏嗚鑺傜偣鐨勫嚭鍙g嚎鏀逛负杩炴帴鍒拌櫄鑺傜偣
List<ModelLine> outLines = modelLineList.stream().filter(item ->
item.getBeginCell().equals(finalNode.getPicId())).collect(Collectors.toList());
@@ -570,7 +1108,7 @@
item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList());
modelLineList.removeAll(inLines);
}
- if (i==path.size()-1) {
+ if (i == path.size() - 1) {
// 灏嗚鑺傜偣鐨勫叆鍙g嚎鏀逛负杩炴帴鍒拌櫄鑺傜偣
List<ModelLine> inLines = modelLineList.stream().filter(item ->
item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList());
@@ -687,12 +1225,37 @@
List<ModelNode> result) {
ModelLine inLine = modelLineList.stream().filter(item ->
item.getEndCell().equals(startNode.getPicId())).collect(Collectors.toList()).get(0);
- ModelNode pathNode = modelNodeList.stream().filter(item ->
- inLine.getBeginCell().equals(item.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 ("switch,vote".contains(pathNode.getNodeType())) return;
+ 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,
@@ -704,10 +1267,10 @@
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;
+ if (startNodes.size() == 0) return hasSimplified;
for (ModelNode startNode : startNodes) {
- if (startNode.getInLineNum()<2) continue;
+ 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,
@@ -721,12 +1284,12 @@
}
private boolean simplifyParallelGroup(Long modelId,
- List<ModelNode> modelNodeList,
- List<ModelLine> modelLineList,
- List<Algorithm> algorithmList,
- List<ModelNode> modelNodeAndVnodeList,
- ModelNode startNode,
- List<ModelLine> lines) {
+ 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) {
@@ -736,10 +1299,10 @@
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) {
+ if (pathOneGroup.size() > 1) {
List<ModelNode> branchNodeList = new ArrayList<>();
ModelNode endNode = getBranchNodesOneParallel(pathOneGroup, branchNodeList);
- if ("connect".equals(startNode.getNodeType()) && pathOneGroup.size()==lines.size()) {
+ if ("connect".equals(startNode.getNodeType()) && pathOneGroup.size() == lines.size()) {
// 鏇挎崲鎴愯櫄鑺傜偣
modelNodeAndVnodeList.add(startNode);
replaceToVnode("parallel", modelId, modelNodeList, modelLineList,
@@ -788,7 +1351,7 @@
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;
+ 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);
@@ -801,7 +1364,7 @@
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);
+ ModelNode endNode = path.get(path.size() - 1);
if (endNodePathsMap.containsKey(endNode)) {
endNodePathsMap.get(endNode).add(path);
} else {
@@ -814,11 +1377,11 @@
}
private ModelNode getBranchNodesOneParallel(List<List<ModelNode>> paths,
- List<ModelNode> branchNodeList) {
+ List<ModelNode> branchNodeList) {
ModelNode endNode = null;
for (List<ModelNode> path : paths) {
branchNodeList.add(path.get(0));
- endNode = path.get(path.size()-1);
+ endNode = path.get(path.size() - 1);
}
return endNode;
}
@@ -831,15 +1394,15 @@
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;
+ "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<ModelLinePair> linePairs = getLinePairs(lines);
- for (ModelLinePair linePair : linePairs) {
+ 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) {
@@ -858,12 +1421,15 @@
List<Algorithm> algorithmList,
List<ModelNode> modelNodeAndVnodeList,
ModelNode startNode,
- ModelLinePair linePair) {
+ 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 ->
@@ -928,6 +1494,79 @@
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);
@@ -935,6 +1574,11 @@
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);
@@ -967,6 +1611,7 @@
algorithmList, modelNodeAndVnodeList, vnode, endNode, branchNodeList);
calcInOutLineNum(startNode, modelLineList);
}
+*/
return true;
}
@@ -987,11 +1632,11 @@
}
// 鎵惧嚭鎵�鏈�2鏍圭嚎鐨勭粍鍚�
- private List<ModelLinePair> getLinePairs(List<ModelLine> lines) {
- List<ModelLinePair> linePairs = new ArrayList<>();
- for (int i=0; i<lines.size()-1; i++) {
- for (int j=i+1; j<lines.size(); j++) {
- ModelLinePair linePair = new ModelLinePair();
+ 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);
@@ -1009,7 +1654,7 @@
boolean hasSimplified) {
List<ModelNode> opNodes = modelNodeList.stream().filter(item ->
operator.equals(item.getNodeType())).collect(Collectors.toList());
- if (opNodes.size()==0) return hasSimplified;
+ if (opNodes.size() == 0) return hasSimplified;
for (ModelNode opNode : opNodes) {
List<ModelLine> lines = modelLineList.stream().filter(item ->
@@ -1064,7 +1709,7 @@
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);
+ algorithm.setStep(algorithmList.size() == 0 ? 0 : algorithmList.get(algorithmList.size() - 1).getStep() + 1);
algorithmList.add(algorithm);
// 鏇挎崲涓鸿櫄鑺傜偣
@@ -1078,7 +1723,7 @@
}
startNode.setId(id);
startNode.setNodeType("vnode");
- startNode.setName("v"+algorithm.getStep());
+ startNode.setName("v" + algorithm.getStep());
ModelLine modelLineNew = new ModelLine();
Long picId2 = UUIDUtil.generateId();
@@ -1097,14 +1742,14 @@
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;
+ 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);
@@ -1118,6 +1763,7 @@
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();
@@ -1129,7 +1775,7 @@
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)){
+ } else if ("image".equals(shape)) {
ModelNode modelNode = new ModelNode();
modelNode.setId(UUIDUtil.generateId());
modelNode.setModelId(modelId);
@@ -1137,39 +1783,72 @@
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()));
- Object voteNum = JsonUtils2.getJsonValueByPath(jsonObject, "data/voteNum".split("/"));
- if (voteNum!=null && StringUtils.isNotBlank(voteNum.toString())) {
- modelNode.setVoteNum(Integer.valueOf(voteNum.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());
}
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());
- Object name = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/"));
- modelNode.setName(name==null ? "" : name.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)) {
- Object obj = JsonUtils2.getJsonValueByPath(jsonObject, "data/reliabDistribType".split("/"));
- if (obj != null && StringUtils.isNotBlank(obj.toString())) {
- productImg.setReliabDistribType(Integer.valueOf(obj.toString()));
+ 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()));
+ }
+ }
}
- productImg.setTaskMtbcf(JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcf".split("/")).toString());
- productImg.setTaskMtbcfOther(JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcfOther".split("/")).toString());
- obj = JsonUtils2.getJsonValueByPath(jsonObject, "data/isRepair".split("/"));
- if (obj != null && StringUtils.isNotBlank(obj.toString())) {
- productImg.setIsRepair(Integer.valueOf(obj.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()) {
- obj = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairDistribType".split("/"));
- if (obj != null && StringUtils.isNotBlank(obj.toString())) {
- productImg.setRepairDistribType(Integer.valueOf(obj.toString()));
+ jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/repairDistribType".split("/"));
+ if (jsonValue != null && StringUtils.isNotBlank(jsonValue.toString())) {
+ productImg.setRepairDistribType(Integer.valueOf(jsonValue.toString()));
}
- productImg.setRepairMttcr(JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcr".split("/")).toString());
- productImg.setRepairMttcrOther(JsonUtils2.getJsonValueByPath(jsonObject, "data/repairMttcrOther".split("/")).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);
--
Gitblit v1.9.1