From 7267e82ccfbea0fa03e8bc809a2d5ac6f7da84ac Mon Sep 17 00:00:00 2001
From: kazelee <1847801760@qq.com>
Date: 星期五, 20 六月 2025 15:33:36 +0800
Subject: [PATCH] 优化国自AGV和ERP下发的报文处理逻辑

---
 util/HttpHelper.cs                                                                   |    3 
 config/config.comment.json                                                           |   17 ++--
 dispatch/GZRobot.cs                                                                  |   14 +++
 api/ErpController.cs                                                                 |  112 +++++++++------------------
 /dev/null                                                                            |    0 
 api/AgvController.cs                                                                 |    2 
 .vs/HH.WCS.Mobox3.AnGang/FileContentIndex/26cb7641-a9ff-4b60-93af-e7b9228fb03d.vsidx |    0 
 api/ApiHelper.cs                                                                     |   31 +++++++
 api/ApiModel.cs                                                                      |    9 +
 process/TaskProcess.cs                                                               |    8 +-
 core/WCSCore.cs                                                                      |    7 +
 .vs/HH.WCS.Mobox3.AnGang/FileContentIndex/487b627d-37f2-4def-b2fe-acf99cac927a.vsidx |    0 
 12 files changed, 103 insertions(+), 100 deletions(-)

diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/26cb7641-a9ff-4b60-93af-e7b9228fb03d.vsidx b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/26cb7641-a9ff-4b60-93af-e7b9228fb03d.vsidx
new file mode 100644
index 0000000..fdebf7c
--- /dev/null
+++ b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/26cb7641-a9ff-4b60-93af-e7b9228fb03d.vsidx
Binary files differ
diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/487b627d-37f2-4def-b2fe-acf99cac927a.vsidx b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/487b627d-37f2-4def-b2fe-acf99cac927a.vsidx
new file mode 100644
index 0000000..63a339b
--- /dev/null
+++ b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/487b627d-37f2-4def-b2fe-acf99cac927a.vsidx
Binary files differ
diff --git a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/88ff7190-7304-453c-8d3d-4144359d0c9e.vsidx b/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/88ff7190-7304-453c-8d3d-4144359d0c9e.vsidx
deleted file mode 100644
index edd9348..0000000
--- a/.vs/HH.WCS.Mobox3.AnGang/FileContentIndex/88ff7190-7304-453c-8d3d-4144359d0c9e.vsidx
+++ /dev/null
Binary files differ
diff --git a/api/AgvController.cs b/api/AgvController.cs
index a64df99..0f27764 100644
--- a/api/AgvController.cs
+++ b/api/AgvController.cs
@@ -52,7 +52,7 @@
         /// <returns></returns>
         [HttpPost]
         [Route("safetyInteraction")]
-        public ReturnResult SafetyInteraction(SafetyInteractionInfo model) {
+        public gzResult SafetyInteraction(SafetyInteractionInfo model) {
             return WCSCore.SafetyInteraction(model);
         }
     }
