From 9a8ba8089ef213b23b945aff895d70377e95673c Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期五, 16 八月 2024 09:40:31 +0800
Subject: [PATCH] 修改仿真后台

---
 modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java |   48 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 32 insertions(+), 16 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 99aff53..a022a2b 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
@@ -36,10 +36,7 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
@@ -53,7 +50,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;
@@ -128,11 +124,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,15 +167,21 @@
             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(" ");
@@ -181,8 +190,12 @@
                         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);
             }
@@ -194,7 +207,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")
@@ -223,9 +236,12 @@
 
     @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";
+        if(Objects.equals(progress, "100")){
+            simulatAssessService.deleteSimInfoInRedis(taskId);
+        }
         return Result.ok(progress);
     }
 

--
Gitblit v1.9.1