From fe295552e5a3b010b5a6a60a1e2a94bc39b49d68 Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期二, 06 八月 2024 15:37:09 +0800
Subject: [PATCH] 修改

---
 modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java |   42 ++++++++++++++++++++++++++++++------------
 1 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java
index 50c1cdf..475202b 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java
@@ -53,7 +53,6 @@
 @Api(tags = "simulat_assess")
 public class SimulatAssessController {
     private static final Logger logger = LoggerFactory.getLogger(SimulatAssessController.class);
-    private static final String taskTypeProgress = "calcprog";
 
     @Autowired
     private RedisTemplate redisTemplate;
@@ -121,6 +120,7 @@
 
     @PostMapping("getResultXML")
     public Result<SimulaDataDto> getResultXML(@RequestBody SimulatAssess simulatAssess) {
+        simulatAssessService.deleteSimInfoInRedis(simulatAssess.getId());
         if (simulatAssess.getDataType().equals("fz")) {
             Integer num = simulatAssessService.getNumById(simulatAssess.getProductId(), simulatAssess.getTaskModelId());
             simulatAssess.setName("浠跨湡璁板綍" + (num + 1));
@@ -128,11 +128,18 @@
         }
         String filePath = path + "/" + simulatAssess.getId() + "/" + "result.xml";
         String xml = null;
+        InputStream in =null;
         try {
-            InputStream in = new FileInputStream(filePath);
+            in = new FileInputStream(filePath);
             xml = IOUtils.toString(in);
         } catch (IOException e) {
             e.printStackTrace();
+        }finally {
+            try {
+                in.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
         xmlJSONObj = XML.toJSONObject(xml);
         simulatAssess.setShowProductId(simulatAssess.getProductId());
@@ -164,24 +171,35 @@
             if (nameValue instanceof Long) {
                 productId = (Long) nameValue;
                 if (productId.equals(simulatAssess.getShowProductId())) {
-                    JSONArray jsonArray2 = jsonArray.getJSONObject(i).getJSONArray("phase");
+                    Object object = jsonArray.getJSONObject(i).get("phase");
                     List<Double> doubleArray = new ArrayList<>();
                     String availability = null;
-                    for (int j = 0; j < jsonArray2.size(); j++) {
-                        if (availability != null) {
-                            availability = availability + " " + jsonArray2.getJSONObject(j).get("availability");
-                        } else {
-                            availability = (String) jsonArray2.getJSONObject(j).get("availability");
+                    if (object instanceof JSONArray) {
+                        JSONArray jsonArray2 = jsonArray.getJSONObject(i).getJSONArray("phase");
+                        for (int j = 0; j < jsonArray2.size(); j++) {
+                            if (availability != null) {
+                                availability = availability + " " + jsonArray2.getJSONObject(j).get("availability");
+                            } else {
+                                availability = (String) jsonArray2.getJSONObject(j).get("availability");
+                            }
                         }
+                    } else {
+                        JSONObject jsonObject2 = jsonArray.getJSONObject(i).getJSONObject("phase");
+                        availability = (String) jsonObject2.get("availability");
                     }
+
                     String[] arr = availability.split(" ");
                     // 閬嶅巻瀛愬瓧绗︿覆鏁扮粍锛屽皢姣忎釜鍏冪礌杞崲涓篸ouble骞跺瓨鍌ㄥ埌double鏁扮粍涓�
                     for (int a = 0; a < arr.length; a++) {
                         doubleArray.add(Double.parseDouble(arr[a]));
                     }
                     param.setYData(doubleArray);
-                    data.setMtbf((Double) jsonArray.getJSONObject(i).get("mttf"));
-                    data.setMttr((Double) jsonArray.getJSONObject(i).get("mttr"));
+                    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.setCurveParam(param);
             }
@@ -193,7 +211,7 @@
     @GetMapping("getStatus")
     public Result<String> getTimeDiagram(Long productId, Long taskId, Long fzId) {
         String data = simulatAssessService.getTimeDiagram(productId, taskId, fzId);
-        return  Result.ok(data);
+        return Result.ok(data);
     }
 
     @GetMapping("getDiagram")
@@ -222,7 +240,7 @@
 
     @GetMapping("getCalcProgress")
     public Result getCalcProgress(Long taskId) {
-        String key = taskId.toString() + taskTypeProgress;
+        String key = taskId.toString() + simulatAssessService.RELIA_SIM_TASK_TYPE_PROGRESS;
         String progress = (String) redisTemplate.opsForValue().get(key);
         if (progress == null) progress = "0";
         return Result.ok(progress);

--
Gitblit v1.9.1