| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | /** |
| | | * 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"; |
| | | |
| | | // 节点 |
| | | /* 自动布局:start与end的大小 */ |
| | | 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; |
| | | /* 自动布局:connect的大小 */ |
| | | 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 |
| | |
| | | |
| | | @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(); |
| | | |
| | | // 删除既有数据 |
| | |
| | | |
| | | @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(); |
| | | |
| | | // 删除既有数据 |
| | |
| | | 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; |
| | | |
| | | // 解析结果存放list |
| | | List<ModelNode> modelNodeList = new ArrayList<>(); |
| | | List<ModelLine> modelLineList = new ArrayList<>(); |
| | | List<Algorithm> algorithmList = new ArrayList<>(); |
| | | List<ProductImg> productImgList = new ArrayList<>(); // 暂不使用(而使用数据库中的可靠性参数) |
| | | |
| | | // 1. 解析出节点与边 |
| | | getNodeAndLineFromRbd(modelRbd.getId(), rbdJsonArray, modelNodeList, modelLineList, productImgList); |
| | | // 2. 对于有多根入口线的产品节点,将其上的表决、旁联关系剥离成运算符节点,添加到该节点的前面,并添加相应的边 |
| | | peelOperationFromProductNode(modelRbd.getId(), modelNodeList, modelLineList); |
| | | // 3. 计算所有节点的入口线数及出口线数 |
| | | calcInOutLineNumAllNode(modelNodeList, modelLineList); |
| | | // 4. 复制产品节点(node)到list |
| | | 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的布局空间参数(x、y坐标) |
| | | root.setBlockX(0); |
| | | root.setBlockY(0); |
| | | calcPosition(rbdJsonArray, root); |
| | | 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 setNodePositionXY(JSONArray rbdJsonArray, RbdTreeNode block) { |
| | | Double x = block.getBlockX() + (block.getBlockWidth() - block.getMyWidth()) / 2; |
| | | Double y = block.getBlockY() + (block.getBlockHeight() - block.getMyHeight()) / 2; |
| | | setRbdNodePosition(rbdJsonArray, block.getPicId(), x, y); |
| | | } |
| | | |
| | | private void calcPosition(JSONArray rbdJsonArray, RbdTreeNode block) { |
| | | if (block.getNodeType().equals("node")) { |
| | | setNodePositionXY(rbdJsonArray, block); |
| | | } 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); |
| | | 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.setPicId(block.getPairStartNodeId()); |
| | | connectBlock.setBlockX(block.getBlockX()); |
| | | connectBlock.setBlockY(firstSubBlockY); |
| | | connectBlock.setBlockWidth(LAYOUT_CELL_SIZE_X); |
| | | connectBlock.setBlockHeight(blockHeight); |
| | | setNodePositionXY(rbdJsonArray, connectBlock); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | // 设置运算符的位置 |
| | | RbdTreeNode opeBlock = new RbdTreeNode(); |
| | | |
| | | opeBlock.setPicId(block.getPicId()); |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | 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,y),自顶向下递归计算各个节点的位置(x,y) |
| | | * |
| | | * @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); |
| | | // 将topNode的坐标定为Cell(0,0),反算所有节点的坐标 |
| | | // 1. 计算节点的Cell位置 |
| | | calcNodeLayoutPositionCell(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo, 0, 0, |
| | | topNode.getVnodeCellNumX(), topNode.getVnodeCellNumY()); |
| | | // 2. 计算节点的x,y坐标位置 |
| | | 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()); |
| | | } |
| | | */ |
| | | |
| | | /* |
| | | // 递归函数(计算各节点的x,y坐标位置) |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 递归函数(计算各节点的Cell位置,以左上角为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); |
| | | *//* |
| | | |
| | | // 需节点代表整个逻辑单元,因此其坐标为originCellX和originCellX |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 自底向上递归合计出整个RBD的大小(横向及纵向所占单元格的数量) |
| | | * |
| | | * @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; |
| | |
| | | |
| | | // 6. 转换为算法库接口XML |
| | | if (result) { |
| | | // result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | // result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList); |
| | | } |
| | | |
| | | // 7. 保存模型 |
| | |
| | | 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()); |
| | |
| | | lineNew.setEndCell(node.getPicId()); |
| | | linesToAdd.add(lineNew); |
| | | |
| | | for(ModelLine line: inLineList){ |
| | | for (ModelLine line : inLineList) { |
| | | line.setEndCell(nodeNewId.toString()); |
| | | } |
| | | } |
| | |
| | | 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); |
| | |
| | | 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); |
| | | |
| | | // 新增结束的虚节点 |
| | |
| | | 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; |
| | |
| | | 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,parallel,switch,vote,bridge".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上只有该产品节点(node/vnode)自己,无需做什么 |
| | | // 将path替换成该节点 |
| | | replaceToTheNodeSeries(modelNodeList, modelLineList, |
| | |
| | | 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) { |
| | | // 将入口线删除 |
| | |
| | | } |
| | | |
| | | 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的结束点的入口线 |
| | | 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) { |
| | | // 将入口线删除 |
| | |
| | | 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); |
| | | |
| | | // 新增虚节点 |
| | |
| | | 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); |
| | | |
| | | // 将path替换为该虚节点 |
| | | 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) { |
| | | // 将该节点的出口线改为连接到虚节点 |
| | | List<ModelLine> outLines = modelLineList.stream().filter(item -> |
| | | item.getBeginCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | | modelLineList.removeAll(inLines); |
| | | } |
| | | if (i==path.size()-1) { |
| | | if (i == path.size() - 1) { |
| | | // 将该节点的入口线改为连接到虚节点 |
| | | List<ModelLine> inLines = modelLineList.stream().filter(item -> |
| | | item.getEndCell().equals(finalNode.getPicId())).collect(Collectors.toList()); |
| | |
| | | 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 |
| | | 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 (pathNode.getOutLineNum() != 1 || pathNode.getInLineNum() != 1) return; |
| | | if ("parallel,switch,vote,bridge".contains(pathNode.getNodeType())) return; |
| | | seekPathSeries(modelNodeList, modelLineList, pathNode, result); |
| | | } |
| | |
| | | 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, |
| | |
| | | } |
| | | |
| | | 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) { |
| | |
| | | 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, |
| | |
| | | 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); |
| | |
| | | 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 { |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | |
| | | boolean hasSimplifiedMe = false; |
| | | List<ModelNode> startNodes = modelNodeList.stream().filter(item -> |
| | | "bridge".equals(item.getNodeType())).collect(Collectors.toList()); |
| | | if (startNodes.size()==0) return hasSimplified; |
| | | 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) { |
| | |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | ModelNode startNode, |
| | | ModelLinePair linePair) { |
| | | ModelLinePairDto linePair) { |
| | | ModelNode node1 = null; |
| | | ModelNode node2 = null; |
| | | ModelNode node3 = null; |
| | |
| | | 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; |
| | | 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); |
| | |
| | | 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; |
| | | 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; |
| | | 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; |
| | | 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); |
| | |
| | | } |
| | | |
| | | // 找出所有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); |
| | |
| | | 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 -> |
| | |
| | | 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); |
| | | |
| | | // 替换为虚节点 |
| | |
| | | } |
| | | startNode.setId(id); |
| | | startNode.setNodeType("vnode"); |
| | | startNode.setName("v"+algorithm.getStep()); |
| | | startNode.setName("v" + algorithm.getStep()); |
| | | |
| | | ModelLine modelLineNew = new ModelLine(); |
| | | Long picId2 = UUIDUtil.generateId(); |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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())) { |
| | | 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(); |
| | |
| | | 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()); |
| | | modelNode.setName(jsonValue == null ? "" : jsonValue.toString()); |
| | | |
| | | productImg.setDataId(dataId); |
| | | String productType = JsonUtils2.getJsonValueByPath(jsonObject, "data/productType".split("/")).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())); |
| | | } |
| | | } |
| | | } |
| | | jsonValue = JsonUtils2.getJsonValueByPath(jsonObject, "data/taskMtbcf".split("/")); |
| | | if (null != jsonValue) productImg.setTaskMtbcf(jsonValue.toString()); |