From 50435a81915932eda06b7f1afd48f9ff1ae84f19 Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期四, 10 四月 2025 17:50:28 +0800
Subject: [PATCH] 1
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java | 62 ++++++++++++++++++++++++++-----
1 files changed, 52 insertions(+), 10 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
index 40b243c..e6fa940 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
@@ -62,6 +62,7 @@
private static final boolean DEBUG = false;//璋冭瘯妯″紡
+ private List<JSONObject> socketReadResults = new ArrayList<>();
private List<JSONObject> socketResults = new ArrayList<>();
//鍘熷璁惧鏁版嵁
@@ -82,6 +83,7 @@
while (true) {
try {
listenSocketMessage();
+ listenInit();//鐩戝惉鍒濆鍖栦簨浠�
} catch (Exception e) {
e.printStackTrace();
}
@@ -137,7 +139,6 @@
Thread otherThread = new Thread(() -> {
while (true) {
try {
- listenInit();//鐩戝惉鍒濆鍖栦簨浠�
saveLog();//淇濆瓨鏁版嵁
} catch (Exception e) {
e.printStackTrace();
@@ -223,7 +224,19 @@
}
JSONObject result = JSON.parseObject(sb.toString());//寰楀埌鍝嶅簲缁撴灉闆�
- if (!socketResults.isEmpty() && socketResults.size() >= 5) {
+
+ String msgType = result.getString("msgType");
+ if ("responseMsg".equals(msgType)) {
+ JSONObject response = result.getJSONObject("response");
+ JSONObject body = response.getJSONObject("body");
+ if (body.containsKey("workingMode")) {
+ //read
+ socketReadResults.add(body);
+ return;
+ }
+ }
+
+ if (!socketResults.isEmpty() && socketResults.size() >= 20) {
socketResults.remove(0);//娓呯悊澶磋妭鐐�
}
socketResults.add(result);//娣诲姞鏁版嵁
@@ -307,7 +320,18 @@
//----------璇诲彇鍥涘悜绌挎杞︾姸鎬�-----------
NyShuttleHttpCommand readStatusCommand = getReadStatusCommand(Integer.parseInt(device.getDeviceNo()));
- JSONObject data = requestCommand(readStatusCommand);
+ requestCommandAsync(readStatusCommand);//璇锋眰鐘舵��
+
+ if (this.socketReadResults.isEmpty()) {
+ if (System.currentTimeMillis() - shuttleProtocol.getLastOnlineTime() > 1000 * 60) {
+ //鏈�鍚庝竴娆′笂绾挎椂闂磋秴杩�60s锛岃瀹氱绾�
+ this.shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.OFFLINE);
+ }
+ return;
+ }
+
+ JSONObject data = this.socketReadResults.get(0);
+ this.socketReadResults.remove(0);
if (data == null) {
if (System.currentTimeMillis() - shuttleProtocol.getLastOnlineTime() > 1000 * 60) {
//鏈�鍚庝竴娆′笂绾挎椂闂磋秴杩�60s锛岃瀹氱绾�
@@ -356,13 +380,17 @@
///璇诲彇鍥涘悜绌挎杞︾姸鎬�-end
//灏忚溅澶勪簬杩愯涓紝灏嗘爣璁扮疆涓簍rue
- if (shuttleProtocol.getDeviceStatus() == 1) {
+ if (shuttleProtocol.getDeviceStatus() == 0) {
shuttleProtocol.setPakMk(true);
}
- if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 0) {
+ if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 1) {
//灏忚溅绌洪棽鐘舵�併�佸皬杞︿换鍔$姸鎬佷负鏈煡锛岃瀹氭浘绂荤嚎杩囷紝闇�瑕佸浣嶆垚绌洪棽
shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE);
+ }
+
+ if (shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.OFFLINE) && shuttleProtocol.getDeviceStatus().intValue() == 1) {
+ this.shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
}
this.originDeviceData = data;
@@ -403,6 +431,9 @@
String requestType = resultBody.getString("requestType");
Integer requestId = resultHeader.getInteger("requestId");
if (requestType.equals("init")) {
+ removeIdx = i;//姝ゆ暟鎹凡缁忓鐞嗭紝浠庣粨鏋滈泦涓墧闄�
+ socketResults.remove(removeIdx);
+
Integer code = resultBody.getInteger("code");
//灏忚溅澶嶄綅璇锋眰
ShuttleCommand initCommand = getInitCommand(requestId, code);
@@ -410,16 +441,11 @@
NyShuttleHttpCommand httpCommand = JSON.parseObject(initCommand.getBody(), NyShuttleHttpCommand.class);
JSONObject requestResult = requestCommand(httpCommand);
- removeIdx = i;//姝ゆ暟鎹凡缁忓鐞嗭紝浠庣粨鏋滈泦涓墧闄�
log.info(MessageFormat.format("銆恵0}銆戝洓鍚戣溅澶嶄綅涓婃姤 ===>> [code:{1}] [ip:{2}] [port:{3}]", device.getId(), code, device.getIp(), device.getPort()));
OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戣溅澶嶄綅涓婃姤 ===>> [code:{1}] [ip:{2}] [port:{3}]", device.getId(), code, device.getIp(), device.getPort()));
break;
}
- }
-
- if (removeIdx != -1) {
- socketResults.remove(removeIdx);
}
} catch (Exception e) {
e.printStackTrace();
@@ -1111,6 +1137,22 @@
return result;//杩斿洖Body缁撴灉闆�
}
+ private void requestCommandAsync(NyShuttleHttpCommand httpCommand) throws IOException {
+ if (this.socket == null) {
+ return;
+ }
+
+ //鍘嬬缉鏁版嵁鍖�
+ JSONObject data = JSON.parseObject(JSON.toJSONString(httpCommand));
+ data.remove("nodes");
+
+ // 鑾峰彇杈撳嚭娴�
+ OutputStreamWriter writer = new OutputStreamWriter(this.socket.getOutputStream());
+ writer.write(JSON.toJSONString(data) + "\r\n");
+ writer.flush();
+// System.out.println("Sent message to server: " + JSON.toJSONString(httpCommand));
+ }
+
private JSONObject filterBodyData(JSONObject data) {
Object response = data.get("response");
if (response == null) {
--
Gitblit v1.9.1