|
|
@@ -11,6 +11,8 @@ import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Properties;
|
|
|
@@ -59,14 +61,21 @@ public class DataUtil {
|
|
|
String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&result="+ret+"&ucode="+user;
|
|
|
log.info("url="+url);
|
|
|
log.info("params="+params);
|
|
|
+ // 先落本地未提交记录,失败后可异步重试并在工作记录显示状态
|
|
|
+ JdbcUtils.ensurePendingSubmitRecord(oprno, sn, params);
|
|
|
String result = doPost(url,params);
|
|
|
log.info("result="+result);
|
|
|
|
|
|
- if(result.equalsIgnoreCase("false")) {
|
|
|
+ if(result == null || result.equalsIgnoreCase("false")) {
|
|
|
return null;
|
|
|
}else {
|
|
|
- JdbcUtils.insertData(oprno, "100000", params, "MQDW", sn);
|
|
|
- return JSONObject.parseObject(result);
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
+ if (obj != null && obj.get("result") != null
|
|
|
+ && obj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ JdbcUtils.markSubmitRecordSuccess(oprno, sn);
|
|
|
+ JdbcUtils.insertData(oprno, "100000", params, "MQDW", sn);
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.info("e="+e.getMessage());
|
|
|
@@ -74,6 +83,47 @@ public class DataUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 异步提交质量结果:主流程只落库排队后立即返回,HTTP 在后台线程执行,失败由定时器重试。
|
|
|
+ */
|
|
|
+ public static void submitQualityAsync(String sn, String oprno, String ret, String user) {
|
|
|
+ try {
|
|
|
+ String enconding = "UTF-8";
|
|
|
+ InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
|
|
|
+ Properties pro = new Properties();
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
|
|
|
+ pro.load(br);
|
|
|
+ String mes_server_ip = pro.getProperty("mes.server_ip");
|
|
|
+ String lineSn = pro.getProperty("mes.line_sn").trim();
|
|
|
+ final String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/pcresult";
|
|
|
+ final String params = "__ajax=json&oprno=" + oprno + "&lineSn=" + lineSn
|
|
|
+ + "&sn=" + sn + "&result=" + ret + "&ucode=" + user;
|
|
|
+ final String station = oprno;
|
|
|
+ final String productSn = sn;
|
|
|
+ JdbcUtils.ensurePendingSubmitRecord(station, productSn, params);
|
|
|
+ log.info("异步提交已入队: sn={}, oprno={}", productSn, station);
|
|
|
+ new Thread(() -> {
|
|
|
+ try {
|
|
|
+ String result = doPost(url, params);
|
|
|
+ log.info("异步提交结果 sn={}, result={}", productSn, result);
|
|
|
+ if (result == null || result.equalsIgnoreCase("false")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
+ if (obj != null && obj.get("result") != null
|
|
|
+ && obj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ JdbcUtils.markSubmitRecordSuccess(station, productSn);
|
|
|
+ JdbcUtils.insertData(station, "100000", params, "MQDW", productSn);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("异步提交异常 sn=" + productSn + ", " + e.getMessage());
|
|
|
+ }
|
|
|
+ }, "submit-quality-" + productSn).start();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("submitQualityAsync入队失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static JSONObject sendQuality(String sn,String oprno,String ret,String user,String ps){
|
|
|
try{
|
|
|
String enconding = "UTF-8";
|
|
|
@@ -87,14 +137,20 @@ public class DataUtil {
|
|
|
String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&sn="+sn+"&result="+ret+"&ucode="+user+"&ps="+ps;
|
|
|
log.info("url="+url);
|
|
|
log.info("params="+params);
|
|
|
+ JdbcUtils.ensurePendingSubmitRecord(oprno, sn, params);
|
|
|
String result = doPost(url,params);
|
|
|
log.info("result="+result);
|
|
|
|
|
|
- if(result.equalsIgnoreCase("false")) {
|
|
|
+ if(result == null || result.equalsIgnoreCase("false")) {
|
|
|
return null;
|
|
|
}else {
|
|
|
- JdbcUtils.insertData(oprno, "100000", params, "MQDW", sn);
|
|
|
- return JSONObject.parseObject(result);
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
+ if (obj != null && obj.get("result") != null
|
|
|
+ && obj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ JdbcUtils.markSubmitRecordSuccess(oprno, sn);
|
|
|
+ JdbcUtils.insertData(oprno, "100000", params, "MQDW", sn);
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.info("e="+e.getMessage());
|
|
|
@@ -102,6 +158,40 @@ public class DataUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 定时重试本地未提交的质量结果 */
|
|
|
+ public static void retryPendingSubmitRecords() {
|
|
|
+ try {
|
|
|
+ String enconding = "UTF-8";
|
|
|
+ InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
|
|
|
+ Properties pro = new Properties();
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
|
|
|
+ pro.load(br);
|
|
|
+ String mes_server_ip = pro.getProperty("mes.server_ip");
|
|
|
+ String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/pcresult";
|
|
|
+ List<ParamReq> pending = JdbcUtils.getPendingSubmitRecords();
|
|
|
+ for (ParamReq item : pending) {
|
|
|
+ String bw = item.getContent();
|
|
|
+ if (bw == null || bw.trim().isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ log.info("重试提交质量结果 id={}, sn={}, bw={}", item.getId(), item.getSn(), bw);
|
|
|
+ String result = doPost(url, bw);
|
|
|
+ if (result == null || result.equalsIgnoreCase("false")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
+ if (obj != null && obj.get("result") != null
|
|
|
+ && obj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ JdbcUtils.markSubmitRecordSuccessById(item.getId());
|
|
|
+ JdbcUtils.insertData(item.getOprno(), "100000", bw, "MQDW", item.getSn());
|
|
|
+ log.info("重试提交成功 id={}, sn={}", item.getId(), item.getSn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("retryPendingSubmitRecords异常: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static JSONObject createOrder(String oprno,String wsn1,String user){
|
|
|
try{
|
|
|
String enconding = "UTF-8";
|
|
|
@@ -272,20 +362,32 @@ public class DataUtil {
|
|
|
connection.setReadTimeout(15000);
|
|
|
connection.setDoOutput(true);
|
|
|
connection.setDoInput(true);
|
|
|
- connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
|
|
+ connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0");
|
|
|
os = connection.getOutputStream();
|
|
|
- os.write(param.getBytes());
|
|
|
- if (connection.getResponseCode() == 200) {
|
|
|
+ os.write(param.getBytes(StandardCharsets.UTF_8));
|
|
|
+ int responseCode = connection.getResponseCode();
|
|
|
+ if (responseCode == 200) {
|
|
|
is = connection.getInputStream();
|
|
|
- br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
|
|
+ br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
|
|
StringBuffer sbf = new StringBuffer();
|
|
|
String temp = null;
|
|
|
while ((temp = br.readLine()) != null) {
|
|
|
sbf.append(temp);
|
|
|
- sbf.append("\r\n");
|
|
|
}
|
|
|
result = sbf.toString();
|
|
|
+ } else {
|
|
|
+ log.error("doPost HTTP {} url={}", responseCode, httpUrl);
|
|
|
+ InputStream errStream = connection.getErrorStream();
|
|
|
+ if (errStream != null) {
|
|
|
+ br = new BufferedReader(new InputStreamReader(errStream, StandardCharsets.UTF_8));
|
|
|
+ StringBuffer sbf = new StringBuffer();
|
|
|
+ String temp;
|
|
|
+ while ((temp = br.readLine()) != null) {
|
|
|
+ sbf.append(temp);
|
|
|
+ }
|
|
|
+ log.error("doPost error body: {}", sbf.toString());
|
|
|
+ }
|
|
|
}
|
|
|
} catch (MalformedURLException e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -411,4 +513,96 @@ public class DataUtil {
|
|
|
|
|
|
return oprno;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定冷板/仓库物料码
|
|
|
+ */
|
|
|
+ public static JSONObject bindWarehouse(String sn, String wsn, String oprno, String userCode, String craft) {
|
|
|
+ try {
|
|
|
+ String mes_server_ip = MesClient.mes_server_ip;
|
|
|
+ String lineSn = MesClient.mes_line_sn;
|
|
|
+ if (mes_server_ip == null || mes_server_ip.isEmpty()) {
|
|
|
+ String enconding = "UTF-8";
|
|
|
+ InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
|
|
|
+ Properties pro = new Properties();
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
|
|
|
+ pro.load(br);
|
|
|
+ mes_server_ip = pro.getProperty("mes.server_ip");
|
|
|
+ lineSn = pro.getProperty("mes.line_sn").trim();
|
|
|
+ }
|
|
|
+ String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/bindWarehouse";
|
|
|
+ String params = "__ajax=json"
|
|
|
+ + "&oprno=" + URLEncoder.encode(oprno != null ? oprno : "", "UTF-8")
|
|
|
+ + "&lineSn=" + URLEncoder.encode(lineSn != null ? lineSn : "", "UTF-8")
|
|
|
+ + "&ucode=" + URLEncoder.encode(userCode != null ? userCode : "", "UTF-8")
|
|
|
+ + "&sn=" + URLEncoder.encode(sn != null ? sn : "", "UTF-8")
|
|
|
+ + "&wsn=" + URLEncoder.encode(wsn != null ? wsn : "", "UTF-8")
|
|
|
+ + "&craft=" + URLEncoder.encode(craft != null ? craft : "", "UTF-8");
|
|
|
+ if (MesClient.sessionid != null && !MesClient.sessionid.isEmpty()) {
|
|
|
+ params += "&__sid=" + URLEncoder.encode(MesClient.sessionid, "UTF-8");
|
|
|
+ }
|
|
|
+ log.info("bindWarehouse url=" + url);
|
|
|
+ log.info("bindWarehouse params=" + params);
|
|
|
+ String result = doPost(url, params);
|
|
|
+ log.info("bindWarehouse result=" + result);
|
|
|
+ if (result == null || result.trim().isEmpty() || result.equalsIgnoreCase("false")) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONObject retObj = JSONObject.parseObject(result);
|
|
|
+ if (retObj != null && retObj.get("result") != null
|
|
|
+ && retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ JdbcUtils.insertData(oprno, craft, params, "MBDW", sn);
|
|
|
+ }
|
|
|
+ return retObj;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("bindWarehouse error: " + e.getMessage(), e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解绑冷板/仓库物料码
|
|
|
+ */
|
|
|
+ public static JSONObject unBindWarehouse(String sn, String wsn, String oprno, String userCode, String craft) {
|
|
|
+ try {
|
|
|
+ String mes_server_ip = MesClient.mes_server_ip;
|
|
|
+ String lineSn = MesClient.mes_line_sn;
|
|
|
+ if (mes_server_ip == null || mes_server_ip.isEmpty()) {
|
|
|
+ String enconding = "UTF-8";
|
|
|
+ InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
|
|
|
+ Properties pro = new Properties();
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
|
|
|
+ pro.load(br);
|
|
|
+ mes_server_ip = pro.getProperty("mes.server_ip");
|
|
|
+ lineSn = pro.getProperty("mes.line_sn").trim();
|
|
|
+ }
|
|
|
+ String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/unBindWarehouse";
|
|
|
+ String params = "__ajax=json"
|
|
|
+ + "&oprno=" + URLEncoder.encode(oprno != null ? oprno : "", "UTF-8")
|
|
|
+ + "&lineSn=" + URLEncoder.encode(lineSn != null ? lineSn : "", "UTF-8")
|
|
|
+ + "&ucode=" + URLEncoder.encode(userCode != null ? userCode : "", "UTF-8")
|
|
|
+ + "&sn=" + URLEncoder.encode(sn != null ? sn : "", "UTF-8")
|
|
|
+ + "&wsn=" + URLEncoder.encode(wsn != null ? wsn : "", "UTF-8")
|
|
|
+ + "&craft=" + URLEncoder.encode(craft != null ? craft : "", "UTF-8");
|
|
|
+ if (MesClient.sessionid != null && !MesClient.sessionid.isEmpty()) {
|
|
|
+ params += "&__sid=" + URLEncoder.encode(MesClient.sessionid, "UTF-8");
|
|
|
+ }
|
|
|
+ log.info("unBindWarehouse url=" + url);
|
|
|
+ log.info("unBindWarehouse params=" + params);
|
|
|
+ String result = doPost(url, params);
|
|
|
+ log.info("unBindWarehouse result=" + result);
|
|
|
+ if (result == null || result.trim().isEmpty() || result.equalsIgnoreCase("false")) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONObject retObj = JSONObject.parseObject(result);
|
|
|
+ if (retObj != null && retObj.get("result") != null
|
|
|
+ && retObj.get("result").toString().equalsIgnoreCase("true")) {
|
|
|
+ JdbcUtils.insertData(oprno, craft, params, "MJBW", sn);
|
|
|
+ }
|
|
|
+ return retObj;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("unBindWarehouse error: " + e.getMessage(), e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|