diff --git a/ruoyi-admin/src/main/java/com/ruoyi/dfm/controller/DoeAnalysisController.java b/ruoyi-admin/src/main/java/com/ruoyi/dfm/controller/DoeAnalysisController.java
index 3073667b5..ebce9f51b 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/dfm/controller/DoeAnalysisController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/dfm/controller/DoeAnalysisController.java
@@ -7,9 +7,11 @@ import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.http.HttpUtils;
+import com.ruoyi.dfm.service.DoeAnalysisService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
@@ -46,6 +48,9 @@ public class DoeAnalysisController extends BaseController {
@Value("${api.doe.Save}")
private String saveUrl;
+ @Autowired
+ DoeAnalysisService doeAnalysisService;
+
/**
* 获取分析页面
*
@@ -65,33 +70,22 @@ public class DoeAnalysisController extends BaseController {
@RequestMapping("/list")
@ResponseBody
public TableDataInfo list(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("dataType") String dataType) {
- String apiUrl = apiRootUrl;
- String param = "productname=" + productname +"&version=" + version;
+ JSONArray jsonArray = new JSONArray();
if(DATA_TYPE_KEY_PARAM.equals(dataType)) {
- apiUrl += getDataByKeyParamUrl;
+ jsonArray = doeAnalysisService.listByKeyParam(productname, version);
} else if(DATA_TYPE_REWORK.equals(dataType)) {
- apiUrl += getDataByReworkUrl;
+ jsonArray = doeAnalysisService.listByRework(productname, version);
}
- log.info("request remote api, url={}, param={}", apiUrl, param);
- String result = HttpUtils.sendGet(apiUrl, param);
- log.info("response remote api, url={}, param={}, result={}", apiUrl, param, result);
- JSONObject resultObj = JSON.parseObject(result);
- if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
- JSONArray data = resultObj.getJSONArray("data");
- return getDataTable(data);
- } else {
- log.error("reponse result failed. url={}, param={}, result={}", apiUrl, param, result);
- }
- return getDataTable(Collections.emptyList());
+ return getDataTable(jsonArray);
}
- @RequestMapping("/calculate")
+ @PostMapping("/calculate")
@ResponseBody
- public TableDataInfo calculate(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("dataType") String dataType) {
- String apiUrl = apiRootUrl + calculateUrl;
- String param = "";
+ public TableDataInfo calculate(String productname, String version, String quantity, String body) {
+ String apiUrl = apiRootUrl + calculateUrl + "?productname=" + productname + "&version=" + version + "&quantity=" + quantity;
+ String param = body;
log.info("request remote api, apiUrl={}, param={}", apiUrl, param);
- String result = HttpUtils.sendPost(apiUrl, param);
+ String result = HttpUtils.sendPost(apiUrl, JSON.parseArray(body));
log.info("response remote api, apiUrl={}, param={}, result={}", apiUrl, param, result);
JSONObject resultObj = JSON.parseObject(result);
if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
@@ -106,11 +100,10 @@ public class DoeAnalysisController extends BaseController {
@RequestMapping("/save")
@ResponseBody
- public AjaxResult save(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("dataType") String dataType) {
- String apiUrl = apiRootUrl + saveUrl;
- String param = "";
+ public AjaxResult save(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("body") String param) {
+ String apiUrl = apiRootUrl + saveUrl + "?productname=" + productname + "&version=" + version;
log.info("request remote api, apiUrl={}, param={}", apiUrl, param);
- String result = HttpUtils.sendPost(apiUrl, param);
+ String result = HttpUtils.sendPost(apiUrl, JSON.parseArray(param));
log.info("response remote api, apiUrl={}, param={}, result={}", apiUrl, param, result);
JSONObject resultObj = JSON.parseObject(result);
if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
diff --git a/ruoyi-admin/src/main/resources/templates/dfm/doeAnalysis.html b/ruoyi-admin/src/main/resources/templates/dfm/doeAnalysis.html
index b208785c0..773e4d47f 100644
--- a/ruoyi-admin/src/main/resources/templates/dfm/doeAnalysis.html
+++ b/ruoyi-admin/src/main/resources/templates/dfm/doeAnalysis.html
@@ -1,7 +1,7 @@
-
+
@@ -9,16 +9,16 @@
-
+
diff --git a/ruoyi-admin/src/main/resources/templates/index_dfm.html b/ruoyi-admin/src/main/resources/templates/index_dfm.html
index 864b3adac..e699ab387 100644
--- a/ruoyi-admin/src/main/resources/templates/index_dfm.html
+++ b/ruoyi-admin/src/main/resources/templates/index_dfm.html
@@ -244,7 +244,7 @@
th:src="@{/system/main}" frameborder="0" seamless>
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
index 7333ad3b8..e7aa8ea1b 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
@@ -1,10 +1,6 @@
package com.ruoyi.common.utils.http;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
+import java.io.*;
import java.net.*;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
@@ -13,9 +9,13 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
+
+import com.alibaba.fastjson.JSON;
+import com.ruoyi.common.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.constant.Constants;
+import org.springframework.web.client.RestTemplate;
/**
* 通用http发送方法
@@ -108,71 +108,80 @@ public class HttpUtils
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
- public static String sendPost(String url, String param)
+ public static String sendPost(String url, Object param)
{
- PrintWriter out = null;
- BufferedReader in = null;
- StringBuilder result = new StringBuilder();
- try
- {
- String urlNameString = url;
- log.info("sendPost - {}", urlNameString);
- URL realUrl = new URL(urlNameString);
- HttpURLConnection conn = (HttpURLConnection)realUrl.openConnection();
- conn.setRequestProperty("accept", "*/*");
- conn.setRequestProperty("connection", "Keep-Alive");
- conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
- conn.setRequestProperty("Accept-Charset", "utf-8");
- conn.setRequestProperty("contentType", "utf-8");
- conn.setRequestMethod("POST");
- conn.setDoOutput(true);
- conn.setDoInput(true);
- out = new PrintWriter(conn.getOutputStream());
- out.print(param);
- out.flush();
- in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
- String line;
- while ((line = in.readLine()) != null)
- {
- result.append(line);
- }
- log.info("recv - {}", result);
- }
- catch (ConnectException e)
- {
- log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
- }
- catch (SocketTimeoutException e)
- {
- log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
- }
- catch (IOException e)
- {
- log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
- }
- catch (Exception e)
- {
- log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
- }
- finally
- {
- try
- {
- if (out != null)
- {
- out.close();
- }
- if (in != null)
- {
- in.close();
- }
- }
- catch (IOException ex)
- {
- log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
- }
- }
- return result.toString();
+// PrintWriter out = null;
+// BufferedReader in = null;
+// StringBuilder result = new StringBuilder();
+// try
+// {
+// String urlNameString = url;
+// log.info("sendPost - {}", urlNameString);
+// URL realUrl = new URL(urlNameString);
+// HttpURLConnection conn = (HttpURLConnection)realUrl.openConnection();
+// conn.setRequestProperty("accept", "*/*");
+// conn.setRequestProperty("connection", "Keep-Alive");
+// conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+// conn.setRequestProperty("Accept-Charset", "utf-8");
+// conn.setRequestProperty("contentType", "utf-8");
+// conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+// conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接
+// conn.setRequestProperty("Charset", "UTF-8");
+// conn.setRequestMethod("POST");
+// conn.setDoOutput(true);
+// conn.setDoInput(true);
+// conn.setUseCaches(false);
+//
+// conn.connect();
+// out = new PrintWriter(conn.getOutputStream());
+// out.print(param);
+// out.flush();
+// in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
+// String line;
+// while ((line = in.readLine()) != null)
+// {
+// result.append(line);
+// }
+// log.info("recv - {}", result);
+// }
+// catch (ConnectException e)
+// {
+// log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
+// }
+// catch (SocketTimeoutException e)
+// {
+// log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
+// }
+// catch (IOException e)
+// {
+// log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
+// }
+// catch (Exception e)
+// {
+// log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
+// }
+// finally
+// {
+// try
+// {
+// if (out != null)
+// {
+// out.close();
+// }
+// if (in != null)
+// {
+// in.close();
+// }
+// }
+// catch (IOException ex)
+// {
+// log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
+// }
+// }
+// return result.toString();
+ RestTemplate restTemplate = new RestTemplate();
+ String result = restTemplate.postForObject(url, param, String.class);
+ return result;
}
public static String sendSSLPost(String url, String param)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/dfm/service/DoeAnalysisService.java b/ruoyi-system/src/main/java/com/ruoyi/dfm/service/DoeAnalysisService.java
new file mode 100644
index 000000000..4b3f756f5
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/dfm/service/DoeAnalysisService.java
@@ -0,0 +1,92 @@
+package com.ruoyi.dfm.service;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.http.HttpUtils;
+import com.ruoyi.dfm.dao.DataAnalysisDAO;
+import com.ruoyi.dfm.pojo.DataAnalysisBean;
+import com.ruoyi.dfm.pojo.UserInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.Collections;
+import java.util.List;
+
+@Component
+public class DoeAnalysisService {
+ private static final Logger log = LoggerFactory.getLogger(DoeAnalysisService.class);
+ private static final Integer SUCCESS_CODE = new Integer(20);
+
+ @Value("${api.root.url}")
+ protected String apiRootUrl;
+
+ @Value("${api.doe.GetDataByKeyParam}")
+ private String getDataByKeyParamUrl;
+
+ @Value("${api.doe.GetDataByRework}")
+ private String getDataByReworkUrl;
+
+ @Value("${api.doe.Calculate}")
+ private String calculateUrl;
+
+ @Value("${api.doe.Save}")
+ private String saveUrl;
+
+ public JSONArray listByKeyParam(String productname, String version){
+ String apiUrl = apiRootUrl + getDataByKeyParamUrl;
+ String param = "productname=" + productname +"&version=" + version;
+ log.info("request remote api, url={}, param={}", apiUrl, param);
+ String result = HttpUtils.sendGet(apiUrl, param);
+ log.info("response remote api, url={}, param={}, result={}", apiUrl, param, result);
+ JSONObject resultObj = JSON.parseObject(result);
+ if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
+ JSONArray data = resultObj.getJSONArray("data");
+ if(CollectionUtils.isEmpty(data)) {
+ return data;
+ }
+ JSONArray newJSONArray = new JSONArray(data.size());
+ for(Object obj : data) {
+ JSONObject jsonObj = ((JSONObject)obj);
+ String defecttypes = jsonObj.getString("defecttype");
+ if(StringUtils.isEmpty(defecttypes)) {
+ newJSONArray.add(obj);
+ } else {
+ String[] defecttypeArr = defecttypes.split(",");
+ for (String defecttype : defecttypeArr) {
+ JSONObject newObj = new JSONObject(jsonObj);
+ newObj.put("defecttype", defecttype);
+ newJSONArray.add(newObj);
+ }
+ }
+ }
+ return newJSONArray;
+ } else {
+ log.error("reponse result failed. url={}, param={}, result={}", apiUrl, param, result);
+ }
+ return new JSONArray();
+ }
+
+ public JSONArray listByRework(String productname, String version){
+ String apiUrl = apiRootUrl + getDataByReworkUrl;
+ String param = "productname=" + productname +"&version=" + version;
+ log.info("request remote api, url={}, param={}", apiUrl, param);
+ String result = HttpUtils.sendGet(apiUrl, param);
+ log.info("response remote api, url={}, param={}, result={}", apiUrl, param, result);
+ JSONObject resultObj = JSON.parseObject(result);
+ if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
+ JSONArray data = resultObj.getJSONArray("data");
+ return data;
+ } else {
+ log.error("reponse result failed. url={}, param={}, result={}", apiUrl, param, result);
+ }
+ return new JSONArray();
+ }
+
+}