| | |
| | | |
| | | // 3. 调用算法库,进行评定计算 |
| | | result = callReliaAssessLib(assessResult); |
| | | if (result.getCode() != 0) throw new RenException(result.getMsg()); |
| | | |
| | | assessResultDao.insert(assessResult); |
| | | |
| | | List<ReliabilityAssess> list = this.getAssess(assessResult, assessId); |
| | |
| | | String nameValue = jsonArray.getJSONObject(i).get("name").toString(); |
| | | if (nameValue.contains(assess.getId().toString())) { |
| | | // 获取对应的值 |
| | | result1 = (Double) jsonArray.getJSONObject(i).get("value"); |
| | | 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]); |
| | | } |
| | | break; // 如果找到就退出循环 |
| | | } |
| | | } |
| | |
| | | InputStream is = null; |
| | | BufferedReader br = null; |
| | | try { |
| | | setParamToRedis(assessResult); |
| | | try { |
| | | setParamToRedis(assessResult); |
| | | } catch (Exception e) { |
| | | throw new RenException("访问Redis失败。请检查Redis是否已启动。"); |
| | | } |
| | | |
| | | Process process = null; |
| | | String command = "python " + assessMain; |
| | |
| | | } 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(); |
| | | // 以命令行方式调用算法库时,接口约定返回的结果是utf-8编码 |
| | |
| | | if (line != null) { |
| | | ReliaSimLibResult rtn = com.alibaba.fastjson.JSONObject.parseObject(line, ReliaSimLibResult.class); |
| | | if ("0".equals(rtn.getCode())) { |
| | | logger.info("启动算法库成功。"); |
| | | logger.info("启动可靠性评定算法库成功。"); |
| | | result = Result.ok(); |
| | | } else { |
| | | String errorMsg = rtn.getErrorMsg(); |
| | | throw new RuntimeException("启动算法库失败: errorMsg=" + errorMsg); |
| | | throw new RenException("启动可靠性评定算法库失败: errorMsg=" + errorMsg); |
| | | } |
| | | } |
| | | |
| | | // deleteAssessInfoInRedis(assessResult.getId()); //TODO(发布时放开) |
| | | deleteAssessInfoInRedis(assessResult.getId()); |
| | | } catch (Exception e) { |
| | | logger.error("启动可靠性评定算法库时发生Exception:", e); |
| | | e.printStackTrace(); |
| | | result = Result.error(e.getMessage()); |
| | | throw new RenException("启动可靠性评定算法库失败: errorMsg=" + e.getMessage()); |
| | | } finally { |
| | | if (is != null) { |
| | | try { |