From 063098e0c336e54dd689e0acfab9f4054a142791 Mon Sep 17 00:00:00 2001 From: kingsfighter Date: Sat, 19 Sep 2020 09:43:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90DOE=E5=88=86=E6=9E=90?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dfm/controller/DoeAnalysisController.java | 41 ++-- .../resources/templates/dfm/doeAnalysis.html | 203 +++++++++++++++--- .../src/main/resources/templates/index.html | 2 +- .../main/resources/templates/index_dfm.html | 2 +- .../ruoyi/common/utils/http/HttpUtils.java | 147 +++++++------ .../ruoyi/dfm/service/DoeAnalysisService.java | 92 ++++++++ 6 files changed, 364 insertions(+), 123 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/dfm/service/DoeAnalysisService.java 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 @@
-
+
  • - 板名: + 板名:
  • - 版本: + 版本:
  • 筛选: @@ -35,12 +35,12 @@
-
- -
+
+
- +
+
@@ -57,10 +57,9 @@
-
-
+
+
-
@@ -68,11 +67,15 @@ var prefix = ctx + "doeAnalysis.do"; //当前表格检索结果,使用的dataType var currentDataType = ""; + var currentProductName = ""; + var currentVersion = ""; $(document).ready(function(){ initKeyParamTable(); initReworkTable(); $("#search-result-rework-table").hide(); + initCalculateResultTable(); + $("#calculate-result-table").hide(); }); function initKeyParamTable() { @@ -84,6 +87,14 @@ { checkbox: true }, + { + field: 'index', + title: '序号', + sortable: false, + formatter: function (value, row, index) { + return index + 1; + } + }, { field: 'keyparamtype', title: '规则名', @@ -127,28 +138,14 @@ { field: 'defecttype', title: '维修类型关联', - sortable: false, - formatter: function (value, row, index) { - var html=""; - html += ""; - return html; - } + sortable: false } ] }; - $.table.init(options); $("#search-result-keyparam-table").bootstrapTable(options); } - function initReworkTable() { var options = { sortName: "roleSort", @@ -158,6 +155,14 @@ { checkbox: true }, + { + field: 'index', + title: '序号', + sortable: false, + formatter: function (value, row, index) { + return index + 1; + } + }, { field: 'refdes', title: '位号', @@ -190,8 +195,6 @@ } ] }; - $.table.init(options); - $("#search-result-rework-table").bootstrapTable(options); } @@ -216,6 +219,8 @@ $("#search-result-table").html(""); var dataType = $("#dataType").val(); currentDataType = dataType; + currentProductName = $("#productname").val(); + currentVersion = $("#version").val(); if("keyParam"== dataType) { fillKeyParamTable(json); $("#search-result-rework-table").hide(); @@ -230,11 +235,153 @@ } function doeCalculate() { + var quantity = $("#quantity").val(); + if($.trim(quantity) == "") { + $.modal.alertError("请填写计算数量!"); + return; + } + var data; + if("keyParam"== currentDataType) { + data = $('#search-result-keyparam-table').bootstrapTable('getAllSelections'); + } else { + data = $('#search-result-rework-table').bootstrapTable('getAllSelections'); + } + if(data.length <= 0) { + $.modal.alertError("请选择需要计算的数据!"); + return; + } + var newData = new Array(); + for (var i = 0; i < data.length; i++) { + var newObj = { + Keyparamtype: data[i].keyparamtype, + Refdes: data[i].refdes, + Defecttype: data[i].defecttype + }; + newData.push(newObj); + } + var param = { + quantity: $("#quantity").val(), + productname : currentProductName, + version: currentVersion, + body: JSON.stringify(newData) + }; + + // var arr = [{ + // "Keyparamtype":"7", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"LX(连锡)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"9", + // "Defecttype":"LX(连锡)" + // },{ + // "Keyparamtype":"9", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"9", + // "Defecttype":"JH(假焊)" + // },{ + // "Keyparamtype":"7", + // "Defecttype":"LX(连锡)" + // }]; + // + // var param = { + // quantity: 10000, + // productname : '130000161095AJB', + // version: '160500', + // body: JSON.stringify(arr) + // }; + $.ajax({ + url: prefix + "/calculate", + data: param, + type: 'post', + cache:false, + dataType:"json", + success: function(json){ + $("#calculate-result-table").bootstrapTable('load', json); + $("#calculate-result-table").show(); + } + }); + } + + + function initCalculateResultTable() { + var options = { + sortName: "roleSort", + pagination: false, + modalName: "DOE分析-计算结果", + columns: [ + { + field: 'index', + title: '序号', + sortable: false, + formatter: function (value, row, index) { + return index + 1; + } + }, + { + field: 'DataType', + title: '规则名', + sortable: false + }, + { + field: 'DataValue', + title: 'DPPM值影响', + sortable: false + } + ] + }; + $("#calculate-result-table").bootstrapTable(options); + $("#calculate-result-table").show(); } function doeSave() { + //获取所有数据 + var rows = $('#calculate-result-table').bootstrapTable('getData',{useCurrentPage:true,includeHiddenRows:true}); + if(rows.length <= 0) { + $.modal.alertError("请先计算出结果,再保存数据"); + return; + } + var param = { + productname : currentProductName, + version: currentVersion, + body: JSON.stringify(rows) + }; + $.ajax({ + url: prefix + "/save", + data: param, + type: 'post', + cache:false, + dataType:"json", + success: function(json){ + if(null == json || 0 != json.code) { + $.modal.alertSuccess("结果入库失败!"); + } else { + $.modal.alertSuccess("结果入库成功!"); + } + } + }); } diff --git a/ruoyi-admin/src/main/resources/templates/index.html b/ruoyi-admin/src/main/resources/templates/index.html index 7e868c851..49e0f7374 100644 --- a/ruoyi-admin/src/main/resources/templates/index.html +++ b/ruoyi-admin/src/main/resources/templates/index.html @@ -236,7 +236,7 @@ th:src="@{/system/main}" frameborder="0" seamless>
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(); + } + +}