diff --git a/api/ApiHelper.cs b/api/ApiHelper.cs
index a5e3514..7f71918 100644
--- a/api/ApiHelper.cs
+++ b/api/ApiHelper.cs
@@ -147,6 +147,17 @@
                 var endLoc = new TN_Location();
                 if (cgDetail.F_QTY > 2000) {
                     // 閲嶉噺瓒呰繃2t锛屾姤閿�+                    if (GZRobot.UpdateInteractInfo(new UpdateInteractInfo {
+                        type_name = "GET_DST",
+                        interaction_info_id = int.Parse(task.S_EQ_TASK_CODE),
+                        info_status = "error",
+                    })) {
+                        LogHelper.Info($"鍥借嚜AGV鎺ュ彈瓒呴噸鍙栨秷淇℃伅鎴愬姛", "API");
+                    }
+                    else {
+                        LogHelper.Info($"鍥借嚜AGV鎺ュ彈瓒呴噸鍙栨秷淇℃伅澶辫触", "API");
+                    }
+                    
                     return BuildSimpleResult(8, $"鐗╂枡閲嶉噺{cgDetail.F_QTY}瓒呰繃2t");
                 }
                 else if (cgDetail.F_QTY > 1500) {
@@ -181,6 +192,19 @@
                 // 淇敼浠诲姟缁堢偣涓篜DA鎸囧畾缁堢偣
                 task.S_END_LOC = endLoc.S_CODE;
                 LocationHelper.LockLoc(ref endLoc, 1); // 缁堢偣鍏ュ簱閿�+
+                if (GZRobot.UpdateInteractInfo(new UpdateInteractInfo {
+                    type_name = "GET_DST",
+                    interaction_info_id = int.Parse(task.S_EQ_TASK_CODE),
+                    info_status = "invalid",
+                    return_value = LocationHelper.GetAgvSite(task.S_END_LOC), // 鐩墠浣跨敤agvsite
+                })) {
+                    LogHelper.Info($"鍥借嚜AGV鎺ュ彈缁堢偣淇℃伅鎴愬姛", "API");
+                }
+                else {
+                    LogHelper.Info($"鍥借嚜AGV鎺ュ彈缁堢偣淇℃伅澶辫触", "API");
+                }
+
 
                 using (var tran = db.Ado.UseTran()) {
                     if (db.Updateable<TN_Task>(task).UpdateColumns(a => a.S_END_LOC).ExecuteCommand() <= 0) {
@@ -241,8 +265,6 @@
 
                 LocationHelper.LockLoc(ref startLoc, 2); // 璧风偣鍑哄簱閿�                 LocationHelper.LockLoc(ref endLoc, 1); // 缁堢偣鍏ュ簱閿�-
-                var res = GZRobot.QueryInteractInfo(3);
 
                 using (var tran = db.Ado.UseTran()) {
                     if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new {
@@ -381,7 +403,10 @@
                     }
                     var res = GZRobot.CancelGZOrder(code);
                     if (!res) {
-                        return BuildSimpleResult(2, $"鍥借嚜AGV鍙栨秷浠诲姟澶辫触锛�);
+                        LogHelper.Info($"鍥借嚜AGV鍙栨秷浠诲姟澶辫触锛�, "API");
+                    }
+                    else {
+                        LogHelper.Info($"鍥借嚜AGV鍙栨秷浠诲姟鎴愬姛锛�, "API");
                     }
 
                     using (var tran = db.Ado.UseTran()) {
diff --git a/api/ApiModel.cs b/api/ApiModel.cs
index bc034a5..0b61204 100644
--- a/api/ApiModel.cs
+++ b/api/ApiModel.cs
@@ -40,7 +40,7 @@
         }
 
         public class SafetyInteractionInfo {
-            public int station_id { get; set; }
+            //public int station_id { get; set; }
 
             /// <summary>
             /// 璇锋眰涓婄嚎/涓嬬嚎鐨勭殑绔欏彴搴撲綅鍚嶇О锛屼緥濡倃ork6銆亀ork8
@@ -51,7 +51,7 @@
             /// 璇锋眰鐮�             /// </summary>
             public string apply_code { get; set; }
-            public string task_no { set; get; }
+            //public string task_no { set; get; }
         }
 
         public class orderStatusReportParme {
@@ -118,6 +118,11 @@
             public string ResultMsg { get; set; }
         }
 
+        public class gzResult {
+            public int code { get; set; } = 0;
+            public string msg { get; set; } = "success";
+        }
+
         /// <summary>
         /// 杩斿洖缁橤Z
         /// </summary>
diff --git a/api/ErpController.cs b/api/ErpController.cs
index 88e60c0..55d9e11 100644
--- a/api/ErpController.cs
+++ b/api/ErpController.cs
@@ -26,10 +26,13 @@
             LogHelper.Info("瑙﹀彂API锛氬叆搴撴暟鎹悓姝� + JsonConvert.SerializeObject(model), "API");
 
             //var headers = Request.Headers;
-            //return ProcessInboundData(headers, model); // 濡傛灉瑕佹眰瀵笻TTP鎶ユ枃瀛楁鏍¢獙锛屼娇鐢ㄨ繖琛屼唬鐮�+            //var checkRes = CheckHeaders(headers);
+            //if (!checkRes.isSuccess) {
+            //    return CreateErrorResponse(checkRes.code, checkRes.message);
+            //}
 
-            //return ApiHelper.InboundDataSync(model);
-            return NormalProcessInboundData(model); // 鏆傛椂浣跨敤鍘熸湰鐨勯�杈�+            var res = ApiHelper.InboundDataSync(model);
+            return CreateSuccessResponse(res);
         }
 
         /// <summary>
@@ -43,32 +46,19 @@
             LogHelper.Info("瑙﹀彂API锛氬嚭搴撳彂鏂欏悓姝� + JsonConvert.SerializeObject(model), "API");
 
             //var headers = Request.Headers;
-            //return ProcessOutboundData(headers, model); // 濡傛灉瑕佹眰瀵笻TTP鎶ユ枃瀛楁鏍¢獙锛屼娇鐢ㄨ繖琛屼唬鐮�+            //var checkRes = CheckHeaders(headers);
+            //if (!checkRes.isSuccess) {
+            //    return CreateErrorResponse(checkRes.code, checkRes.message);
+            //}
 
-            //return ApiHelper.OutboundDataSync(model);
-            return NormalProcessOutboundData(model); // 鏆傛椂浣跨敤鍘熸湰鐨勯�杈�+            var res = ApiHelper.OutboundDataSync(model);
+            return CreateSuccessResponse(res);
         }
 
-        private IHttpActionResult NormalProcessInboundData(InboundDataSyncInfo model) {
-            var data = ApiHelper.InboundDataSync(model);
-            return ResponseMessage(new HttpResponseMessage(HttpStatusCode.OK) {
-                Headers = { },
-                Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
-            });
-        }
-
-        private IHttpActionResult NormalProcessOutboundData(OutboundDataSyncInfo model) {
-            var data = ApiHelper.OutboundDataSync(model);
-            return ResponseMessage(new HttpResponseMessage(HttpStatusCode.OK) {
-                Headers = { },
-                Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
-            });
-        }
-
-        private IHttpActionResult ProcessInboundData(System.Net.Http.Headers.HttpRequestHeaders headers, InboundDataSyncInfo model) {
+        private CheckHeadersResult CheckHeaders(System.Net.Http.Headers.HttpRequestHeaders headers) {
             // 蹇呴』瀛楁楠岃瘉
             if (!headers.Contains("sourceAppCode") || !headers.Contains("serviceId") || !headers.Contains("msgSendTime")) {
-                return CreateErrorResponse("2003", "缂哄皯蹇呰璇锋眰澶村弬鏁�);
+                return CreateCheckHeadersResult(false, "2003", "缂哄皯蹇呰璇锋眰澶村弬鏁�);
             }
 
             var headerModel = new {
@@ -79,60 +69,18 @@
                 MsgSendTime = headers.GetValues("msgSendTime").First()
             };
 
-            // 2. 楠岃瘉Header
+            // 楠岃瘉Header
             var validationResult = ValidateHeaders(headerModel);
             if (validationResult != null) {
                 return validationResult;
             }
 
-            // 3. 璇诲彇Body
-            //string requestBody = await Request.Content.ReadAsStringAsync(); // 涓嶉渶瑕佸紓姝ヨ鍙栵紝鐩存帴鐢╩odel
-
-            // 4. 楠岃瘉Body
+            // 楠岃瘉Body
             if (Request.Content.Headers.ContentLength > 2 * 1024 * 1024) {
-                return CreateErrorResponse("2102", "娑堟伅鍐呭杩囬暱锛岃秴杩�M");
+                return CreateCheckHeadersResult(false, "2102", "娑堟伅鍐呭杩囬暱锛岃秴杩�M");
             }
 
-            // 5. 澶勭悊涓氬姟閫昏緫
-            var result = ApiHelper.InboundDataSync(model);
-
-            // 6. 杩斿洖鎴愬姛鍝嶅簲
-            return CreateSuccessResponse(result);
-        }
-
-        private IHttpActionResult ProcessOutboundData(System.Net.Http.Headers.HttpRequestHeaders headers, OutboundDataSyncInfo model) {
-            // 蹇呴』瀛楁楠岃瘉
-            if (!headers.Contains("sourceAppCode") || !headers.Contains("serviceId") || !headers.Contains("msgSendTime")) {
-                return CreateErrorResponse("2003", "缂哄皯蹇呰璇锋眰澶村弬鏁�);
-            }
-
-            var headerModel = new {
-                SourceAppCode = headers.GetValues("sourceAppCode").First(),
-                Password = headers.Contains("password") ? headers.GetValues("password").First() : null,
-                ServiceId = headers.GetValues("serviceId").First(),
-                MsgToken = headers.Contains("msgToken") ? headers.GetValues("msgToken").First() : null,
-                MsgSendTime = headers.GetValues("msgSendTime").First()
-            };
-
-            // 2. 楠岃瘉Header
-            var validationResult = ValidateHeaders(headerModel);
-            if (validationResult != null) {
-                return validationResult;
-            }
-
-            // 3. 璇诲彇Body
-            //string requestBody = await Request.Content.ReadAsStringAsync();
-
-            // 4. 楠岃瘉Body
-            if (Request.Content.Headers.ContentLength > 2 * 1024 * 1024) {
-                return CreateErrorResponse("2102", "娑堟伅鍐呭杩囬暱锛岃秴杩�M");
-            }
-
-            // 5. 澶勭悊涓氬姟閫昏緫
-            var result = ApiHelper.OutboundDataSync(model);
-
-            // 6. 杩斿洖鎴愬姛鍝嶅簲
-            return CreateSuccessResponse(result);
+            return CreateCheckHeadersResult(true);
         }
 
         private IHttpActionResult CreateSuccessResponse(object data) {
@@ -149,22 +97,22 @@
             });
         }
 
-        private IHttpActionResult ValidateHeaders(dynamic headers) {
+        private CheckHeadersResult ValidateHeaders(dynamic headers) {
             // 瀹炵幇鎵�湁Header楠岃瘉閫昏緫
             if (!IsRegisteredApp(headers.SourceAppCode, headers.Password)) {
-                return CreateErrorResponse("2201", "婧愯皟鐢ㄧ郴缁熸湭娉ㄥ唽");
+                return CreateCheckHeadersResult(false, "2201", "婧愯皟鐢ㄧ郴缁熸湭娉ㄥ唽");
             }
 
             if (!IsValidService(headers.ServiceId)) {
-                return CreateErrorResponse("2202", "浠g悊鏈嶅姟鏈敞鍐�);
+                return CreateCheckHeadersResult(false, "2202", "浠g悊鏈嶅姟鏈敞鍐�);
             }
 
             if (!IsValidDateTime(headers.MsgSendTime)) {
-                return CreateErrorResponse("2101", "鏃堕棿鏍煎紡鏍¢獙澶辫触");
+                return CreateCheckHeadersResult(false, "2101", "鏃堕棿鏍煎紡鏍¢獙澶辫触");
             }
 
             if (!string.IsNullOrEmpty(headers.MsgToken) && headers.MsgToken.Length > 32) {
-                return CreateErrorResponse("2104", "娑堟伅浠ょ墝杩囬暱锛岃秴杩�2浣�);
+                return CreateCheckHeadersResult(false, "2104", "娑堟伅浠ょ墝杩囬暱锛岃秴杩�2浣�);
             }
 
             return null;
@@ -181,5 +129,19 @@
         private bool IsValidDateTime(string dataTime) {
             return true;
         }
+
+        private CheckHeadersResult CreateCheckHeadersResult(bool isSuccess, string code = "", string message = "") {
+            return new CheckHeadersResult {
+                code = code,
+                message = message,
+                isSuccess = isSuccess
+            };
+        }
+    }
+
+    public class CheckHeadersResult {
+        public bool isSuccess { get; set; }
+        public string code { get; set; }
+        public string message { get; set; }
     }
 }
\ No newline at end of file
diff --git a/config/config.comment.json b/config/config.comment.json
index afb4578..d34ee7a 100644
--- a/config/config.comment.json
+++ b/config/config.comment.json
@@ -1,22 +1,21 @@
 {
-    "WebApiUrl": "http://127.0.0.1:8901",
-    "RCSApiUrl": "http://127.0.0.1:6001",
-    "NDCApiUrl": "http://127.0.0.1:5201/api/order/",
-    "SqlServer": "Data Source=192.168.1.144;Initial Catalog=YinKouAnGan;User ID=hhuser;Password=Am123123",
-    //"SqlServer": "Data Source=(local);Initial Catalog=AnGangTest;User ID=sa;Password=123456",
+    "WebApiUrl": "http://127.0.0.1:8901", // 缁堢鍦板潃
+    "RCSApiUrl": "http://127.0.0.1:6001", // 鍥借嚜AGV璋冨害
+    "NDCApiUrl": "http://127.0.0.1:5201/api/order/", // 椤圭洰涓嶄娇鐢�+    "SqlServer": "Data Source=192.168.1.144;Initial Catalog=YinKouAnGan;User ID=hhuser;Password=Hh123321&&", // 鏁版嵁搴撳湴鍧�     "TCPServerIP": "127.0.0.1",
     "TCPServerPort": 8085,
     "Areas": [
         {
-            "Name": "鏀跺彂鍖�,
-            "Codes": [ "SFQ" ]
+            "Name": "鍙栨斁璐у尯",
+            "Codes": [ "QFHQ" ]
         },
         {
             "Name": "璐ф灦鍖�,
             "Codes": [ "HJQ" ]
         }
     ],
-    "Snap": [
+    "Snaps": [ // 鐩告満鎷嶆憚鐨処P鍜岃处鍙峰瘑鐮佷俊鎭�         {
             "Ip": "172.23.8.95",
             "Port": 37777,
@@ -24,5 +23,5 @@
             "Pwd": "123456"
         }
     ],
-    "CaptureUrl": "http://127.0.0.1/"
+    "CaptureUrl": "http://127.0.0.1/" // 鐩告満淇濆瓨鍥剧墖鐨勫湴鍧� }
\ No newline at end of file
diff --git a/core/WCSCore.cs b/core/WCSCore.cs
index c904e6f..ca22441 100644
--- a/core/WCSCore.cs
+++ b/core/WCSCore.cs
@@ -348,8 +348,11 @@
         }
 
         // DOC 4.	绔欏彴鐢宠瀹夊叏浜や簰 RCS->WMS
-        public static ReturnResult SafetyInteraction(SafetyInteractionInfo model) {
-            var gzResult = new ReturnResult();
+        public static gzResult SafetyInteraction(SafetyInteractionInfo model) {
+            var gzResult = new gzResult() {
+                code = 0,
+                msg = "success"
+            };
             // 鐩墠璇ラ」鐩病鏈夌珯鍙板畨鍏ㄤ氦浜掔殑鍔熻兘
             return gzResult;
         }
diff --git a/dispatch/GZRobot.cs b/dispatch/GZRobot.cs
index 465007f..0604374 100644
--- a/dispatch/GZRobot.cs
+++ b/dispatch/GZRobot.cs
@@ -7,6 +7,7 @@
 using HH.WCS.Mobox3.AnGang.models;
 using Newtonsoft.Json;
 using static HH.WCS.Mobox3.AnGang.api.ApiModel;
+using static System.Net.WebRequestMethods;
 
 namespace HH.WCS.Mobox3.AnGang.dispatch {
     /// <summary>
@@ -41,7 +42,14 @@
             if (response != "") {
                 try {
                     var dataResult = JsonConvert.DeserializeObject<gzResult<OrderInfoResult>>(response);
-                    if (dataResult.code == 0) {
+                    // 鍘熶唬鐮侀儴鍒�+                    //if (dataResult.code == 0) {
+                    //    orderId = dataResult.data[0].in_order_id;
+                    //}
+                    // 灏婇噸鏂囨。鐨勭増鏈�+                    // 杩斿洖鍙傛暟涓紝code鐩墠涓嶅啀浣跨敤锛屽彲閫氳繃msg瀛楁鍒ゆ柇鏄惁鎴愬姛锛屽鏋渕sg涓衡�success鈥濆垯琛ㄧず鎴愬姛锛屽惁鍒欎负鎶ラ敊淇℃伅鎴栦笉瀛樺湪銆俬ttp code涓�22鏃跺�鐨勬姤閿欎负绯荤粺鎶ラ敊锛屽叾涓殑msg鏃犳硶鍏ㄩ儴鑾峰彇銆�+                    // SELFNOTE: 鐩存帴璋冪敤HttpHelper.Post鏂规硶锛屾棤娉曡幏鍙杊eader锛屾殏鏃朵笉鑰冭檻
+                    if (dataResult.msg == "success") {
                         orderId = dataResult.data[0].in_order_id;
                     }
                 }
@@ -240,7 +248,7 @@
             return list;
         }
 
-        // DOC 澶囩敤
+        // DOC 6.	浜や簰琛ㄦ煡璇紙鏇存柊缁堢偣璐т綅锛�         public static bool UpdateInteractInfo(UpdateInteractInfo interactInfo) {
             string msg = "";
             var result = false;
@@ -257,6 +265,7 @@
             }
             return result;
         }
+
 
         // DOC 5.	绉伴噸淇℃伅鏌ヨ
         public static List<CustomData> CustomBuf() {
@@ -420,6 +429,7 @@
     public class UpdateInteractInfo
     {
         public int interaction_info_id { get; set; }
+        public string type_name { get; set; } = "GET_DST";
         public string info_status { get; set; }
         public string return_value { get; set; }
     }
diff --git a/process/TaskProcess.cs b/process/TaskProcess.cs
index 5dab3ac..6c81fbd 100644
--- a/process/TaskProcess.cs
+++ b/process/TaskProcess.cs
@@ -114,11 +114,11 @@
             if (mst.N_B_STATE == 0) {
                 // 鍘熶唬鐮佺増鏈�                 //var code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = mst.S_START_LOC, dst = mst.S_END_LOC }), "p2p");
-                // 灏婇噸鏂囨。鐨勭増鏈紙鏆備笉鑰冭檻淇敼锛屽洜涓烘病鏈夌粓鐐圭珯鐐癸紝涓嶅悎鐞嗭級
-                //var startSite = LocationHelper.GetAgvSite(mst.S_START_LOC);
-                //var endSite = LocationHelper.GetAgvSite(mst.S_END_LOC);
+                // 灏婇噸鏂囨。鐨勭増鏈�+                var startSite = LocationHelper.GetAgvSite(mst.S_START_LOC);
+                var endSite = LocationHelper.GetAgvSite(mst.S_END_LOC); // 濡傛灉鎵句笉鍒颁細杩斿洖0锛屽氨鏄亣缁堢偣
 
-                var code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = mst.S_START_LOC, dst = mst.S_END_LOC }), "p2pdst", "pgapi");
+                var code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = startSite, dst = endSite }), "p2pdst", "pgapi");
 
                 if (code > 0) {
                     //鏇存柊浠诲姟鐘舵�
diff --git a/util/HttpHelper.cs b/util/HttpHelper.cs
index 1beb8ac..d71f403 100644
--- a/util/HttpHelper.cs
+++ b/util/HttpHelper.cs
@@ -101,9 +101,8 @@
                 if (stream != null) stream.Close();
                 if (rsp != null) rsp.Close();
             }
-
         }
-
+        
         public string Post(string url, string postData, string contentType = "application/json", string sessionId = "") {
             Console.WriteLine(url);
             WebRequest request = WebRequest.Create(url);

--
Gitblit v1.9.1