人工交互分析gamma重新分析峰数据调用算法部分代码修改,dll改为调用http服务的方式
This commit is contained in:
parent
ff6d8b9baa
commit
9f64646c77
|
@ -0,0 +1,103 @@
|
|||
package org.jeecg.common.handler;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class HttpClient {
|
||||
private static final String URL_ADDRESS = "http://127.0.0.1:7080/";
|
||||
|
||||
public static String fitPeakFull(String phdStr, List<Integer> Af, List<Integer> Cf, List<Integer> Ff) {
|
||||
//接收算法返回内容
|
||||
String resultJson = "";
|
||||
//拼接请求路径
|
||||
String url = URL_ADDRESS + "fitPeakFull";
|
||||
HttpURLConnection connection = null;
|
||||
OutputStream out = null;
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
//创建请求参数 以json的形式
|
||||
JsonObject requestJson = new JsonObject();
|
||||
requestJson.addProperty("phd", phdStr);
|
||||
JsonArray AfJson = new JsonArray();
|
||||
for (int i = 0; i < Af.size(); i++) {
|
||||
AfJson.add(Af.get(i));
|
||||
}
|
||||
requestJson.add("Af", AfJson);
|
||||
JsonArray CfJson = new JsonArray();
|
||||
for (int i = 0; i < Cf.size(); i++) {
|
||||
CfJson.add(Cf.get(i));
|
||||
}
|
||||
requestJson.add("Cf", CfJson);
|
||||
JsonArray FfJson = new JsonArray();
|
||||
for (int i = 0; i < Ff.size(); i++) {
|
||||
FfJson.add(Ff.get(i));
|
||||
}
|
||||
requestJson.add("Ff", FfJson);
|
||||
//请求的json参数转换为字符串
|
||||
String requestParam = requestJson.toString();
|
||||
//请求的json字符串转为字节数组的方式
|
||||
byte[] requestParamBytes = requestParam.getBytes(StandardCharsets.UTF_8);
|
||||
//建立Http连接
|
||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setRequestProperty("Content-Length", String.valueOf(requestParamBytes.length));
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(300000);
|
||||
connection.setReadTimeout(300000);
|
||||
//获取http连接的输出流
|
||||
out = connection.getOutputStream();
|
||||
//向输出流写入传递的参数字节数组信息
|
||||
out.write(requestParamBytes);
|
||||
//接收http请求的响应编码
|
||||
int responseCode = connection.getResponseCode();
|
||||
//如果是成功的响应编码
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
StringBuilder responseBuilder = new StringBuilder();
|
||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
responseBuilder.append(line);
|
||||
}
|
||||
resultJson = responseBuilder.toString();
|
||||
} else {
|
||||
System.out.println("Error while sending request to C++ server, response code: " + responseCode);
|
||||
}
|
||||
} catch (ProtocolException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (Objects.nonNull(out)) {
|
||||
out.close();
|
||||
}
|
||||
if (Objects.nonNull(connection)) {
|
||||
connection.disconnect();
|
||||
}
|
||||
if (Objects.nonNull(in)) {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ import org.apache.shiro.SecurityUtils;
|
|||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.cache.LocalCache;
|
||||
import org.jeecg.common.constant.DateConstant;
|
||||
import org.jeecg.common.handler.HttpClient;
|
||||
import org.jeecg.common.properties.ParameterProperties;
|
||||
import org.jeecg.common.properties.SpectrumPathProperties;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
|
@ -1491,7 +1492,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
|
|||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String phdStr = mapper.writeValueAsString(phd);
|
||||
String strValue = CalValuesHandler.fitPeakFull(phdStr, Af, Cf, Ff);
|
||||
String strValue = HttpClient.fitPeakFull(phdStr, Af, Cf, Ff);
|
||||
Map<String, Object> parseMap = JSON.parseObject(strValue, Map.class);
|
||||
for (Map.Entry<String, Object> entry : parseMap.entrySet()) {
|
||||
if (entry.getKey().equalsIgnoreCase("vPeak")) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user