From 8d4f47547f7e502ea5825f4a519aa88e7cdb2596 Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期二, 06 八月 2024 14:19:02 +0800
Subject: [PATCH] 修改

---
 modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java |  171 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 141 insertions(+), 30 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 fa81fd7..fbc976f 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
@@ -1,37 +1,45 @@
 package com.zt.life.modules.mainPart.taskReliability.controller;
 
 
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.XML;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.zt.common.annotation.LogOperation;
-import com.zt.common.constant.Constant;
-import com.zt.common.annotation.QueryParam;
-import com.zt.common.db.query.QueryFilter;
 import com.zt.common.servlet.Result;
-import com.zt.common.servlet.PageResult;
-import com.zt.common.utils.JsonUtils;
 import com.zt.common.validator.AssertUtils;
 import com.zt.common.validator.ValidatorUtils;
 import com.zt.common.validator.group.DefaultGroup;
 import com.zt.common.validator.group.UpdateGroup;
 import com.zt.life.modules.mainPart.async.PythonLib;
+import com.zt.life.modules.mainPart.taskReliability.dto.SimulaDataDto;
+import com.zt.life.modules.mainPart.taskReliability.dto.ProductStatusDto;
+import com.zt.life.modules.mainPart.taskReliability.dto.StatusDto;
+import com.zt.life.modules.mainPart.taskReliability.model.CurveParam;
 import com.zt.life.modules.mainPart.taskReliability.model.SimulatAssess;
+import com.zt.life.modules.mainPart.taskReliability.model.Task;
+import com.zt.life.modules.mainPart.taskReliability.model.TimeDiagram;
 import com.zt.life.modules.mainPart.taskReliability.service.SimulatAssessService;
+import com.zt.life.modules.mainPart.taskReliability.service.TaskService;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
-import springfox.documentation.annotations.ApiIgnore;
 
+import java.io.File;
+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;
 
 
 /**
@@ -53,13 +61,19 @@
     @Autowired
     private PythonLib pythonLib;
 
+    @Autowired
+    private TaskService taskService;
     @Value("${data.reliaSimLib.resultHome}")
     private String path;
+
 
     @Autowired
     private SimulatAssessService simulatAssessService;
 
-    @GetMapping("page")
+    private JSONObject xmlJSONObj;
+
+
+   /* @GetMapping("page")
     @ApiOperation("鍒嗛〉")
     @ApiImplicitParams({
             @ApiImplicitParam(name = Constant.Q.PAGE, value = Constant.QV.PAGE, required = true, dataType = Constant.QT.INT),
@@ -70,7 +84,7 @@
     public PageResult<SimulatAssess> page(@ApiIgnore @QueryParam QueryFilter queryFilter) {
 
         return PageResult.ok(simulatAssessService.page(queryFilter));
-    }
+    }*/
 
     @GetMapping("{id}")
     @ApiOperation("淇℃伅")
@@ -80,47 +94,143 @@
         return Result.ok(data);
     }
 
+    @GetMapping("getSimulatList")
+    @ApiOperation("淇℃伅")
+    public Result<List<SimulatAssess>> getSimulatList(Long productId, Long taskModelId) {
+        List<SimulatAssess> data = simulatAssessService.getList(productId, taskModelId);
+
+        return Result.ok(data);
+    }
+
+    @GetMapping("getSimulatParams")
+    @ApiOperation("淇℃伅")
+    public Result<SimulatAssess> getSimulatParams(Long id, Long taskModelId) {
+        SimulatAssess data = simulatAssessService.getParams(id, taskModelId);
+
+        return Result.ok(data);
+    }
+
     @PostMapping("analyze")
     public Result<Long> analyze(@RequestBody SimulatAssess simulatAssess) {
         //鏁堥獙鏁版嵁
-/*
-        ValidatorUtils.validateEntity(simulatAssess, AddGroup.class, DefaultGroup.class);
-        Long taskId = UUIDUtil.generateId();
-        Integer time = simulatAssess.getSamplPeriod();
-        Integer Frequency = simulatAssess.getSimulatFrequency();
-        HashMap<String, Object> paramMap = new HashMap<>();
-        paramMap.put("taskId", taskId);
-        paramMap.put("time", time);
-        paramMap.put("Frequency", Frequency);
-        paramMap.put("url", "http://localhost:8050/test-project//taskReliability/SimulatAssess/calculate");
-        String result1 = HttpUtil.get("http://localhost:8080/system/user/get", paramMap);
-*/
-        Result result = pythonLib.callPython(simulatAssess);
+//        Result result = pythonLib.callPython(simulatAssess);
+        Result result = simulatAssessService.simulate(simulatAssess);
 
         return result;
     }
 
