modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java
@@ -107,6 +107,7 @@
    String templetStr = "{\"cells\":[]}";
    Map<String, JSONObject> templetsMap = new HashMap<>();
    Map<String, String> templetsStrMap = new HashMap<>();
    Map<Integer, String> templetsStrMap2 = new HashMap<>();
    private JSONObject xmlJSONObj;
@@ -150,7 +151,10 @@
        return baseDao.getChildren(productId, taskId);
    }
    public String getTimeDiagram(Long productId, Long taskId, Long fzId) {
    public TimeDiagramDto getTimeDiagram(Long productId, Long taskId, Long fzId, double smallWidth, double minPointNum) {
        TimeDiagramDto timeDiagramDto = new TimeDiagramDto();
        timeDiagramDto.setSmallWidth(smallWidth);
        timeDiagramDto.setMinPointNum(minPointNum);
        String filePath = path + "/" + fzId + "/" + "status.json";
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr = null;
@@ -178,7 +182,10 @@
        JSONObject jsonObject = new JSONObject(templetStr);
        JSONArray jsonArray = jsonObject.getJSONArray("cells");
        this.getPetsInfo();
        JSONObject jsonObject3 = new JSONObject(templetStr);
        JSONArray jsonArray3 = jsonObject3.getJSONArray("cells");
        String modelStr2 = this.getPetsInfo();
        double x1 = 0;
        double x2 = 0;
        int y = -10;
@@ -189,26 +196,39 @@
        double pointNumPerHour = 60.0 / simulatAssess.getSamplPeriod();
        //时序图线
        List<List<TimeDiagramStatusDto>> lineArray = new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            List<TimeDiagramStatusDto> statusDtoList = new ArrayList<>();
            x1 = 0;
            groupY = groupHeight * i;
            ProductStatusDto dto = list.get(i);
            double startTime = 0.0;
            int status2 = 5;
            for (StatusDto status : dto.getStatusList()) {
                switch (status.getStatus()) {
                    case "O":
                        y = groupY;
                        status2 = 5;
                        break;
                    case "F":
                        y = groupY;// + spaceHeight;
                        status2 = 1;
                        break;
                    case "I":
                        y = groupY;// + spaceHeight;
                        status2 = 3;
                        break;
                    case "S":
                        y = groupY;// + spaceHeight;
                        status2 = 2;
                        break;
                    case "M":
                        y = groupY;// + 2 * spaceHeight;
                        status2 = 4;
                        break;
                }
                x2 = x1 + status.getTimes() * pointNumPerHour + 5;
                statusDtoList.add(new TimeDiagramStatusDto(x1, x2, status2));
                JSONObject lineJson = new JSONObject(templetsStrMap.get(status.getStatus()));
                setlineXy(lineJson, x1, y, x2, y, "");
                JsonUtils2.setJsonValueByPath(lineJson, "data/status".split("/"), status.getStatus());
@@ -219,34 +239,22 @@
                x1 = x2 - 5;
                jsonArray.add(lineJson);
            }
            lineArray.add(statusDtoList);
            JSONObject textJson = new JSONObject(templetsStrMap.get("text"));
            JsonUtils2.setJsonValueByPath(textJson, "id".split("/"), UUIDUtil.generateId().toString());
            JsonUtils2.setJsonValueByPath(textJson, "attrs/label/textWrap/text".split("/"), dto.getName());
            JsonUtils2.setJsonValueByPath(textJson, "position/x".split("/"), 20);
            JsonUtils2.setJsonValueByPath(textJson, "position/y".split("/"), y - 15);
            jsonArray.add(textJson);
        }
        //图例
        int spaceWitdth = 80;
        x1 = -spaceWitdth;
        x2 = -11;
        y = -110;
        String[] tlArr = "O,F,I,S,M".split(",");
        for (String s : tlArr) {
            JSONObject f = templetsMap.get(s);
            x1 = x1 + spaceWitdth;
            x2 = x2 + spaceWitdth;
            setlineXy(f, x1, y, x2, y, null);
            jsonArray.add(f);
            jsonArray3.add(textJson);
        }
        //阶段模型及刻度
        x1 = 0;
        x2 = 0;
        double y1 = -80;
        y = -60;
        double y2 = -50;
        double y1 = -60;
        y = -40;
        double y2 = -30;
        JSONObject modelJson = new JSONObject(templetsStrMap.get("model"));
        setlineXy(modelJson, 1, y1, 1, y2, null);
@@ -288,6 +296,7 @@
            jsonArray.add(textJson);
            x1 = x2;
        }
        JSONObject modelJson3 = new JSONObject(templetsStrMap.get("model"));
        setlineXy(modelJson3, 0, y, x2, y, null);
        jsonArray.add(modelJson3);
@@ -315,9 +324,122 @@
            curPointHour += periodHour;
        }
        timeDiagramDto.setTotalWidth(x2);
        double pointRate = timeDiagramDto.getTotalWidth() / timeDiagramDto.getSmallWidth();
        return jsonObject.toString();
        List<TimeDiagramStatusDto> subStatusDtoList = new ArrayList<>();
        int lastStatus = 5;
        boolean isFirst = true;
        x1 = 0;
        for (double i = 0; i < timeDiagramDto.getSmallWidth(); i = i + timeDiagramDto.getMinPointNum()) {
            int netStatus = 5;
            for (int j = 1; j < list.size(); j++) {
                if (i >= 448) {
                    System.out.println(111);
                }
                int tmpStatus = getPointStatus(lineArray.get(j), i * pointRate, (i + timeDiagramDto.getMinPointNum()) * pointRate - 1);
                if (tmpStatus < netStatus) {
                    netStatus = tmpStatus;
                }
            }
            if (!isFirst) {
                if (lastStatus != netStatus) {
                    subStatusDtoList.add(new TimeDiagramStatusDto(x1, x2, lastStatus));
                    lastStatus = netStatus;
                    x1 = i;
                }
            } else {
                lastStatus = netStatus;
                isFirst = false;
            }
            x2 = i + timeDiagramDto.getMinPointNum() - 1;
        }
        subStatusDtoList.add(new TimeDiagramStatusDto(x1, x2, lastStatus));
        List<TimeDiagramStatusDto> parentStatusDtoList = new ArrayList<>();
        lastStatus = 5;
        isFirst = true;
        x1 = 0;
        for (double i = 0; i < timeDiagramDto.getSmallWidth(); i = i + timeDiagramDto.getMinPointNum()) {
            if (i >= 448) {
                System.out.println(111);
            }
            int netStatus = getPointStatus(lineArray.get(0), i * pointRate, (i + timeDiagramDto.getMinPointNum()) * pointRate - 1);
            if (!isFirst) {
                if (lastStatus != netStatus) {
                    parentStatusDtoList.add(new TimeDiagramStatusDto(x1, x2, lastStatus));
                    lastStatus = netStatus;
                    x1 = i;
                }
            } else {
                lastStatus = netStatus;
                isFirst = false;
            }
            x2 = i + timeDiagramDto.getMinPointNum() - 1;
        }
        parentStatusDtoList.add(new TimeDiagramStatusDto(x1, x2, lastStatus));
        JSONObject jsonObject2 = new JSONObject(modelStr2);
        JSONArray jsonArray2 = jsonObject2.getJSONArray("cells");
        List<List<TimeDiagramStatusDto>> smallStatusDtoList = new ArrayList<>();
        smallStatusDtoList.add(parentStatusDtoList);
        smallStatusDtoList.add(subStatusDtoList);
        y = 10;
        for (int i = 0; i < smallStatusDtoList.size(); i++) {
            for (TimeDiagramStatusDto status : smallStatusDtoList.get(i)) {
                JSONObject lineJson = new JSONObject(templetsStrMap2.get(status.getStatus()));
                setlineXy(lineJson, status.getX1(), y, status.getX2() + 5, y, "");
                JsonUtils2.setJsonValueByPath(lineJson, "data/status".split("/"), status.getStatus());
                JsonUtils2.setJsonValueByPath(lineJson, "id".split("/"), UUIDUtil.generateId().toString());
                jsonArray2.add(lineJson);
            }
            y = y + 25;
        }
        //图例
        int spaceWitdth = 80;
        x1 = 0;
        x2 = spaceWitdth - 11;
        y = 60;
        String[] tlArr = "O,F,I,S,M".split(",");
        for (String s : tlArr) {
            JSONObject f = templetsMap.get(s);
            x1 = x1 + spaceWitdth;
            x2 = x2 + spaceWitdth;
            setlineXy(f, x1, y, x2, y, null);
            jsonArray2.add(f);
        }
        timeDiagramDto.setDiagramJson(jsonObject.toString());
        timeDiagramDto.setSmallDiagramJson(jsonObject2.toString());
        timeDiagramDto.setTextDiagramJson(jsonObject3.toString());
        return timeDiagramDto;
    }
    private int getPointStatus(List<TimeDiagramStatusDto> dtoList, double x1, double x2) {
        int status = 5;
        boolean findStart = false;
        for (int i = 0; i < dtoList.size(); i++) {
            if (x2 <= dtoList.get(i).getX1()) {
                break;
            }
            if (!findStart) {
                if (dtoList.get(i).getX1() >= x1 && x1 <= dtoList.get(i).getX2()) {
                    status = dtoList.get(i).getStatus();
                    findStart = true;
                }
            }
            if (dtoList.get(i).getX2() >= x2) {
                if (dtoList.get(i).getStatus() < status)
                    status = dtoList.get(i).getStatus();
            }
        }
        return status;
    }
    public void setlineXy(JSONObject lineJson, double x1, double y1, double x2, double y2, String text) {
        JsonUtils2.setJsonValueByPath(lineJson, "source/x".split("/"), x1);
@@ -330,12 +452,14 @@
        }
    }
    public void getPetsInfo() {
    public String getPetsInfo() {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("projectId", 10000);
        params.put("diagramId", 10000);
        String modelStr2 = "";
        List<TimeDiagram> list_style = baseDao.getTimeDiagram(params);
        if (list_style.size() > 0) {
            modelStr2 = list_style.get(0).getContent2();
            String modelStr = list_style.get(0).getContent();
            JSONObject modelJson = new JSONObject(modelStr);
            JSONArray modelJsonArray = modelJson.getJSONArray("cells");
@@ -349,22 +473,27 @@
                    if ("运行".equals(nodeMarker)) {
                        templetsMap.put("O", jsonObject);
                        templetsStrMap.put("O", jsonObject.toString());
                        templetsStrMap2.put(5, jsonObject.toString());
                    }
                    if ("故障".equals(nodeMarker)) {
                        templetsMap.put("F", jsonObject);
                        templetsStrMap.put("F", jsonObject.toString());
                        templetsStrMap2.put(1, jsonObject.toString());
                    }
                    if ("空闲".equals(nodeMarker)) {
                        templetsMap.put("I", jsonObject);
                        templetsStrMap.put("I", jsonObject.toString());
                        templetsStrMap2.put(3, jsonObject.toString());
                    }
                    if ("备份".equals(nodeMarker)) {
                        templetsMap.put("S", jsonObject);
                        templetsStrMap.put("S", jsonObject.toString());
                        templetsStrMap2.put(2, jsonObject.toString());
                    }
                    if ("未用".equals(nodeMarker)) {
                        templetsMap.put("M", jsonObject);
                        templetsStrMap.put("M", jsonObject.toString());
                        templetsStrMap2.put(4, jsonObject.toString());
                    }
                    if ("模型".equals(nodeMarker)) {
                        JsonUtils2.setJsonValueByPath(tmpJSONObject, "attrs/text/text".split("/"), "");
@@ -403,6 +532,7 @@
                }
            }
        }
        return modelStr2;
    }
    public List<ProductStatusDto> getStatusData(Long productId, Long taskId) {
@@ -482,7 +612,7 @@
        List<TaskModelCheckResultDto> chkResult = taskService.checkTaskModel(simulatAssess.getProductId(),
                simulatAssess.getTaskModelId());
        if (chkResult.size() > 0) {
            result = Result.error("模型不完整,请检查模型定义及参数配置。");
            result = Result.ok(chkResult);
            return result;
        }
@@ -500,7 +630,11 @@
        InputStream is = null;
        BufferedReader br = null;
        try {
            setParamToRedis(simulatAssess);
            try {
                setParamToRedis(simulatAssess);
            } catch (Exception e) {
                throw new RenException("访问Redis失败。请检查Redis是否已启动。");
            }
            Process process = null;
            String command = "python " + reliaSimMain;
@@ -512,7 +646,7 @@
            } else if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) {
                process = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", command});
            } else {
                throw new Exception("暂不支持该操作系统,进行启动算法库计算!");
                throw new RenException("暂不支持该操作系统,进行启动算法库计算!");
            }
            is = process.getInputStream();
            // 以命令行方式调用算法库时,接口约定返回的结果是utf-8编码
@@ -523,17 +657,17 @@
            if (line != null) {
                ReliaSimLibResult rtn = com.alibaba.fastjson.JSONObject.parseObject(line, ReliaSimLibResult.class);
                if ("0".equals(rtn.getCode())) {
                    logger.info("启动算法库成功。");
                    logger.info("启动可靠性仿真评估算法库成功。");
                    result = Result.ok();
                } else {
                    String errorMsg = rtn.getErrorMsg();
                    throw new RuntimeException("启动算法库失败: errorMsg=" + errorMsg);
                    throw new RenException("启动可靠性仿真评估算法库失败: errorMsg=" + errorMsg);
                }
            }
        } catch (Exception e) {
            logger.error("启动算法库仿真时发生Exception:", e);
        } catch (IOException e) {
            logger.error("启动可靠性仿真评估算法库仿真时发生Exception:", e);
            e.printStackTrace();
            result = Result.error(e.getMessage());
            throw new RenException("启动可靠性仿真评估算法库失败: errorMsg=" + e.getMessage());
        } finally {
            if (is != null) {
                try {
@@ -638,7 +772,7 @@
            insert(simulatAssess);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("组装算法库仿真计算用模型XML失败: " + e.getMessage());
            throw new RenException("组装算法库仿真计算用模型XML失败: " + e.getMessage());
        }
    }
@@ -935,6 +1069,7 @@
                element.addAttribute("k", algo.getVoteNum().toString());
            } else if ("switch".equals(algo.getAlgorithmType())) {
                element.addAttribute("type", "standby");
                element.addAttribute("k", algo.getVoteNum().toString());
            } else if ("bridge".equals(algo.getAlgorithmType())) {
                element.addAttribute("type", "bridge");
            }
@@ -977,7 +1112,8 @@
                break;
            case 3:
                // 二项分布
                if (taskBinoParam.getSimulatTimes().intValue() == taskBinoParam.getSuccessTimes().intValue()) {
                if ((taskBinoParam.getSimulatTimes() == null && taskBinoParam.getSuccessTimes() == null) ||
                        (taskBinoParam.getSimulatTimes().intValue() == taskBinoParam.getSuccessTimes().intValue())) {
                    // 相等则为成败型
                    failureModel.setType(FailureModel.TYPE_FIX);
                    failureModel.setParam1(taskBinoParam.getSuccessRate());