完成DOE分析功能
This commit is contained in:
parent
22a4436964
commit
063098e0c3
|
|
@ -7,9 +7,11 @@ import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.utils.http.HttpUtils;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
||||||
|
import com.ruoyi.dfm.service.DoeAnalysisService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
|
|
@ -46,6 +48,9 @@ public class DoeAnalysisController extends BaseController {
|
||||||
@Value("${api.doe.Save}")
|
@Value("${api.doe.Save}")
|
||||||
private String saveUrl;
|
private String saveUrl;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
DoeAnalysisService doeAnalysisService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取分析页面
|
* 获取分析页面
|
||||||
*
|
*
|
||||||
|
|
@ -65,33 +70,22 @@ public class DoeAnalysisController extends BaseController {
|
||||||
@RequestMapping("/list")
|
@RequestMapping("/list")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TableDataInfo list(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("dataType") String dataType) {
|
public TableDataInfo list(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("dataType") String dataType) {
|
||||||
String apiUrl = apiRootUrl;
|
JSONArray jsonArray = new JSONArray();
|
||||||
String param = "productname=" + productname +"&version=" + version;
|
|
||||||
if(DATA_TYPE_KEY_PARAM.equals(dataType)) {
|
if(DATA_TYPE_KEY_PARAM.equals(dataType)) {
|
||||||
apiUrl += getDataByKeyParamUrl;
|
jsonArray = doeAnalysisService.listByKeyParam(productname, version);
|
||||||
} else if(DATA_TYPE_REWORK.equals(dataType)) {
|
} else if(DATA_TYPE_REWORK.equals(dataType)) {
|
||||||
apiUrl += getDataByReworkUrl;
|
jsonArray = doeAnalysisService.listByRework(productname, version);
|
||||||
}
|
}
|
||||||
log.info("request remote api, url={}, param={}", apiUrl, param);
|
return getDataTable(jsonArray);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/calculate")
|
@PostMapping("/calculate")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TableDataInfo calculate(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("dataType") String dataType) {
|
public TableDataInfo calculate(String productname, String version, String quantity, String body) {
|
||||||
String apiUrl = apiRootUrl + calculateUrl;
|
String apiUrl = apiRootUrl + calculateUrl + "?productname=" + productname + "&version=" + version + "&quantity=" + quantity;
|
||||||
String param = "";
|
String param = body;
|
||||||
log.info("request remote api, apiUrl={}, param={}", apiUrl, param);
|
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);
|
log.info("response remote api, apiUrl={}, param={}, result={}", apiUrl, param, result);
|
||||||
JSONObject resultObj = JSON.parseObject(result);
|
JSONObject resultObj = JSON.parseObject(result);
|
||||||
if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
|
if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
|
||||||
|
|
@ -106,11 +100,10 @@ public class DoeAnalysisController extends BaseController {
|
||||||
|
|
||||||
@RequestMapping("/save")
|
@RequestMapping("/save")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult save(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("dataType") String dataType) {
|
public AjaxResult save(@RequestParam("productname") String productname, @RequestParam("version") String version, @RequestParam("body") String param) {
|
||||||
String apiUrl = apiRootUrl + saveUrl;
|
String apiUrl = apiRootUrl + saveUrl + "?productname=" + productname + "&version=" + version;
|
||||||
String param = "";
|
|
||||||
log.info("request remote api, apiUrl={}, param={}", apiUrl, param);
|
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);
|
log.info("response remote api, apiUrl={}, param={}, result={}", apiUrl, param, result);
|
||||||
JSONObject resultObj = JSON.parseObject(result);
|
JSONObject resultObj = JSON.parseObject(result);
|
||||||
if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
|
if(null != resultObj && SUCCESS_CODE.equals(resultObj.getInteger("code"))) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
|
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
|
||||||
<head>
|
<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">-->
|
<!--<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>-->
|
<!--<script src="https://unpkg.com/bootstrap-table@1.17.1/dist/bootstrap-table.min.js"></script>-->
|
||||||
|
|
@ -9,16 +9,16 @@
|
||||||
</head>
|
</head>
|
||||||
<body class="gray-bg">
|
<body class="gray-bg">
|
||||||
<div class="container-div">
|
<div class="container-div">
|
||||||
<div class="row">
|
<div class="row" style="height: 50%;">
|
||||||
<div class="col-sm-12 search-collapse">
|
<div class="col-sm-12 search-collapse">
|
||||||
<form id="search-form">
|
<form id="search-form">
|
||||||
<div class="select-list">
|
<div class="select-list">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
板名:<input type="text" name="productname" required/>
|
板名:<input type="text" name="productname" id="productname" required/>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
版本:<input type="text" name="version" required/>
|
版本:<input type="text" name="version" id="version" required/>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
筛选:
|
筛选:
|
||||||
|
|
@ -35,12 +35,12 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="search-result-div" class="col-sm-12 select-table table-striped" style="overflow: scroll;height: 300px;">
|
<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 id="search-result-keyparam-table"></table>
|
||||||
</table>
|
|
||||||
<table id="search-result-rework-table" style="display: none"></table>
|
<table id="search-result-rework-table" style="display: none"></table>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row" style="height: 50%;">
|
||||||
<div class="col-sm-12 search-collapse">
|
<div class="col-sm-12 search-collapse">
|
||||||
<form id="calculate-form">
|
<form id="calculate-form">
|
||||||
<div class="select-list">
|
<div class="select-list">
|
||||||
|
|
@ -57,10 +57,9 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="calculate-result-div" class="col-sm-12 select-table table-striped" style="overflow: scroll;height: 200px;">
|
<div id="calculate-result-div" class="col-sm-12 select-table table-striped" style="overflow: scroll;height:80%;">
|
||||||
<table id="calculate-result-table"></table>
|
<table id="calculate-result-table" style="display: none"></table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<th:block th:include="include :: footer" />
|
<th:block th:include="include :: footer" />
|
||||||
|
|
@ -68,11 +67,15 @@
|
||||||
var prefix = ctx + "doeAnalysis.do";
|
var prefix = ctx + "doeAnalysis.do";
|
||||||
//当前表格检索结果,使用的dataType
|
//当前表格检索结果,使用的dataType
|
||||||
var currentDataType = "";
|
var currentDataType = "";
|
||||||
|
var currentProductName = "";
|
||||||
|
var currentVersion = "";
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
initKeyParamTable();
|
initKeyParamTable();
|
||||||
initReworkTable();
|
initReworkTable();
|
||||||
$("#search-result-rework-table").hide();
|
$("#search-result-rework-table").hide();
|
||||||
|
initCalculateResultTable();
|
||||||
|
$("#calculate-result-table").hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
function initKeyParamTable() {
|
function initKeyParamTable() {
|
||||||
|
|
@ -84,6 +87,14 @@
|
||||||
{
|
{
|
||||||
checkbox: true
|
checkbox: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: 'index',
|
||||||
|
title: '序号',
|
||||||
|
sortable: false,
|
||||||
|
formatter: function (value, row, index) {
|
||||||
|
return index + 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
field: 'keyparamtype',
|
field: 'keyparamtype',
|
||||||
title: '规则名',
|
title: '规则名',
|
||||||
|
|
@ -127,28 +138,14 @@
|
||||||
{
|
{
|
||||||
field: 'defecttype',
|
field: 'defecttype',
|
||||||
title: '维修类型关联',
|
title: '维修类型关联',
|
||||||
sortable: false,
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
$.table.init(options);
|
|
||||||
$("#search-result-keyparam-table").bootstrapTable(options);
|
$("#search-result-keyparam-table").bootstrapTable(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function initReworkTable() {
|
function initReworkTable() {
|
||||||
var options = {
|
var options = {
|
||||||
sortName: "roleSort",
|
sortName: "roleSort",
|
||||||
|
|
@ -158,6 +155,14 @@
|
||||||
{
|
{
|
||||||
checkbox: true
|
checkbox: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: 'index',
|
||||||
|
title: '序号',
|
||||||
|
sortable: false,
|
||||||
|
formatter: function (value, row, index) {
|
||||||
|
return index + 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
field: 'refdes',
|
field: 'refdes',
|
||||||
title: '位号',
|
title: '位号',
|
||||||
|
|
@ -190,8 +195,6 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
$.table.init(options);
|
|
||||||
|
|
||||||
$("#search-result-rework-table").bootstrapTable(options);
|
$("#search-result-rework-table").bootstrapTable(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,6 +219,8 @@
|
||||||
$("#search-result-table").html("");
|
$("#search-result-table").html("");
|
||||||
var dataType = $("#dataType").val();
|
var dataType = $("#dataType").val();
|
||||||
currentDataType = dataType;
|
currentDataType = dataType;
|
||||||
|
currentProductName = $("#productname").val();
|
||||||
|
currentVersion = $("#version").val();
|
||||||
if("keyParam"== dataType) {
|
if("keyParam"== dataType) {
|
||||||
fillKeyParamTable(json);
|
fillKeyParamTable(json);
|
||||||
$("#search-result-rework-table").hide();
|
$("#search-result-rework-table").hide();
|
||||||
|
|
@ -230,11 +235,153 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function doeCalculate() {
|
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() {
|
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("结果入库成功!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@
|
||||||
th:src="@{/system/main}" frameborder="0" seamless></iframe>
|
th:src="@{/system/main}" frameborder="0" seamless></iframe>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>
|
<!--<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--右侧部分结束-->
|
<!--右侧部分结束-->
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@
|
||||||
th:src="@{/system/main}" frameborder="0" seamless></iframe>
|
th:src="@{/system/main}" frameborder="0" seamless></iframe>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>
|
<!--<div class="pull-right">© [[${copyrightYear}]] RuoYi Copyright </div>-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--右侧部分结束-->
|
<!--右侧部分结束-->
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,6 @@
|
||||||
package com.ruoyi.common.utils.http;
|
package com.ruoyi.common.utils.http;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
|
@ -13,9 +9,13 @@ import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.ruoyi.common.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用http发送方法
|
* 通用http发送方法
|
||||||
|
|
@ -108,71 +108,80 @@ public class HttpUtils
|
||||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||||
* @return 所代表远程资源的响应结果
|
* @return 所代表远程资源的响应结果
|
||||||
*/
|
*/
|
||||||
public static String sendPost(String url, String param)
|
public static String sendPost(String url, Object param)
|
||||||
{
|
{
|
||||||
PrintWriter out = null;
|
// PrintWriter out = null;
|
||||||
BufferedReader in = null;
|
// BufferedReader in = null;
|
||||||
StringBuilder result = new StringBuilder();
|
// StringBuilder result = new StringBuilder();
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
String urlNameString = url;
|
// String urlNameString = url;
|
||||||
log.info("sendPost - {}", urlNameString);
|
// log.info("sendPost - {}", urlNameString);
|
||||||
URL realUrl = new URL(urlNameString);
|
// URL realUrl = new URL(urlNameString);
|
||||||
HttpURLConnection conn = (HttpURLConnection)realUrl.openConnection();
|
// HttpURLConnection conn = (HttpURLConnection)realUrl.openConnection();
|
||||||
conn.setRequestProperty("accept", "*/*");
|
// conn.setRequestProperty("accept", "*/*");
|
||||||
conn.setRequestProperty("connection", "Keep-Alive");
|
// conn.setRequestProperty("connection", "Keep-Alive");
|
||||||
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
// conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||||
conn.setRequestProperty("Accept-Charset", "utf-8");
|
// conn.setRequestProperty("Accept-Charset", "utf-8");
|
||||||
conn.setRequestProperty("contentType", "utf-8");
|
// conn.setRequestProperty("contentType", "utf-8");
|
||||||
conn.setRequestMethod("POST");
|
// conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||||
conn.setDoOutput(true);
|
// conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接
|
||||||
conn.setDoInput(true);
|
// conn.setRequestProperty("Charset", "UTF-8");
|
||||||
out = new PrintWriter(conn.getOutputStream());
|
// conn.setRequestMethod("POST");
|
||||||
out.print(param);
|
// conn.setDoOutput(true);
|
||||||
out.flush();
|
// conn.setDoInput(true);
|
||||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
|
// conn.setUseCaches(false);
|
||||||
String line;
|
//
|
||||||
while ((line = in.readLine()) != null)
|
// conn.connect();
|
||||||
{
|
// out = new PrintWriter(conn.getOutputStream());
|
||||||
result.append(line);
|
// out.print(param);
|
||||||
}
|
// out.flush();
|
||||||
log.info("recv - {}", result);
|
// in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
|
||||||
}
|
// String line;
|
||||||
catch (ConnectException e)
|
// while ((line = in.readLine()) != null)
|
||||||
{
|
// {
|
||||||
log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
|
// result.append(line);
|
||||||
}
|
// }
|
||||||
catch (SocketTimeoutException e)
|
// log.info("recv - {}", result);
|
||||||
{
|
// }
|
||||||
log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
|
// catch (ConnectException e)
|
||||||
}
|
// {
|
||||||
catch (IOException e)
|
// log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
|
||||||
{
|
// }
|
||||||
log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
|
// catch (SocketTimeoutException e)
|
||||||
}
|
// {
|
||||||
catch (Exception e)
|
// log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
|
||||||
{
|
// }
|
||||||
log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
|
// catch (IOException e)
|
||||||
}
|
// {
|
||||||
finally
|
// log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
|
||||||
{
|
// }
|
||||||
try
|
// catch (Exception e)
|
||||||
{
|
// {
|
||||||
if (out != null)
|
// log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
|
||||||
{
|
// }
|
||||||
out.close();
|
// finally
|
||||||
}
|
// {
|
||||||
if (in != null)
|
// try
|
||||||
{
|
// {
|
||||||
in.close();
|
// if (out != null)
|
||||||
}
|
// {
|
||||||
}
|
// out.close();
|
||||||
catch (IOException ex)
|
// }
|
||||||
{
|
// if (in != null)
|
||||||
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
|
// {
|
||||||
}
|
// in.close();
|
||||||
}
|
// }
|
||||||
return result.toString();
|
// }
|
||||||
|
// 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)
|
public static String sendSSLPost(String url, String param)
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue