From c0e3f24edd2ef47339c676ff3dc6fdc06b3c387e Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期五, 18 十月 2024 10:42:40 +0800
Subject: [PATCH] 1)修改bug:可靠性预计参数配置,可靠性分布类型下拉框缺少威布尔分布; 2)细化可靠性仿真评估报错信息。

---
 modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java |  320 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 243 insertions(+), 77 deletions(-)

diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java
index b9b65f5..f6132a6 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/SimulatAssessService.java
@@ -14,7 +14,6 @@
 import com.zt.life.modules.mainPart.basicInfo.dao.XhProductModelDao;
 import com.zt.life.modules.mainPart.basicInfo.model.ParamData;
 import com.zt.life.modules.mainPart.basicInfo.model.XhProductModel;
-import com.zt.life.modules.mainPart.basicInfo.service.XhProductModelService;
 import com.zt.life.modules.mainPart.taskReliability.dao.*;
 import com.zt.common.utils.JsonUtils2;
 import com.zt.life.modules.mainPart.taskReliability.dao.SimulatAssessDao;
@@ -108,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;
 
@@ -151,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;
@@ -179,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;
@@ -188,63 +194,67 @@
         int groupHeight = 20;
 
         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());
-                JsonUtils2.setJsonValueByPath(lineJson, "data/startTimes".split("/"), String.format("%.4f", x1));
-                JsonUtils2.setJsonValueByPath(lineJson, "data/endTimes".split("/"), String.format("%.4f", x1 + status.getTimes()));
+                JsonUtils2.setJsonValueByPath(lineJson, "data/startTimes".split("/"), String.format("%.1f", startTime));
+                JsonUtils2.setJsonValueByPath(lineJson, "data/endTimes".split("/"), String.format("%.1f", startTime + status.getTimes()));
                 JsonUtils2.setJsonValueByPath(lineJson, "id".split("/"), UUIDUtil.generateId().toString());
+                startTime = startTime + status.getTimes();
                 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);
@@ -275,17 +285,18 @@
             JSONObject textJson = new JSONObject(templetsStrMap.get("text"));
             JsonUtils2.setJsonValueByPath(textJson, "data/dataId".split("/"), modelId);
             JsonUtils2.setJsonValueByPath(textJson, "id".split("/"), UUIDUtil.generateId().toString());
-            JsonUtils2.setJsonValueByPath(textJson, "attrs/label/textWrap/text".split("/"), "妯″瀷"+(i+1));
+            JsonUtils2.setJsonValueByPath(textJson, "attrs/label/textWrap/text".split("/"), "妯″瀷" + (i + 1));
             JsonUtils2.setJsonValueByPath(textJson, "attrs/label/textWrap/modelName".split("/"), modelName);
 
-            JsonUtils2.setJsonValueByPath(textJson, "size/width".split("/"), mapSpace.get("width")+10);
+            JsonUtils2.setJsonValueByPath(textJson, "size/width".split("/"), mapSpace.get("width") + 10);
 
-            double x11 = x1 + ((gkPoint - mapSpace.get("width")+12) / 2);
+            double x11 = x1 + ((gkPoint - mapSpace.get("width") + 12) / 2);
             JsonUtils2.setJsonValueByPath(textJson, "position/x".split("/"), x11);
-            JsonUtils2.setJsonValueByPath(textJson, "position/y".split("/"), y1-10);
+            JsonUtils2.setJsonValueByPath(textJson, "position/y".split("/"), y1 - 10);
             jsonArray.add(textJson);
             x1 = x2;
         }
+
         JSONObject modelJson3 = new JSONObject(templetsStrMap.get("model"));
         setlineXy(modelJson3, 0, y, x2, y, null);
         jsonArray.add(modelJson3);
@@ -307,15 +318,128 @@
 
             double x11 = x - mapSpace.get("width") / 2 - 5;
             JsonUtils2.setJsonValueByPath(textJson, "position/x".split("/"), x11);
