From 26419bf11ec888de7af9141a0ac1874065775e61 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 04 十一月 2023 13:59:51 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/utils/NyHttpUtils.java | 107 ++++++++++++++++++++++++++++++-----------------------
1 files changed, 60 insertions(+), 47 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/NyHttpUtils.java b/src/main/java/com/zy/common/utils/NyHttpUtils.java
index be86a96..40a7436 100644
--- a/src/main/java/com/zy/common/utils/NyHttpUtils.java
+++ b/src/main/java/com/zy/common/utils/NyHttpUtils.java
@@ -16,6 +16,8 @@
*/
public class NyHttpUtils {
+ private static final boolean DEBUG = true;//璋冭瘯妯″紡
+
//鑾峰彇HTTP璇锋眰鏍囧噯缁撴瀯浣�
public static NyShuttleHttpCommand getHttpStandard(Integer shuttleNo, Integer wrkNo) {
NyShuttleHttpCommand httpStandard = new NyShuttleHttpCommand();
@@ -69,11 +71,27 @@
NyShuttleHttpCommand httpStandard = getHttpStandard(shuttleNo, wrkNo);
NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
+ NyShuttleProtocol.NyShuttlePointClass nyStartPoint = new NyShuttleProtocol.NyShuttlePointClass();
+ NyShuttleProtocol.NyShuttlePointClass nyTargetPoint = new NyShuttleProtocol.NyShuttlePointClass();
+ if (in) {
+ //杩涙彁鍗囨満
+ nyStartPoint = navigateNodeToNyPointNode(start);
+ nyTargetPoint.setX(target.getX());
+ nyTargetPoint.setY(target.getY());
+ nyTargetPoint.setZ(target.getZ());
+ }else {
+ //鍑烘彁鍗囨満
+ nyTargetPoint = navigateNodeToNyPointNode(target);
+ nyStartPoint.setX(start.getX());
+ nyStartPoint.setY(start.getY());
+ nyStartPoint.setZ(start.getZ());
+ }
+
HashMap<String, Object> body = new HashMap<>();
body.put("requestType", in ? "intoLift" : "outLift");//杩涘嚭鎻愬崌鏈�
body.put("taskId", getTaskId());//TaskID闇�瑕侀殢鏈�
- body.put("start", navigateNodeToNyPointNode(start));//璧风偣
- body.put("target", navigateNodeToNyPointNode(target));//缁堢偣
+ body.put("start", nyStartPoint);//璧风偣
+ body.put("target", nyTargetPoint);//缁堢偣
request.setBody(body);
httpStandard.setRequest(request);
@@ -123,8 +141,8 @@
}
//鑾峰彇鏇存柊灞傚潗鏍嘮(妤煎眰)鍛戒护
- public static NyShuttleHttpCommand getUpdateZCommand(Integer shuttleNo, Integer z) {
- NyShuttleHttpCommand httpStandard = getHttpStandard(shuttleNo, 9999);
+ public static NyShuttleHttpCommand getUpdateZCommand(Integer shuttleNo, Integer z, Integer wrkNo) {
+ NyShuttleHttpCommand httpStandard = getHttpStandard(shuttleNo, wrkNo);
NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
HashMap<String, Object> body = new HashMap<>();
@@ -279,54 +297,49 @@
}
//鍙戝嚭璇锋眰
- public static JSONObject requestCommand(Socket socket, NyShuttleHttpCommand httpCommand) {
- try {
- if (socket == null) {
- return null;
- }
- // 鑾峰彇杈撳叆娴佸拰杈撳嚭娴�
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- OutputStreamWriter writer = new OutputStreamWriter(socket.getOutputStream());
- writer.write(JSON.toJSONString(httpCommand) + "\r\n");
- writer.flush();
+ public static JSONObject requestCommand(Socket socket, NyShuttleHttpCommand httpCommand) throws IOException {
+ if (socket == null) {
+ return null;
+ }
+
+ //鍘嬬缉鏁版嵁鍖�
+ JSONObject data = JSON.parseObject(JSON.toJSONString(httpCommand));
+ data.remove("nodes");
+
+ // 鑾峰彇杈撳叆娴佸拰杈撳嚭娴�
+ BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ OutputStreamWriter writer = new OutputStreamWriter(socket.getOutputStream());
+ writer.write(JSON.toJSONString(data) + "\r\n");
+ writer.flush();
// System.out.println("Sent message to server: " + JSON.toJSONString(httpCommand));
- // 璇诲彇鏈嶅姟鍣ㄧ殑鍝嶅簲
- StringBuffer sb = new StringBuffer();
- String response = null;
- char[] chars = new char[2048];//缂撳啿鍖�
- do {
- reader.read(chars);
- String trim = new String(chars).trim();
- sb.append(trim);
- if (sb.lastIndexOf("\r\n") != -1) {
- break;
- }
- } while (response != null);
+ // 璇诲彇鏈嶅姟鍣ㄧ殑鍝嶅簲
+ StringBuffer sb = new StringBuffer();
+ String response = null;
+ char[] chars = new char[2048];//缂撳啿鍖�
+ do {
+ reader.read(chars);
+ String trim = new String(chars).trim();
+ sb.append(trim);
+ if (sb.lastIndexOf("\r\n") != -1) {
+ break;
+ }
+ } while (response != null);
// System.out.println("Received response from server: " + sb);
- JSONObject result = JSON.parseObject(sb.toString());//寰楀埌鍝嶅簲缁撴灉闆�
- if (!result.get("msgType").equals("responseMsg")) {//涓嶆槸鍝嶅簲鍐呭
- return null;
- }
-
- JSONObject resultResponse = JSON.parseObject(result.get("response").toString());
- JSONObject resultHeader = JSON.parseObject(resultResponse.get("header").toString());
- int responseId = Integer.parseInt(resultHeader.get("responseId").toString());
-// if (responseId != httpCommand.getRequest().getHeader().getRequestId()) {
-// return null;//鍝嶅簲ID涓庤姹侷D涓嶄竴鑷�
-// }
-
- return filterBodyData(result);//杩斿洖Body缁撴灉闆�
- } catch (Exception e) {
- e.printStackTrace();
- try {
- socket.close();
- } catch (IOException exception) {
- exception.printStackTrace();
- }
+ JSONObject result = JSON.parseObject(sb.toString());//寰楀埌鍝嶅簲缁撴灉闆�
+ if (!result.get("msgType").equals("responseMsg")) {//涓嶆槸鍝嶅簲鍐呭
+ return null;
}
- return null;
+
+ JSONObject resultResponse = JSON.parseObject(result.get("response").toString());
+ JSONObject resultHeader = JSON.parseObject(resultResponse.get("header").toString());
+ int responseId = Integer.parseInt(resultHeader.get("responseId").toString());
+ if (!DEBUG && responseId != httpCommand.getRequest().getHeader().getRequestId()) {
+ return null;//鍝嶅簲ID涓庤姹侷D涓嶄竴鑷达紝涓嶅湪璋冭瘯妯″紡涓�
+ }
+
+ return filterBodyData(result);//杩斿洖Body缁撴灉闆�
}
public static JSONObject filterBodyData(JSONObject data) {
--
Gitblit v1.9.1