xyc
2024-09-10 ef6d6e4abc03b3a34818d1283e27ae9827b57efe
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ModelLineService.java
@@ -11,20 +11,17 @@
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;
@@ -37,6 +34,42 @@
 */
@Service
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
@@ -102,6 +135,448 @@
        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);
        // 7. 递归计算RBD的布局空间参数(x、y坐标)
        calcLayoutPosition(modelRbd, algorithmList, modelNodeAndVnodeList);
        // 8. 保存自动布局模型
        // 更新RBD数据
//        modelRbd.setAutoLayoutContent("测试文字");
        modelRbdDao.updateById(modelRbd);
        return result;
    }
    /**
     * 根据顶层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);
        // 将toNode的中心坐标定为(0,0),反算所有节点的坐标
        // 1. 计算并设置start的位置
        double x = -topNode.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2 - LAYOUT_START_END_SIZE_X;
        double y = -LAYOUT_START_END_SIZE_Y/2;
        setRbdNodePosition(rbdJsonArray, "10000", x, y);
        // 2. 计算并设置节点的位置
        calcNodeLayoutPosition(rbdJsonArray, algorithmList, modelNodeAndVnodeList, topNode, topAlgo, 0, 0);
        // 3. 计算并设置end的位置
        x = topNode.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2;
        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())) {
            //设置node(设备节点)布局信息
            node.setPositionX(x - node.getCellNumX()*LAYOUT_CELL_SIZE_X/2);
            node.setPositionY(y - node.getCellNumY()*LAYOUT_CELL_SIZE_Y/2);
            setRbdNodePosition(rbdJsonArray, node.getPicId().toString(), node.getPositionX(), node.getPositionY());
        } else if ("vnode".equals(node.getNodeType())) {
            String[] computerNodeListStr = algo.getComputerList().split(",");
            switch (algo.getAlgorithmType()) {
                case OPE_TYPE_SERIES:
                    int sumCellNumX = 0;
                    for (String nodeStr : computerNodeListStr) {
                        ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
                                nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                        sumCellNumX += childNode.getVnodeCellNumX();
                    }
                    for (int i=0; i<computerNodeListStr.length; i++) {
                        int idx = i;
                        ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
                                computerNodeListStr[idx].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                        if (0==i) {
                            double childNodeX = x - sumCellNumX * LAYOUT_CELL_SIZE_X / 2;
                            double childNodeY = y - childNode.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y / 2;
                            if ("node".equals(childNode.getNodeType())) {
                                childNode.setPositionX(childNodeX);
                                childNode.setPositionY(childNodeY);
                                setRbdNodePosition(rbdJsonArray, childNode.getPicId().toString(), childNode.getPositionX(), childNode.getPositionY());
                            } else {
                                Algorithm childAlgo = algorithmList.stream().filter(item ->
                                        childNode.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                                calcNodeLayoutPosition(rbdJsonArray,
                                        algorithmList,
                                        modelNodeAndVnodeList,
                                        childNode,
                                        childAlgo,
                                        childNodeX,
                                        childNodeY);
                            }
                        } else {
                            int idxPre = i - 1;
                            ModelNode childNodePre = modelNodeAndVnodeList.stream().filter(item ->
                                    computerNodeListStr[idxPre].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                            int idxMe = i;
                            double childNodeX = childNodePre.getPositionX() + childNodePre.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X;
                            double childNodeY = y - childNode.getVnodeCellNumY()*LAYOUT_CELL_SIZE_Y/2;
                            if ("node".equals(childNode.getNodeType())) {
                                childNode.setPositionX(childNodeX);
                                childNode.setPositionY(childNodeY);
                                setRbdNodePosition(rbdJsonArray, childNode.getPicId().toString(), childNode.getPositionX(), childNode.getPositionY());
                            } else {
                                ModelNode childNodeMe = modelNodeAndVnodeList.stream().filter(item ->
                                        computerNodeListStr[idxMe].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                                Algorithm childAlgoMe = algorithmList.stream().filter(item ->
                                        childNodeMe.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                                calcNodeLayoutPosition(rbdJsonArray,
                                        algorithmList,
                                        modelNodeAndVnodeList,
                                        childNode,
                                        childAlgoMe,
                                        childNodePre.getPositionX() + childNodePre.getVnodeCellNumX() * LAYOUT_CELL_SIZE_X,
                                        y - childNodeMe.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y / 2);
                            }
                        }
                    }
                    break;
                case OPE_TYPE_PARALLEL:
                case OPE_TYPE_SWITCH:
                case OPE_TYPE_VOTE:
                    int sumCellNumY = 0;
                    for (String nodeStr : computerNodeListStr) {
                        ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
                                nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                        sumCellNumY += childNode.getVnodeCellNumY();
                    }
                    for (int i=0; i<computerNodeListStr.length; i++) {
                        int idx = i;
                        ModelNode childNode = modelNodeAndVnodeList.stream().filter(item ->
                                computerNodeListStr[idx].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                        if (0==i) {
                            double childNodeX = x - childNode.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2;
                            double childNodeY = y - sumCellNumY*LAYOUT_CELL_SIZE_Y/2;
                            if ("node".equals(childNode.getNodeType())) {
                                childNode.setPositionX(childNodeX);
                                childNode.setPositionY(childNodeY);
                                setRbdNodePosition(rbdJsonArray, childNode.getPicId(), childNode.getPositionX(), childNode.getPositionY());
                            } else {
                                Algorithm childAlgo = algorithmList.stream().filter(item ->
                                        childNode.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                                calcNodeLayoutPosition(rbdJsonArray,
                                        algorithmList,
                                        modelNodeAndVnodeList,
                                        childNode,
                                        childAlgo,
                                        childNodeX,
                                        childNodeY);
                            }
                        } else {
                            int idxPre = i - 1;
                            ModelNode childNodePre = modelNodeAndVnodeList.stream().filter(item ->
                                    computerNodeListStr[idxPre].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                            int idxMe = i;
                            ModelNode childNodeMe = modelNodeAndVnodeList.stream().filter(item ->
                                    computerNodeListStr[idxMe].equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                            double childNodeX = x - childNodeMe.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y / 2;
                            double childNodeY = childNodePre.getPositionY() + childNodePre.getVnodeCellNumY() * LAYOUT_CELL_SIZE_Y;
                            if ("node".equals(childNodeMe.getNodeType())) {
                                childNodeMe.setPositionX(childNodeX);
                                childNodeMe.setPositionY(childNodeY);
                                setRbdNodePosition(rbdJsonArray, childNodeMe.getPicId(), childNodeMe.getPositionX(), childNodeMe.getPositionY());
                            } else {
                                Algorithm childAlgoMe = algorithmList.stream().filter(item ->
                                        childNodeMe.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                                calcNodeLayoutPosition(rbdJsonArray,
                                        algorithmList,
                                        modelNodeAndVnodeList,
                                        childNodeMe,
                                        childAlgoMe,
                                        childNodeX,
                                        childNodeY);
                            }
                        }
                    }
                    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 计算第一行两个节点的坐标
                    calcNodeLayoutPosition(rbdJsonArray,
                            algorithmList,
                            modelNodeAndVnodeList,
                            node1,
                            algo1,
                            x - (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2,
                            y - (totalCellNumY-firstRowCellNumY+node1.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2);
                    calcNodeLayoutPosition(rbdJsonArray,
                            algorithmList,
                            modelNodeAndVnodeList,
                            node2,
                            algo2,
                            x + (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2,
                            y - (totalCellNumY-firstRowCellNumY+node2.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2);
                    // 2.2 计算第二行桥联节点的坐标
                    calcNodeLayoutPosition(rbdJsonArray,
                            algorithmList,
                            modelNodeAndVnodeList,
                            node2,
                            algo2,
                            x - node3.getVnodeCellNumX()*LAYOUT_CELL_SIZE_X/2,
                            y - (totalCellNumY/2-firstRowCellNumY)*LAYOUT_CELL_SIZE_Y);
                    // 2.3 计算第三行两个节点的坐标
                    calcNodeLayoutPosition(rbdJsonArray,
                            algorithmList,
                            modelNodeAndVnodeList,
                            node1,
                            algo1,
                            x - (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2,
                            y - (totalCellNumY-firstRowCellNumY+node1.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2);
                    calcNodeLayoutPosition(rbdJsonArray,
                            algorithmList,
                            modelNodeAndVnodeList,
                            node2,
                            algo2,
                            x + (node1.getVnodeCellNumX() + node2.getVnodeCellNumX())*LAYOUT_CELL_SIZE_X/2,
                            y - (totalCellNumY-firstRowCellNumY+node2.getVnodeCellNumY())*LAYOUT_CELL_SIZE_Y/2);
                    // 2.4 计算桥联运算符的坐标
                    // 2.5 计算左侧配对的connect的坐标
                    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);
            }
        }
    }
    /**
     * 自底向上递归合计出整个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);
                if ("node".equals(childNode.getNodeType())) {
                    childNode.setWidth(LAYOUT_DEVICE_NODE_SIZE_X);
                    childNode.setHeight(LAYOUT_DEVICE_NODE_SIZE_Y);
                    childNode.setCellNumX(LAYOUT_CELL_NUM_NODE_X);
                    childNode.setCellNumY(LAYOUT_CELL_NUM_NODE_Y);
                    childNode.setVnodeCellNumX(node.getCellNumX());
                    childNode.setVnodeCellNumY(node.getCellNumY());
                } else {
                    Algorithm childAlgo = algorithmList.stream().filter(item ->
                            childNode.getId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
                    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.getCellNumX();
                    numY = childNode.getCellNumY() > numY ? childNode.getCellNumY() : numY;
                    break;
                case OPE_TYPE_PARALLEL:
                case OPE_TYPE_SWITCH:
                case OPE_TYPE_VOTE:
                    numX = childNode.getCellNumX() > numX ? childNode.getCellNumX() : numX;
                    numY += childNode.getCellNumY();
                    break;
                default:
                    break;
            }
        }
        if (OPE_TYPE_PARALLEL.equals(algo.getAlgorithmType())
            || OPE_TYPE_SWITCH.equals(algo.getAlgorithmType())
            || OPE_TYPE_VOTE.equals(algo.getAlgorithmType())) {
            // 设置connect的大小
            ModelNode connect = modelNodeAndVnodeList.stream().filter(item ->
                    vnode.getPairStartNodeId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
            connect.setWidth(LAYOUT_CONNECT_SIZE_X);
            connect.setHeight(LAYOUT_CONNECT_SIZE_Y);
            connect.setCellNumX(LAYOUT_CELL_NUM_CONNECT_X);
            connect.setCellNumY(LAYOUT_CELL_NUM_CONNECT_Y);
            numX += connect.getCellNumX();
            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的大小
            ModelNode connect = modelNodeAndVnodeList.stream().filter(item ->
                    vnode.getPairStartNodeId().equals(item.getId().toString())).collect(Collectors.toList()).get(0);
            connect.setWidth(LAYOUT_CONNECT_SIZE_X);
            connect.setHeight(LAYOUT_CONNECT_SIZE_Y);
            connect.setCellNumX(LAYOUT_CELL_NUM_CONNECT_X);
            connect.setCellNumY(LAYOUT_CELL_NUM_CONNECT_Y);
            numX += connect.getCellNumX();
            numX += vnode.getCellNumX();
        }
        vnode.setVnodeCellNumX(numX);
        vnode.setVnodeCellNumY(numY);
    }
    @Transactional(rollbackFor = Exception.class)
    public boolean analyze(ModelRbd modelRbd) {
        boolean result = true;
@@ -138,7 +613,7 @@
        // 6. 转换为算法库接口XML
        if (result) {
            result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList);
//           result = createIfXmlFromRbd(modelRbd, algorithmList, modelNodeAndVnodeList);
        }
        // 7. 保存模型
@@ -189,134 +664,6 @@
        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节点到root1
            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节点到root
            Element start = root.addElement("Node");
            start.addAttribute("Name", "Start");
            start.addAttribute("Type", "NODE");
            // 添加link(路径)到root
            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();
            // 输出格式化xml
            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,
                                        List<ModelNode> modelNodeList,
                                        List<ModelLine> modelLineList,
@@ -340,7 +687,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);
@@ -423,7 +771,7 @@
            if (result.size()<2) continue;
            ModelNode endNode = result.get(result.size()-1);
            if ("start,switch,vote".contains(endNode.getNodeType()) || endNode.getOutLineNum()!=1) {
            if ("start,parallel,switch,vote,bridge".contains(endNode.getNodeType()) || endNode.getOutLineNum()!=1) {
                result.remove(endNode);
            }
            List<ModelNode> realSeriesNodes = result.stream().filter(item ->
@@ -687,12 +1035,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 ("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,
@@ -831,15 +1204,15 @@
                                   boolean hasSimplified) {
        boolean hasSimplifiedMe = false;
        List<ModelNode> startNodes = modelNodeList.stream().filter(item ->
                "node,vnode,connect,end".contains(item.getNodeType())).collect(Collectors.toList());
                "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) {
            List<ModelLinePairDto> linePairs = getLinePairs(lines);
            for (ModelLinePairDto linePair : linePairs) {
                hasSimplifiedMe = simplifyBridgeOneLinePair(modelId, modelNodeList, modelLineList,
                        algorithmList, modelNodeAndVnodeList, startNode, linePair);
                if (hasSimplifiedMe) {
@@ -858,12 +1231,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 +1304,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 +1384,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 +1421,7 @@
                    algorithmList, modelNodeAndVnodeList, vnode, endNode, branchNodeList);
            calcInOutLineNum(startNode, modelLineList);
        }
*/
        return true;
    }
@@ -987,11 +1442,11 @@
    }
    // 找出所有2根线的组合
    private List<ModelLinePair> getLinePairs(List<ModelLine> lines) {
        List<ModelLinePair> linePairs = new ArrayList<>();
    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++) {
                ModelLinePair linePair = new ModelLinePair();
                ModelLinePairDto linePair = new ModelLinePairDto();
                linePair.setLine1(lines.get(i));
                linePair.setLine2(lines.get(j));
                linePairs.add(linePair);
@@ -1118,6 +1573,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();
@@ -1137,39 +1593,70 @@
                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()));
                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);