-            JsonUtils2.setJsonValueByPath(textJson, "position/y".split("/"), y2-10);
+            JsonUtils2.setJsonValueByPath(textJson, "position/y".split("/"), y2 - 10);
             jsonArray.add(textJson);
 
             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);
@@ -328,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");
@@ -347,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("/"), "");
@@ -401,6 +532,7 @@
                 }
             }
         }
+        return modelStr2;
     }
 
     public List<ProductStatusDto> getStatusData(Long productId, Long taskId) {
@@ -480,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;
         }
 
@@ -498,7 +630,11 @@
         InputStream is = null;
         BufferedReader br = null;
         try {
-            setParamToRedis(simulatAssess);
+            try {
+                setParamToRedis(simulatAssess);
+            } catch (Exception e) {
+                throw new RenException("璁块棶Redis澶辫触銆傝妫�鏌edis鏄惁宸插惎鍔ㄣ��");
+            }
 
             Process process = null;
             String command = "python " + reliaSimMain;
@@ -510,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();
             // 浠ュ懡浠よ鏂瑰紡璋冪敤绠楁硶搴撴椂锛屾帴鍙g害瀹氳繑鍥炵殑缁撴灉鏄痷tf-8缂栫爜
@@ -521,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("鍚姩鍙潬鎬т豢鐪熻瘎浼扮畻娉曞簱浠跨湡鏃跺彂鐢烢xception锛�", e);
             e.printStackTrace();
-            result = Result.error(e.getMessage());
+            throw new RenException("鍚姩鍙潬鎬т豢鐪熻瘎浼扮畻娉曞簱澶辫触: errorMsg=" + e.getMessage());
         } finally {
             if (is != null) {
                 try {
@@ -579,6 +715,7 @@
 
     private void assembleModelXml(SimulatAssess simulatAssess) {
         Long productId = simulatAssess.getProductId();
+        XhProductModel product = xhProductModelDao.getById(productId);
         List<XhProductModel> productList = xhProductModelDao.getByShipId(productId);
         List<ParamData> paramDataList = paramDataDao.getDeviceParams(productId);
         Long taskId = simulatAssess.getTaskModelId();
@@ -604,6 +741,8 @@
             addTasksTag(taskPhaseModelAll, root);
             addModelsTag(taskId,
                     productId,
+                    product.getName(),
+                    product.getNamePath(),
                     productList,
                     paramDataList,
                     taskPhaseModelAll,
@@ -630,10 +769,10 @@
                 if (xmlWriter != null) xmlWriter.close();
             }
             // XML瀛樼洏
-            update(simulatAssess);
+            insert(simulatAssess);
         } catch (Exception e) {
             e.printStackTrace();
-            throw new RuntimeException("缁勮绠楁硶搴撲豢鐪熻绠楃敤妯″瀷XML澶辫触: " + e.getMessage());
+            throw new RenException("缁勮绠楁硶搴撲豢鐪熻绠楃敤妯″瀷XML澶辫触: " + e.getMessage());
         }
     }
 
@@ -666,8 +805,8 @@
         }
     }
 
