|
@@ -71,6 +71,7 @@ public class IweldCloudUtil {
|
|
|
String loginUrl = pro.getProperty("iweld.login.url", DEFAULT_LOGIN_URL).trim();
|
|
String loginUrl = pro.getProperty("iweld.login.url", DEFAULT_LOGIN_URL).trim();
|
|
|
if (accessKey.isEmpty()) {
|
|
if (accessKey.isEmpty()) {
|
|
|
log.warn("IweldCloud login skipped: iweld.accessKey is empty");
|
|
log.warn("IweldCloud login skipped: iweld.accessKey is empty");
|
|
|
|
|
+ sessionKey = "";
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -79,6 +80,7 @@ public class IweldCloudUtil {
|
|
|
String response = HttpUtils.sendPostRequestJson(loginUrl, body.toJSONString());
|
|
String response = HttpUtils.sendPostRequestJson(loginUrl, body.toJSONString());
|
|
|
if (response == null || response.isEmpty() || "false".equalsIgnoreCase(response)) {
|
|
if (response == null || response.isEmpty() || "false".equalsIgnoreCase(response)) {
|
|
|
log.error("IweldCloud login failed: empty response");
|
|
log.error("IweldCloud login failed: empty response");
|
|
|
|
|
+ sessionKey = "";
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -86,24 +88,28 @@ public class IweldCloudUtil {
|
|
|
JSONObject result = json.getJSONObject("result");
|
|
JSONObject result = json.getJSONObject("result");
|
|
|
if (result == null) {
|
|
if (result == null) {
|
|
|
log.error("IweldCloud login failed: missing result");
|
|
log.error("IweldCloud login failed: missing result");
|
|
|
|
|
+ sessionKey = "";
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (result.getIntValue("status") != 1) {
|
|
if (result.getIntValue("status") != 1) {
|
|
|
JSONObject error = result.getJSONObject("error");
|
|
JSONObject error = result.getJSONObject("error");
|
|
|
String message = error != null ? error.getString("message") : "unknown";
|
|
String message = error != null ? error.getString("message") : "unknown";
|
|
|
log.error("IweldCloud login failed: status={}, message={}", result.getIntValue("status"), message);
|
|
log.error("IweldCloud login failed: status={}, message={}", result.getIntValue("status"), message);
|
|
|
|
|
+ sessionKey = "";
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
sessionKey = result.getString("sessionKey");
|
|
sessionKey = result.getString("sessionKey");
|
|
|
if (sessionKey == null || sessionKey.isEmpty()) {
|
|
if (sessionKey == null || sessionKey.isEmpty()) {
|
|
|
log.error("IweldCloud login failed: empty sessionKey");
|
|
log.error("IweldCloud login failed: empty sessionKey");
|
|
|
|
|
+ sessionKey = "";
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
log.info("IweldCloud login success, sessionKey={}", sessionKey);
|
|
log.info("IweldCloud login success, sessionKey={}", sessionKey);
|
|
|
return true;
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("IweldCloud login error", e);
|
|
log.error("IweldCloud login error", e);
|
|
|
|
|
+ sessionKey = "";
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -206,16 +212,40 @@ public class IweldCloudUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 确保有有效 session 并拉取实时数据;失败时清 session 重登再拉一次。
|
|
|
|
|
+ * 用于隔夜 session 失效、客户端未重启等场景。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static boolean ensureSessionAndFetchRunInfo() {
|
|
|
|
|
+ if (sessionKey == null || sessionKey.isEmpty()) {
|
|
|
|
|
+ if (!Boolean.TRUE.equals(login())) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fetchRobotRunInfo()) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.warn("IweldCloud run info failed, clearing session and re-login");
|
|
|
|
|
+ sessionKey = "";
|
|
|
|
|
+ if (!Boolean.TRUE.equals(login())) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(API_MIN_INTERVAL_MS);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return fetchRobotRunInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 焊接运行中从 IweldCloud 采集焊机参数,更新界面并写入本地缓存。
|
|
* 焊接运行中从 IweldCloud 采集焊机参数,更新界面并写入本地缓存。
|
|
|
*/
|
|
*/
|
|
|
public static void collectWeldingParams() {
|
|
public static void collectWeldingParams() {
|
|
|
if (MesClient.tjFlaga != 2 && MesClient.tjFlagb != 2) {
|
|
if (MesClient.tjFlaga != 2 && MesClient.tjFlagb != 2) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (sessionKey == null || sessionKey.isEmpty()) {
|
|
|
|
|
- login();
|
|
|
|
|
- }
|
|
|
|
|
- if (!fetchRobotRunInfo()) {
|
|
|
|
|
|
|
+ if (!ensureSessionAndFetchRunInfo()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|