|
|
@@ -1,12 +1,16 @@
|
|
|
package com.mes.util;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.mes.ui.MesClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Properties;
|
|
|
|
|
|
public class IweldCloudUtil {
|
|
|
@@ -15,6 +19,16 @@ public class IweldCloudUtil {
|
|
|
private static volatile String sessionKey = "";
|
|
|
private static volatile String robotRunInfo = "";
|
|
|
|
|
|
+ public static class WelderParams {
|
|
|
+ public String voltage = "";
|
|
|
+ public String current = "";
|
|
|
+ public String wireSpeed = "";
|
|
|
+
|
|
|
+ public boolean hasData() {
|
|
|
+ return !voltage.isEmpty() || !current.isEmpty() || !wireSpeed.isEmpty();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static String getSessionKey() {
|
|
|
return sessionKey;
|
|
|
}
|
|
|
@@ -80,7 +94,6 @@ public class IweldCloudUtil {
|
|
|
}
|
|
|
|
|
|
robotRunInfo = response;
|
|
|
- System.out.println("IweldCloud getRobotRunInfo: " + response);
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
log.error("IweldCloud getRobotRunInfo error", e);
|
|
|
@@ -88,6 +101,134 @@ public class IweldCloudUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 焊接运行中从 IweldCloud 采集焊机参数,更新界面并写入本地缓存。
|
|
|
+ */
|
|
|
+ public static void collectWeldingParams() {
|
|
|
+ if (MesClient.tjFlaga != 2 && MesClient.tjFlagb != 2) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (sessionKey == null || sessionKey.isEmpty()) {
|
|
|
+ login();
|
|
|
+ }
|
|
|
+ if (!fetchRobotRunInfo()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ WelderParams[] welders = parseWelderParamsFromResponse(robotRunInfo);
|
|
|
+ welders = mergeSecondProdCode(welders);
|
|
|
+ if (welders == null || (!welders[0].hasData() && !welders[1].hasData())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ MesClient.param1.setText(welders[0].voltage);
|
|
|
+ MesClient.param2.setText(welders[0].current);
|
|
|
+ MesClient.param3.setText(welders[0].wireSpeed);
|
|
|
+ MesClient.param21.setText(welders[1].voltage);
|
|
|
+ MesClient.param22.setText(welders[1].current);
|
|
|
+ MesClient.param23.setText(welders[1].wireSpeed);
|
|
|
+
|
|
|
+ String recordTime = DateLocalUtils.getCurrentTime();
|
|
|
+ MesClient.hjparams.add(
|
|
|
+ welders[0].voltage + "|" + welders[0].current + "|" + welders[0].wireSpeed + "|" + "" + "|" + "" + "|"
|
|
|
+ + welders[1].voltage + "|" + welders[1].current + "|" + welders[1].wireSpeed + "|" + "" + "|" + "" + "|"
|
|
|
+ + recordTime
|
|
|
+ );
|
|
|
+
|
|
|
+ if (MesClient.hjparams.size() == 60) {
|
|
|
+ try {
|
|
|
+ String oprno = buildOprno();
|
|
|
+ if (MesClient.curFlag.equals("A")) {
|
|
|
+ JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, MesClient.product_sn.getText(), JSON.toJSONString(MesClient.hjparams));
|
|
|
+ } else {
|
|
|
+ JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, MesClient.product_sn2.getText(), JSON.toJSONString(MesClient.hjparams));
|
|
|
+ }
|
|
|
+ MesClient.hjparams = new ArrayList<>();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static WelderParams[] parseWelderParamsFromResponse(String response) {
|
|
|
+ if (response == null || response.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ JSONObject json = JSONObject.parseObject(response);
|
|
|
+ JSONArray dataList = json.getJSONArray("dataList");
|
|
|
+ if (dataList == null || dataList.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ WelderParams[] welders = new WelderParams[2];
|
|
|
+ welders[0] = parseWelderItem(dataList.getJSONObject(0));
|
|
|
+ if (dataList.size() > 1) {
|
|
|
+ welders[1] = parseWelderItem(dataList.getJSONObject(1));
|
|
|
+ } else {
|
|
|
+ welders[1] = new WelderParams();
|
|
|
+ }
|
|
|
+ return welders;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("IweldCloud parse welder params error", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static WelderParams parseWelderItem(JSONObject item) {
|
|
|
+ WelderParams params = new WelderParams();
|
|
|
+ if (item == null) {
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+ params.voltage = readField(item,
|
|
|
+ "weldingVoltage", "voltage", "vol", "v_meas", "actualVoltage", "actualVol", "U", "dy", "voltageValue");
|
|
|
+ params.current = readField(item,
|
|
|
+ "weldingCurrent", "current", "cur", "c_meas", "actualCurrent", "actualCur", "I", "dl", "currentValue", "electricity");
|
|
|
+ params.wireSpeed = readField(item,
|
|
|
+ "wireFeedSpeed", "wireSpeed", "feedingSpeed", "f_meas", "speed", "ss", "feedSpeed", "wireFeed", "feeding");
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String readField(JSONObject item, String... keys) {
|
|
|
+ for (String key : keys) {
|
|
|
+ if (item.containsKey(key) && item.get(key) != null) {
|
|
|
+ return String.valueOf(item.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static WelderParams[] mergeSecondProdCode(WelderParams[] welders) {
|
|
|
+ try {
|
|
|
+ Properties pro = loadConfig();
|
|
|
+ String prodCode2 = pro.getProperty("iweld.prodCode2", "").trim();
|
|
|
+ if (prodCode2.isEmpty()) {
|
|
|
+ return welders;
|
|
|
+ }
|
|
|
+ if (welders == null) {
|
|
|
+ welders = new WelderParams[]{new WelderParams(), new WelderParams()};
|
|
|
+ }
|
|
|
+ String baseUrl = pro.getProperty("iweld.robot.run.info.url",
|
|
|
+ "https://api.iweldcloud.com/ApiServer/rest/WeldWebService/getRobotRunInfo").trim();
|
|
|
+ String response = HttpUtils.sendGetRequestWithHeader(baseUrl + "?prodCode=" + prodCode2, "app-token", sessionKey);
|
|
|
+ WelderParams[] second = parseWelderParamsFromResponse(response);
|
|
|
+ if (second != null && second[0].hasData()) {
|
|
|
+ welders[1] = second[0];
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("IweldCloud fetch second prodCode error", e);
|
|
|
+ }
|
|
|
+ return welders;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String buildOprno() {
|
|
|
+ String side = MesClient.curFlag.equals("A") ? "A" : "B";
|
|
|
+ if (MesClient.mes_gwflag.equals("B")) {
|
|
|
+ side = MesClient.curFlag.equals("A") ? "C" : "D";
|
|
|
+ }
|
|
|
+ return MesClient.mes_gw + side;
|
|
|
+ }
|
|
|
+
|
|
|
private static Properties loadConfig() throws Exception {
|
|
|
Properties pro = new Properties();
|
|
|
InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
|