From 8b6dccc8ff919ca8970c4981b2e8cb30892e6698 Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期二, 06 八月 2024 16:08:52 +0800
Subject: [PATCH] 修改
---
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java | 124 ++++++++++++++++++----------------------
1 files changed, 56 insertions(+), 68 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 992308e..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
@@ -18,11 +18,13 @@
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.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;
@@ -51,8 +53,6 @@
@Api(tags = "simulat_assess")
public class SimulatAssessController {
private static final Logger logger = LoggerFactory.getLogger(SimulatAssessController.class);
- private static final String taskTypeProgress = "calcprog";
- private List<Map<String, Double>> dialgram = new ArrayList<>();
@Autowired
private RedisTemplate redisTemplate;
@@ -62,16 +62,15 @@
@Autowired
private TaskService taskService;
-
@Value("${data.reliaSimLib.resultHome}")
private String path;
+
@Autowired
private SimulatAssessService simulatAssessService;
private JSONObject xmlJSONObj;
- private JSONObject dialgramJson;
/* @GetMapping("page")
@ApiOperation("鍒嗛〉")
@@ -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());
@@ -149,7 +156,7 @@
public SimulaDataDto getResultData(SimulatAssess simulatAssess) {
SimulaDataDto data = new SimulaDataDto();
CurveParam param = new CurveParam();
- Double samplPeriod = simulatAssess.getSamplPeriod().doubleValue();
+ Double samplPeriod = Double.valueOf(simulatAssess.getSamplPeriod());
Task task = taskService.get(simulatAssess.getTaskModelId());
samplPeriod = samplPeriod / 60;
List<Double> xList = new ArrayList<>();
@@ -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);
}
@@ -191,67 +209,38 @@
}
@GetMapping("getStatus")
- public Result<List<ProductStatusDto>> getStatus(Long productId, Long taskId, Long fzId) {
- String filePath = path + "/" + fzId + "/" + "status.json";
- ObjectMapper mapper = new ObjectMapper();
- String jsonStr = null;
- try {
- // 浣跨敤 ObjectMapper 鐨� readValue 鏂规硶锛屽皢鏂囦欢涓殑 JSON 鏁版嵁杞崲涓轰竴涓� Java 瀵硅薄
- // 杩欓噷浣跨敤 Object 绫讳綔涓烘硾鍨嬪弬鏁帮紝琛ㄧず浠绘剰绫诲瀷鐨勫璞�
- Object obj = mapper.readValue(new File(filePath), Object.class);
- // 浣跨敤 ObjectMapper 鐨� writeValueAsString 鏂规硶锛屽皢 Java 瀵硅薄杞崲涓� JSON 瀛楃涓�
- jsonStr = mapper.writeValueAsString(obj);
-
- } catch (IOException e) {
- // 澶勭悊寮傚父
- e.printStackTrace();
- }
- dialgramJson = new JSONObject(jsonStr);
- List<ProductStatusDto> childList = this.getStatusData(productId, taskId);
- return Result.ok(childList);
-
+ public Result<String> getTimeDiagram(Long productId, Long taskId, Long fzId) {
+ String data = simulatAssessService.getTimeDiagram(productId, taskId, fzId);
+ return Result.ok(data);
}
- public List<ProductStatusDto> getStatusData(Long productId, Long taskId) {
- List<ProductStatusDto> childList = simulatAssessService.getChildren(productId, taskId);
- for (ProductStatusDto item : childList) {
- if (dialgram.size() > 0) {
- dialgram.clear();
- }
- JSONArray jsonArray = dialgramJson.getJSONArray(String.valueOf(item.getId()));
- if (jsonArray != null) {
- this.processJSONArray(jsonArray, item);
- }
- }
- return childList;
+ @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);
}
- public void processJSONArray(JSONArray jsonArray, ProductStatusDto productStatusDto) {
- String status = null;
- Double times = null;
- for (int i = 0; i < jsonArray.size(); i++) {
- Object item = jsonArray.get(i);
- if (item instanceof JSONArray) {
- processJSONArray((JSONArray) item, productStatusDto); // 閫掑綊璋冪敤
- } else {
- if (item instanceof Double) {
- times = (Double) item;
- } else {
- status = String.valueOf(item);
- }
- }
- }
- if (status != null || times != null) {
- StatusDto statusDto =new StatusDto();
- statusDto.setTimes(times);
- statusDto.setStatus(status);
- productStatusDto.getStatusList().add(statusDto);
- }
+ @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 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);
@@ -278,7 +267,6 @@
return Result.ok();
}
-
}
--
Gitblit v1.9.1