| | |
| | | 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; |
| | |
| | | |
| | | Long assessId = UUIDUtil.generateId(); |
| | | assessResult.setId(assessId); |
| | | /* |
| | | // 1. 检查参数完整性 |
| | | List<TaskModelCheckResultDto> chkResult = taskService.checkTaskModel(simulatAssess.getProductId(), |
| | | simulatAssess.getTaskModelId()); |
| | | if (chkResult.size() > 0) { |
| | | result = Result.error("模型不完整,请检查模型定义及参数配置。"); |
| | | return result; |
| | | } |
| | | |
| | | */ |
| | | // 2. 组装供算法库评定的模型xml |
| | | // 1. 组装供算法库评定的模型xml |
| | | assembleModelXml(assessResult); |
| | | |
| | | // 3. 调用算法库,进行评定计算 |
| | | // 2. 调用算法库,进行评定计算 |
| | | result = callReliaAssessLib(assessResult); |
| | | if (result.getCode() != 0) throw new RenException(result.getMsg()); |
| | | |
| | |
| | | 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]); |
| | | } |
| | |
| | | |
| | | // 建立产品结构树时,相同的设备多个使用时,多个设备使用相同的名称。这样,在此处通过名称来判断是否是相同的设备,相同的设备,需要拿出来作为子标签嵌套进xml。 |
| | | private void assembleModelXml(AssessResult assessResult) { |
| | | /* |
| | | // 测试算法库用 |
| | | String xml = "<des name=\"General system\" gama=\"0.7\">\n" + |
| | | " <tasks>\n" + |
| | | " <task duration=\"1\" model=\"1819282257303678978\"/>\n" + |
| | | " </tasks>\n" + |
| | | " <models>\n" + |
| | | " <model name=\"1819282257303678978\">\n" + |
| | | " <logic name=\"系统\" type=\"series\" >\n" + |
| | | " <logic name=\"分系统1\" type=\"series\" >\n" + |
| | | " <logic name=\"v1\" type=\"parallel\" nums=\"2\">\n" + |
| | | " <node name=\"设备1\" distType=\"exp\" ToE=\"20\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <node name=\"设备2\" distType=\"exp\" ToE=\"0.3\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <logic name=\"分系统2\" type=\"series\" >\n" + |
| | | " <node name=\"设备3\" distType=\"exp\" ToE=\"0.2\" F=\"0\"/>\n" + |
| | | " <node name=\"设备4\" distType=\"ber\" NoE=\"18\" F=\"0\"/>\n" + |
| | | " <logic name=\"v2\" type=\"series\" nums=\"2\">\n" + |
| | | " <node name=\"设备5\" distType=\"exp\" ToE=\"0.5,0,6\" F=\"1,2\"/>\n" + |
| | | " </logic> \n" + |
| | | " <node name=\"设备6\" distType=\"exp\" ToE=\"0.3\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <logic name=\"分系统3\" type=\"vote\" nums=\"3\" k=\"2\" >\n" + |
| | | " <node name=\"设备7\" distType=\"exp\" ToE=\"87\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " </logic>\n" + |
| | | " </model>\n" + |
| | | " </models>\n" + |
| | | "</des>"; |
| | | String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
| | | "\n" + |
| | | "<des name=\"General system\" gama=\"0.6\">\n" + |
| | | " <tasks>\n" + |
| | | " <task duration=\"1.0\" model=\"1839217232446533633\"/>\n" + |
| | | " </tasks>\n" + |
| | | " <models>\n" + |
| | | " <model name=\"1839217232446533633\">\n" + |
| | | " <logic name=\"1727338143768926498\" real_name=\"评审用船A\" type=\"series\">\n" + |
| | | " <logic name=\"1727338125295232953\" real_name=\"通信系统\" name_path=\"通信系统\" type=\"series\">\n" + |
| | | " <logic name=\"v1\" type=\"parallel\" nums=\"2\">\n" + |
| | | " <node name=\"1727338347041863487,1727338104458428136\" real_name=\"对讲机\" name_path=\"通信系统,对讲机b\" distType=\"ber\" NoE=\"0,10\" F=\"0,1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <node name=\"1727338109884317860\" real_name=\"交换机\" name_path=\"通信系统,交换机\" distType=\"exp\" ToE=\"10\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <logic name=\"1727338132480394459\" real_name=\"空调系统\" name_path=\"空调系统\" type=\"vote\" k=\"2\" nums=\"3\">\n" + |
| | | " <node name=\"1727338148414415252,1727338894880570868,1727338666019181419\" real_name=\"空调\" name_path=\"空调系统,空调c\" distType=\"exp\" ToE=\"88,87,86\" F=\"8,7,6\"/>\n" + |
| | | " </logic>\n" + |
| | | " <logic name=\"1727338199831104683\" real_name=\"电力系统\" name_path=\"电力系统\" type=\"series\">\n" + |
| | | " <node name=\"1727338129701280729\" real_name=\"发电机2\" name_path=\"电力系统,发电机2\" distType=\"ber\" NoE=\"20\" F=\"2\"/>\n" + |
| | | " <node name=\"1727338865212183133\" real_name=\"发电机1\" name_path=\"电力系统,发电机1\" distType=\"exp\" ToE=\"20\" F=\"2\"/>\n" + |
| | | " <node name=\"1727338589328410328\" real_name=\"配电板\" name_path=\"电力系统,配电板\" distType=\"exp\" ToE=\"50\" F=\"5\"/>\n" + |
| | | " <logic name=\"v3\" type=\"series\" nums=\"2\">\n" + |
| | | " <node name=\"1727338101737644187,1727338554151292452\" real_name=\"蓄电池\" name_path=\"电力系统,蓄电池a\" distType=\"exp\" ToE=\"30,40\" F=\"3,4\"/>\n" + |
| | | " </logic>\n" + |
| | | " </logic>\n" + |
| | | " </logic>\n" + |
| | | " </model>\n" + |
| | | " </models>\n" + |
| | | "</des>"; |
| | | assessResult.setXml(xml1); |
| | | */ |
| | | Long productId = assessResult.getProductId(); |
| | | Long taskId = assessResult.getTaskId(); |
| | | Long itemId = assessResult.getItemId(); |
| | |
| | | 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); |
| | |
| | | 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 { |
| | |
| | | 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) { |
| | |
| | | } |
| | | } |
| | | |
| | | // 根据同类设备名称进行分组处理 |
| | | // 根据同类设备名称进行分组处理(改为根据dataId进行分组) |
| | | 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<>(); |
| | |
| | | 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); |
| | |
| | | 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"); |
| | |
| | | ReliaSimLibResult rtn = com.alibaba.fastjson.JSONObject.parseObject(line, ReliaSimLibResult.class); |
| | | if ("0".equals(rtn.getCode())) { |
| | | logger.info("启动可靠性评定算法库成功。"); |
| | | result = Result.ok(); |
| | | if (exitCode == 0) { |
| | | deleteAssessInfoInRedis(assessResult.getId()); |
| | | result = Result.ok(); |
| | | } else { |
| | | result = Result.error("可靠性评定算法库计算失败: exitCode=" + exitCode); |
| | | } |
| | | } else { |
| | | String errorMsg = rtn.getErrorMsg(); |
| | | throw new RenException("启动可靠性评定算法库失败: errorMsg=" + errorMsg); |
| | | } |
| | | } |
| | | |
| | | deleteAssessInfoInRedis(assessResult.getId()); |
| | | } catch (Exception e) { |
| | | logger.error("启动可靠性评定算法库时发生Exception:", e); |
| | | e.printStackTrace(); |
| | |
| | | path = shipPath = name; |
| | | xtPath = ""; |
| | | fxtPath = ""; |
| | | sbPath = ""; |
| | | productId = shipId; |
| | | } else { |
| | | if (type.equals("系统")) { |
| | | if (StringUtils.isNotBlank(shipPath)) { |
| | | path = xtPath = name; |
| | | fxtPath = ""; |
| | | sbPath = ""; |
| | | } else { |
| | | continue; |
| | | } |
| | |
| | | if (type.equals("分系统")) { |
| | | if (StringUtils.isNotBlank(xtPath)) { |
| | | path = fxtPath = xtPath + "," + name; |
| | | sbPath = ""; |
| | | } else { |
| | | continue; |
| | | } |
| | | } |
| | | if (type.equals("设备")) { |
| | | if ((StringUtils.isNotBlank(xtPath) || StringUtils.isNotBlank(fxtPath))) { |
| | | path = sbPath = StringUtils.isNotBlank(fxtPath) ? fxtPath + "," + name : xtPath + "," + name; |
| | | path = StringUtils.isNotBlank(fxtPath) ? fxtPath + "," + name : xtPath + "," + name; |
| | | } else { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | baseDao.deleteByItemId(itemId); |
| | | ReliabilityAssess assess = new ReliabilityAssess(); |
| | | assess.setFailNum(failNum); |
| | | assess.setRunNum(runNum); |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | ImportUtil.updateErrMap(errMap, "导入异常" + e.getMessage(), "", row1); |
| | | //err++; |
| | | } |
| | | |
| | | Date nowDate = new Date(); |
| | |
| | | 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, "评定"); |
| | | } |
| | | } |