From 12e38a9c58fa02cc42104793609ac4e240bc6184 Mon Sep 17 00:00:00 2001
From: wente <329538422@qq.com>
Date: 星期四, 07 十一月 2024 16:46:29 +0800
Subject: [PATCH] 工况管理
---
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ReliabilityAssessService.java | 93 ++++++++++++++++++++++++++++++++--------------
1 files changed, 64 insertions(+), 29 deletions(-)
diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ReliabilityAssessService.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ReliabilityAssessService.java
index 1016376..2212a70 100644
--- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ReliabilityAssessService.java
+++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/service/ReliabilityAssessService.java
@@ -38,6 +38,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
@@ -157,9 +159,9 @@
String nameValue = jsonArray.getJSONObject(i).get("name").toString();
if (nameValue.contains(assess.getId().toString())) {
// 鑾峰彇瀵瑰簲鐨勫��
- if (jsonArray.getJSONObject(i).get("value") instanceof Double){
- result1 = (Double) jsonArray.getJSONObject(i).get("value");
- }else{
+ if (jsonArray.getJSONObject(i).get("value") instanceof Double) {
+ result1 = (Double) jsonArray.getJSONObject(i).get("value");
+ } else {
String[] values = jsonArray.getJSONObject(i).get("value").toString().split(",");
result1 = Double.valueOf(values[1]);
}
@@ -376,18 +378,18 @@
String NoEStr = "";
String ToEStr = "";
String FStr = "";
- for (ModelNode node : nodeList) {
- List<ReliabilityAssess> assessDatas = assessDataList.stream().filter(item ->
- node.getDataId().equals(item.getId())).collect(Collectors.toList());
- NoEStr += ",";
- ToEStr += ",";
- FStr += ",";
- if (assessDatas.size() > 0) {
- NoEStr += assessDatas.get(0).getRunNum() != null ? assessDatas.get(0).getRunNum().toString() : "0";
- ToEStr += assessDatas.get(0).getRunTimes() != null ? assessDatas.get(0).getRunTimes().toString() : "0";
- FStr += assessDatas.get(0).getFailNum() != null ? assessDatas.get(0).getFailNum().toString() : "0";
- }
+// for (ModelNode node : nodeList) {
+ List<ReliabilityAssess> assessDatas = assessDataList.stream().filter(item ->
+ dataId.equals(item.getId())).collect(Collectors.toList());
+ NoEStr += ",";
+ ToEStr += ",";
+ FStr += ",";
+ if (assessDatas.size() > 0) {
+ NoEStr += assessDatas.get(0).getRunNum() != null ? assessDatas.get(0).getRunNum().toString() : "0";
+ ToEStr += assessDatas.get(0).getRunTimes() != null ? assessDatas.get(0).getRunTimes().toString() : "0";
+ FStr += assessDatas.get(0).getFailNum() != null ? assessDatas.get(0).getFailNum().toString() : "0";
}
+// }
NoEStr = NoEStr.substring(1);
ToEStr = ToEStr.substring(1);
FStr = FStr.substring(1);
@@ -397,7 +399,7 @@
vCounter.put("v", counter);
Element sameNameGroupTag = parent.addElement("logic");
sameNameGroupTag.addAttribute("name",
- "v"+counter);
+ "v" + counter);
if ("parallel".equals(sameNameGroupAlgorithmType)) {
sameNameGroupTag.addAttribute("type", "parallel");
} else {
@@ -406,7 +408,8 @@
sameNameGroupTag.addAttribute("nums", String.valueOf(nodeList.size()));
Element nodeTag = sameNameGroupTag.addElement("node");
nodeTag.addAttribute("name",
- nodeList.stream().map(item -> item.getDataId().toString()).collect(Collectors.joining(",")));
+ nodeList.stream().map(item -> item.getDataId().toString() + "-" + item.getDeviceNo().toString()).
+ collect(Collectors.joining(",")));
nodeTag.addAttribute("real_name", product.getSameSbName());
nodeTag.addAttribute("name_path", product.getNamePath());
if (paramData.getReliabDistribType() == 3) {
@@ -519,16 +522,17 @@
}
}
- // 鏍规嵁鍚岀被璁惧鍚嶇О杩涜鍒嗙粍澶勭悊
+ // 鏍规嵁鍚岀被璁惧鍚嶇О杩涜鍒嗙粍澶勭悊锛堟敼涓烘牴鎹甦ataId杩涜鍒嗙粍锛�
Map<String, List<ModelNode>> groupByNameMap = new HashMap<>();
for (String nodeStr : computerNodeListStr) {
ModelNode mn = modelNodeAndVnodeList.stream().filter(item ->
nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0);
String sameSbName = null;
if (mn.getDataId() != null) {
- XhProductModel product = productList.stream().filter(item ->
- mn.getDataId().equals(item.getId())).collect(Collectors.toList()).get(0);
- if ("5".equals(product.getProductType())) sameSbName = product.getSameSbName();
+// XhProductModel product = productList.stream().filter(item ->
+// mn.getDataId().equals(item.getId())).collect(Collectors.toList()).get(0);
+// if ("5".equals(product.getProductType())) sameSbName = product.getSameSbName();
+ sameSbName = mn.getDataId().toString();
}
if (sameSbName == null) {
List<ModelNode> list = new ArrayList<>();
@@ -680,6 +684,7 @@
NoEStr += "," + (assessData.getRunNum() != null ? assessData.getRunNum().toString() : "0");
ToEStr += "," + (assessData.getRunTimes() != null ? assessData.getRunTimes().toString() : "0");
FStr += "," + (assessData.getFailNum() != null ? assessData.getFailNum().toString() : "0");
+ break;
}
}
NoEStr = NoEStr.substring(1);
@@ -687,7 +692,8 @@
FStr = FStr.substring(1);
nodeTag.addAttribute("name",
- nodes.stream().map(item -> item.getDataId().toString()).collect(Collectors.joining(",")));
+ nodes.stream().map(item -> item.getDataId().toString() + "-" + item.getDeviceNo().toString()).
+ collect(Collectors.joining(",")));
if (distTypes.get(0) == 3) {
// 浜岄」鍒嗗竷
nodeTag.addAttribute("distType", "ber");
@@ -717,7 +723,7 @@
try {
setParamToRedis(assessResult);
} catch (Exception e) {
- throw new RuntimeException("璁块棶Redis澶辫触銆傝妫�鏌edis鏄惁宸插惎鍔ㄣ��");
+ throw new RenException("璁块棶Redis澶辫触銆傝妫�鏌edis鏄惁宸插惎鍔ㄣ��");
}
Process process = null;
@@ -730,7 +736,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缂栫爜
@@ -741,19 +747,22 @@
if (line != null) {
ReliaSimLibResult rtn = com.alibaba.fastjson.JSONObject.parseObject(line, ReliaSimLibResult.class);
if ("0".equals(rtn.getCode())) {
- logger.info("鍚姩绠楁硶搴撴垚鍔熴��");
- result = Result.ok();
+ logger.info("鍚姩鍙潬鎬ц瘎瀹氱畻娉曞簱鎴愬姛銆�");
+ if (exitCode == 0) {
+ deleteAssessInfoInRedis(assessResult.getId());
+ result = Result.ok();
+ } else {
+ result = Result.error("鍙潬鎬ц瘎瀹氱畻娉曞簱璁$畻澶辫触: exitCode=" + exitCode);
+ }
} else {
String errorMsg = rtn.getErrorMsg();
- throw new RuntimeException("鍚姩绠楁硶搴撳け璐�: errorMsg=" + errorMsg);
+ throw new RenException("鍚姩鍙潬鎬ц瘎瀹氱畻娉曞簱澶辫触: errorMsg=" + errorMsg);
}
}
-
- deleteAssessInfoInRedis(assessResult.getId());
} catch (Exception e) {
logger.error("鍚姩鍙潬鎬ц瘎瀹氱畻娉曞簱鏃跺彂鐢烢xception锛�", e);
e.printStackTrace();
- result = Result.error(e.getMessage());
+ throw new RenException("鍚姩鍙潬鎬ц瘎瀹氱畻娉曞簱澶辫触: errorMsg=" + e.getMessage());
} finally {
if (is != null) {
try {
@@ -929,4 +938,30 @@
return baseDao.getAssessDataList(productId);
}
+ public void downloadXml(HttpServletRequest request, HttpServletResponse response, Long productId, Long taskId, Long itemId, Integer xml) {
+ Long assessId = baseDao.getAssessId(itemId, productId, taskId);
+ String json="";
+ if (xml == 1) {
+ json = baseDao.getxml(assessId);
+ } else {
+ String filePath = path + "/" + assessId + "/" + "result.xml";
+ InputStream in = null;
+ File file = new File(filePath);
+ if (file.exists()) {
+ try {
+ in = new FileInputStream(filePath);
+ json = IOUtils.toString(in);
+ } catch (IOException e) {
+ throw new RenException("鏂囦欢涓嶅瓨鍦ㄦ垨鑰呮枃浠舵墦涓嶅紑");
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ simulatAssessService.writeToTxt(request, response, json, "璇勫畾");
+ }
}
--
Gitblit v1.9.1