-    @GetMapping("getResultXML")
-    public Result getResultXML(Long taskId) {
-        String filePath = path + "/"+taskId+"/"+"result.xml";
-        InputStream in = JsonUtils.class.getResourceAsStream(filePath);
+    @PostMapping("getResultXML")
+    public Result<SimulaDataDto> getResultXML(@RequestBody SimulatAssess simulatAssess) {
+        if (simulatAssess.getDataType().equals("fz")) {
+            Integer num = simulatAssessService.getNumById(simulatAssess.getProductId(), simulatAssess.getTaskModelId());
+            simulatAssess.setName("浠跨湡璁板綍" + (num + 1));
+            simulatAssessService.insert(simulatAssess);
+        }
+        String filePath = path + "/" + simulatAssess.getId() + "/" + "result.xml";
         String xml = null;
         try {
+            InputStream in = new FileInputStream(filePath);
             xml = IOUtils.toString(in);
+            in.close();
         } catch (IOException e) {
             e.printStackTrace();
         }
-        JSONObject xmlJSONObj = XML.toJSONObject(xml);
+        xmlJSONObj = XML.toJSONObject(xml);
+        simulatAssess.setShowProductId(simulatAssess.getProductId());
+        SimulaDataDto data = this.getResultData(simulatAssess);
+        return Result.ok(data);
+    }
 
+    @PostMapping("getResultData")
+    public Result<SimulaDataDto> getData(@RequestBody SimulatAssess simulatAssess) {
+        SimulaDataDto data = this.getResultData(simulatAssess);
+        return Result.ok(data);
+    }
 
+    public SimulaDataDto getResultData(SimulatAssess simulatAssess) {
+        SimulaDataDto data = new SimulaDataDto();
+        CurveParam param = new CurveParam();
+        Double samplPeriod = Double.valueOf(simulatAssess.getSamplPeriod());
+        Task task = taskService.get(simulatAssess.getTaskModelId());
+        samplPeriod = samplPeriod / 60;
+        List<Double> xList = new ArrayList<>();
+        for (Double i = 0.0; i + samplPeriod <= task.getTaskDuration(); i += samplPeriod) {
+            xList.add(i);
+        }
+        param.setXData(xList);
+        JSONArray jsonArray = xmlJSONObj.getJSONObject("ResultNodes").getJSONArray("ResultNode");
+        for (int i = 0; i < jsonArray.size(); i++) {
+            Long productId = null;
+            Object nameValue = jsonArray.getJSONObject(i).get("name");
+            if (nameValue instanceof Long) {
+                productId = (Long) nameValue;
+                if (productId.equals(simulatAssess.getShowProductId())) {
+                    JSONArray jsonArray2 = jsonArray.getJSONObject(i).getJSONArray("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");
+                        }
+                    }
+
+                    String[] arr = availability.split(" ");
+                    // 閬嶅巻瀛愬瓧绗︿覆鏁扮粍锛屽皢姣忎釜鍏冪礌杞崲涓篸ouble骞跺瓨鍌ㄥ埌double鏁扮粍涓�
+                    for (int a = 0; a < arr.length; a++) {
+                        doubleArray.add(Double.parseDouble(arr[a]));
+                    }
+                    param.setYData(doubleArray);
+                    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);
+            }
+        }
+
+        return data;
+    }
+
+    @GetMapping("getStatus")
+    public Result<String> getTimeDiagram(Long productId, Long taskId, Long fzId) {
+        String data = simulatAssessService.getTimeDiagram(productId, taskId, fzId);
+        return  Result.ok(data);
+    }
+
+    @GetMapping("getDiagram")
+    @ApiOperation("鏌ヨ娴佺▼鍥�")
+    @LogOperation("鏌ヨ娴佺▼鍥�")
+    public Result<TimeDiagram> getDiagram(String projectId, String diagramId, String showType, String isShow, String digramParams, String majorId, Integer winWidth, Integer winHeight) throws Exception {
+        if (StringUtils.isBlank(diagramId))
+            diagramId = projectId;
+        TimeDiagram diagram = simulatAssessService.getDiagram(projectId, diagramId, showType, isShow, digramParams, majorId, winWidth, winHeight);
+        return Result.ok(diagram);
+    }
+
+    @PutMapping("saveDiagram")
+    @ApiOperation("鏌ヨ娴佺▼鍥�")
+    @LogOperation("鏌ヨ娴佺▼鍥�")
+    public Result saveDiagram(@RequestBody TimeDiagram diagram) {
+        // 鏁堥獙鏁版嵁
+        //ValidatorUtils.validateEntity(project.getProject(), UpdateGroup.class, DefaultGroup.class);
+        if (diagram.getConfigChange() == null)
+            diagram.setConfigChange(0);
+        diagram.setSaveStatus(2);
+        simulatAssessService.updateDiagram(diagram);
+        //simulatAssessService.combineDiagram(diagram);
         return Result.ok();
     }
 
     @GetMapping("getCalcProgress")
     public Result getCalcProgress(Long taskId) {
         String key = taskId.toString() + taskTypeProgress;
-        String progress = (String)redisTemplate.opsForValue().get(key);
-        if (progress==null) progress = "0";
+        String progress = (String) redisTemplate.opsForValue().get(key);
+        if (progress == null) progress = "0";
         return Result.ok(progress);
     }
 
@@ -146,4 +256,5 @@
         return Result.ok();
     }
 
+
 }

--
Gitblit v1.9.1