完成DOE分析功能

This commit is contained in:
kingsfighter 2020-09-19 09:43:18 +08:00
parent 22a4436964
commit 063098e0c3
6 changed files with 364 additions and 123 deletions

View File

@ -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"))) {

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('用户列表')" />
<th:block th:include="include :: header('DOE分析')" />
<!--<link href="https://unpkg.com/bootstrap-table@1.17.1/dist/bootstrap-table.min.css" rel="stylesheet">-->
<!--<script src="https://unpkg.com/bootstrap-table@1.17.1/dist/bootstrap-table.min.js"></script>-->
@ -9,16 +9,16 @@
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="row" style="height: 50%;">
<div class="col-sm-12 search-collapse">
<form id="search-form">
<div class="select-list">
<ul>
<li>
板名:<input type="text" name="productname" required/>
板名:<input type="text" name="productname" id="productname" required/>
</li>
<li>
版本:<input type="text" name="version" required/>
版本:<input type="text" name="version" id="version" required/>
</li>
<li>
筛选:
@ -35,12 +35,12 @@
</form>
</div>
<div id="search-result-div" class="col-sm-12 select-table table-striped" style="overflow: scroll;height: 300px;">
<table id="search-result-keyparam-table">
</table>
<div id="search-result-div" class="col-sm-12 select-table table-striped" style="overflow: scroll;height:90%;">
<table id="search-result-keyparam-table"></table>
<table id="search-result-rework-table" style="display: none"></table>
</div>
</div>
<div class="row" style="height: 50%;">
<div class="col-sm-12 search-collapse">
<form id="calculate-form">
<div class="select-list">
@ -57,10 +57,9 @@
</form>
</div>
<div id="calculate-result-div" class="col-sm-12 select-table table-striped" style="overflow: scroll;height: 200px;">
<table id="calculate-result-table"></table>
<div id="calculate-result-div" class="col-sm-12 select-table table-striped" style="overflow: scroll;height:80%;">
<table id="calculate-result-table" style="display: none"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
@ -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 += "<select name=\"status\" class=\"form-control m-b\" multiple>";
if($.trim(value) != "") {
var defecttypes = value.split(",");
for (var i = 0; i < defecttypes.length; i++) {
html += "<option value=\""+defecttypes[i]+"\">"+defecttypes[i]+"</option>";
}
}
html += "</select>";
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("结果入库成功!");
}
}
});
}

View File

@ -236,7 +236,7 @@
th:src="@{/system/main}" frameborder="0" seamless></iframe>
</div>
<div class="footer">
<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>
<!--<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>-->
</div>
</div>
<!--右侧部分结束-->

View File

@ -244,7 +244,7 @@
th:src="@{/system/main}" frameborder="0" seamless></iframe>
</div>
<div class="footer">
<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>
<!--<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>-->
</div>
</div>
<!--右侧部分结束-->

View File

@ -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)

View File

@ -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();
}
}