-    private void addTasksTag(List<TaskPhaseModel> taskPhaseModelAll,
-                             Element root) {
+    public void addTasksTag(List<TaskPhaseModel> taskPhaseModelAll,
+                            Element root) {
         Element tasksTag = root.addElement("tasks");
         for (TaskPhaseModel taskPhaseModel : taskPhaseModelAll) {
             Element taskTag = tasksTag.addElement("task");
@@ -743,8 +882,8 @@
         }
     }
 
-    private void calcTaskPhaseModelDuration(TaskPhase taskPhase,
-                                            List<TaskPhaseModel> taskPhaseModelAll) {
+    public void calcTaskPhaseModelDuration(TaskPhase taskPhase,
+                                           List<TaskPhaseModel> taskPhaseModelAll) {
         List<TaskPhaseModel> taskPhaseModels = taskPhaseModelDao.getListByPhaseId(taskPhase.getId());
         double totalRate = taskPhaseModels.stream().mapToDouble(TaskPhaseModel::getOperatConditDurationRate).sum();
         double sum = 0.0;
@@ -763,7 +902,7 @@
         taskPhaseModels.get(taskPhaseModels.size() - 1).setOperatConditDuration(duration + taskPhase.getPhaseDuration() - sum);
     }
 
-    private List<TaskPhase> calcTaskPhaseDuration(Task task) {
+    public List<TaskPhase> calcTaskPhaseDuration(Task task) {
         List<TaskPhase> taskPhases = taskPhaseDao.getListByTaskId(task.getId());
         double totalRate = taskPhases.stream().mapToDouble(TaskPhase::getPhaseDurationRate).sum();
         double sum = 0.0;
@@ -781,6 +920,8 @@
 
     private void addModelsTag(Long taskId,
                               Long productId,
+                              String productName,
+                              String productNamePath,
                               List<XhProductModel> productList,
                               List<ParamData> paramDataList,
                               List<TaskPhaseModel> taskPhaseModelAll,
@@ -807,6 +948,8 @@
                     taskPhaseModel,
                     gkModelTop.getModelId(),
                     productId,
+                    productName,
+                    productNamePath,
                     productList,
                     paramDataList,
                     gkModelsAssembled,
@@ -823,6 +966,8 @@
                           TaskPhaseModel taskPhaseModel,
                           Long modelId,
                           Long productId,
+                          String productName,
+                          String productNamePath,
                           List<XhProductModel> productList,
                           List<ParamData> paramDataList,
                           List<OperatConditModel> gkModelsAssembled,
@@ -851,6 +996,8 @@
                         taskPhaseModel,
                         gkModel.getModelId(),
                         product.getId(),
+                        product.getName(),
+                        product.getNamePath(),
                         productList,
                         paramDataList,
                         gkModelsAssembled,
@@ -863,6 +1010,8 @@
                 // 璁惧
                 Element nodeTag = parent.addElement("node");
                 nodeTag.addAttribute("name", dataId.toString());
+                nodeTag.addAttribute("real_name", product.getName());
+                nodeTag.addAttribute("name_path", product.getNamePath());
                 nodeTag.addAttribute("type", "node");
 
                 ParamData paramData = paramDataList.stream().filter(item ->
@@ -908,6 +1057,8 @@
                 element.addAttribute("name", algo.getId().toString());
             } else {
                 element.addAttribute("name", productId.toString());
+                element.addAttribute("real_name", productName);
+                element.addAttribute("name_path", productNamePath);
             }
             if ("series".equals(algo.getAlgorithmType())) {
                 element.addAttribute("type", "series");
@@ -918,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");
             }
@@ -928,6 +1080,8 @@
                 node2DOM(taskId,
                         taskPhaseModel,
                         modelId,
+                        null,
+                        null,
                         null,
                         productList,
                         paramDataList,
@@ -958,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());
@@ -1006,7 +1161,7 @@
         String filePath = path + "/" + fzId + "/" + "result.xml";
         List<WeakDto> list = new ArrayList<>();
         Map<Long, WeakDto> map = new HashMap<>();
-        String xml = null;
+        String xml;
         InputStream in = null;
         try {
             in = new FileInputStream(filePath);
@@ -1016,10 +1171,13 @@
             throw new RenException("鏂囦欢涓嶅瓨鍦ㄦ垨鑰呮枃浠舵墦涓嶅紑");
         } finally {
             try {
-                in.close();
+                if (in != null) {
+                    in.close();
+                }
             } catch (IOException e) {
                 e.printStackTrace();
             }
+
         }
 
         List<WeakDto> productList = baseDao.getProductList(taskId, productId);
@@ -1030,39 +1188,45 @@
         JSONArray jsonArray = xmlJSONObj.getJSONObject("ResultNodes").getJSONArray("ResultNode");
         for (int i = 0; i < jsonArray.size(); i++) {
             WeakDto data = new WeakDto();
-            Long productId1 = null;
+            Long productId1;
             Object nameValue = jsonArray.getJSONObject(i).get("name");
             if (nameValue instanceof Long) {
                 productId1 = (Long) nameValue;
-                WeakDto weakDto = map.get(productId1);
-                Double mtbfTime = null;
+                if (map.get(productId1) != null) {
+                    WeakDto weakDto = map.get(productId1);
+                    Double mtbfTime = null;
 
-                Double mtbf = (Double) jsonArray.getJSONObject(i).get("mttf");
-                Double mttr = (Double) jsonArray.getJSONObject(i).get("mttr");
-                Double msr = (Double) jsonArray.getJSONObject(i).get("msr");
+                    Double mtbf = (Double) jsonArray.getJSONObject(i).get("mttf");
+                    Double mttr = (Double) jsonArray.getJSONObject(i).get("mttr");
+                    Double msr = (Double) jsonArray.getJSONObject(i).get("msr");
 
-                data.setMtbf(mtbf);
-                data.setMttr(mttr);
-                data.setMsr(msr);
+                    data.setMtbf(mtbf);
+                    data.setMttr(mttr);
+                    data.setMsr(msr);
 
-                if (weakDto != null) {
-                    data.setId(weakDto.getId());
-                    data.setSort(weakDto.getSort());
-                    data.setPid(weakDto.getPid());
-                    data.setName(weakDto.getName());
-                    data.setProductType(weakDto.getProductType());
-                    data.setTimeRate(weakDto.getTimeRate());
-                    mtbfTime = mtbf / weakDto.getTimeRate();
+                    if (weakDto != null) {
+                        data.setId(weakDto.getId());
+                        data.setSort(weakDto.getSort());
+                        data.setPid(weakDto.getPid());
+                        data.setName(weakDto.getName());
+                        data.setProductType(weakDto.getProductType());
+                        data.setTimeRate(weakDto.getTimeRate());
+                        mtbfTime = mtbf / weakDto.getTimeRate();
+                    }
+
+                    data.setMtbfTime(mtbfTime);
+                    data.setIsWeak(0);
+
+                    list.add(data);
                 }
-
-                data.setMtbfTime(mtbfTime);
-                data.setIsWeak(0);
-
-                list.add(data);
             }
         }
-        List<WeakDto> treeList = TreeUtils.build(list);
-        this.getIsweak(treeList.get(0).getChildren());
+        List<WeakDto> treeList = new ArrayList<>();
+        if (list.size() > 0) {
+            treeList = TreeUtils.build(list);
+            this.getIsweak(treeList.get(0).getChildren());
+        }
+
         return treeList;
     }
 
@@ -1098,10 +1262,10 @@
             task = taskService.get(taskModelId);
             simulatAssess = this.getByTaskId(taskModelId);
             SimulaDataDto resultData;
-            if (showProductId!=null){
+            if (showProductId != null) {
                 simulatAssess.setProductId(showProductId);
-                resultData =this.getResultXML(simulatAssess);
-            }else{
+                resultData = this.getResultXML(simulatAssess);
+            } else {
                 resultData = this.getResultXML(simulatAssess);
             }
 
@@ -1130,7 +1294,7 @@
             this.update(simulatAssess);
         }
         String filePath = path + "/" + simulatAssess.getId() + "/" + "result.xml";
-        String xml = null;
+        String xml;
         InputStream in = null;
 
         try {
@@ -1141,7 +1305,9 @@
             throw new RenException("鏂囦欢涓嶅瓨鍦ㄦ垨鑰呮枃浠舵墦涓嶅紑");
         } finally {
             try {
-                in.close();
+                if (in != null) {
+                    in.close();
+                }
             } catch (IOException e) {
                 e.printStackTrace();
             }

--
Gitblit v1.9.1