From 8d25be31906e458a5a8a2a3627184e3adc49e395 Mon Sep 17 00:00:00 2001
From: czw <selecti@yeah.net>
Date: 星期六, 05 七月 2025 15:37:48 +0800
Subject: [PATCH] 1

---
 2025年6月12日/AuxAllWCS/Build/Project/代码/VS自定义类/AutoThread.cs |  199 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 193 insertions(+), 6 deletions(-)

diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs"
index 4abdad7..a7b454f 100644
--- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs"
+++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs"
@@ -25,6 +25,7 @@
 using System.Net.WebSockets;
 using System.Net;
 using System.Threading;
+using System.IO;
 
 namespace GZ.Projects.AuxAllWCS
 {
@@ -76,8 +77,8 @@
             }
 
             // 鎵ц濮旀墭
-            if (methodName != "TaskEverythingRun")
-                return null;
+            //if (methodName != "TaskEverythingRun")
+            //    return null;
             return methodDelegate.DynamicInvoke(args);
         }
 
@@ -254,6 +255,8 @@
 
             if (VERX != null)
             {
+                if (tag.wxr1.R44)
+                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr1.R44} R44LAST>{tag.wxr1.R44_LAST} R10>{tag.wxr1.R10}");
                 if (tag.wxr1.R44 && !tag.wxr1.R44_LAST && tag.wxr1.R10)
                 {
                     if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -292,6 +295,8 @@
                         if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                         {
                             //涓婃姤鏍¢獙銆�+                            LogHelper.Info($"{VERX.deviceNo[0]} 涓婃姤鏍¢獙>{traycode}");
+
                             ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                             var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
                             {
@@ -312,6 +317,10 @@
                         }
                         else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
                     }
+                    else if (!tag.wxr1.R10)
+                    {
+                        TcpServer.TrayIps.Remove(VERX.deviceNo[0]);
+                    }
                 }
             }
         }
@@ -327,6 +336,8 @@
 
             if (VERX != null)
             {
+                if (tag.wxr1.R46)
+                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr1.R46} R44LAST>{tag.wxr1.R46_LAST} R10>{tag.wxr1.R11}");
                 if (tag.wxr1.R46 && !tag.wxr1.R46_LAST && tag.wxr1.R11)
                 {
                     if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -364,6 +375,7 @@
                         if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                         {
                             //涓婃姤鏍¢獙銆�+                            LogHelper.Info($"{VERX.deviceNo[1]} 涓婃姤鏍¢獙>{traycode}");
                             ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                             var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
                             {
@@ -384,6 +396,10 @@
                         }
                         else { TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
                     }
+                    else if (!tag.wxr1.R11)
+                    {
+                        TcpServer.TrayIps.Remove(VERX.deviceNo[1]);
+                    }
                 }
             }
         }
@@ -399,6 +415,8 @@
 
             if (VERX != null)
             {
+                if (tag.wxr2.R44)
+                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr2.R44} R44LAST>{tag.wxr2.R44_LAST} R10>{tag.wxr2.R10}");
                 if (tag.wxr2.R44 && !tag.wxr2.R44_LAST && tag.wxr2.R10)
                 {
                     if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -436,6 +454,7 @@
                         if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[0], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                         {
                             //涓婃姤鏍¢獙銆�+                            LogHelper.Info($"{VERX.deviceNo[0]} 涓婃姤鏍¢獙>{traycode}");
                             ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                             var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
                             {
@@ -456,6 +475,10 @@
                         }
                         else { TcpServer.TcpServerSend(VERX.deviceNo[0], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E")); }
                     }
+                    else if (!tag.wxr2.R10)
+                    {
+                        TcpServer.TrayIps.Remove(VERX.deviceNo[0]);
+                    }
                 }
             }
         }
@@ -472,6 +495,8 @@
 
             if (VERX != null)
             {
+                if (tag.wxr2.R46)
+                    LogHelper.Info($"{VERX.deviceName} R44>{tag.wxr2.R46} R44LAST>{tag.wxr2.R46_LAST} R10>{tag.wxr2.R11}");
                 if (tag.wxr2.R46 && !tag.wxr2.R46_LAST && tag.wxr2.R11)
                 {
                     if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
@@ -510,7 +535,7 @@
                         else
                         if (TcpServer.TrayIps.TryGetValue(VERX.deviceNo[1], out string traycode) && !string.IsNullOrEmpty(traycode.Trim()))
                         {
-                            LogHelper.Info($"Threadwxr2R 涓婃姤鏍¢獙>{traycode}");
+                            LogHelper.Info($"{VERX.deviceNo[1]} 涓婃姤鏍¢獙>{traycode}");
                             //涓婃姤鏍¢獙銆�                             ///var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
                             var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/202", JsonConvert.SerializeObject(new
@@ -535,6 +560,10 @@
                             LogHelper.Info($"Threadwxr2R銆傘�  -鍙戦�鎵爜");
                             TcpServer.TcpServerSend(VERX.deviceNo[1], GZ.Device.PLC.PlcHelper.Hex2Bin("544F4E"));
                         }
+                    }
+                    else if (!tag.wxr2.R11)
+                    {
+                        TcpServer.TrayIps.Remove(VERX.deviceNo[1]);
                     }
                 }
             }
@@ -1584,6 +1613,10 @@
             foreach (var task in tasks)
             {
                 LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} ");
+                if (task.S_TYPE?.Trim() == "100")
+                {
+                    LogHelper.Info($"MES浠诲姟 S_TYPE 100->{task.S_TYPE} ");
+                }
                 var sx = VERXs?.Find(x => x.location.Contains(task.S_END_LOC));
                 LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} {(sx == null ? "闈� : "鏄�)}鎬昏鏈哄櫒浜轰换鍔�);
                 if (sx == null)
@@ -2008,7 +2041,7 @@
                 if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                 {
                     Console.WriteLine($"ip= {ip.ToString()}");
-
+                    new HttpServer(ip.ToString()).HttpServerRun();
                     new TcpServer(ip.ToString());
                     var server = new EnhancedWebSocketServer($"http://{ip.ToString()}:8809/").StartAsync();
                     //var client = new WebSocketClient($"http://{ip.ToString()}:8809/").ConnectAsync();
@@ -2026,12 +2059,168 @@
 
 
 
+    }
 
 
+    public class HttpServer
+    {
+        System.Net.HttpListener HttpSvcHost = null;
+
+        public static string _listenerPrefix = "";
+        public HttpServer(string ip)
+        {
+            _listenerPrefix = $"http://{ip}:8808/";
+        }
+        public void HttpServerRun()
+        {
+            HttpSvcHost = new System.Net.HttpListener();
+            HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous;
+            HttpSvcHost.Prefixes.Add(_listenerPrefix);
+            HttpSvcHost.Start();
+            HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
+        }
 
 
+        private async void HttpSvcListenerCallback(IAsyncResult ar)
+        {
+            System.Net.HttpListenerContext context = null;
+            var data = DateTime.Now;
+            string apth = "";
+            try
+            {
+                HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null);
+                context = HttpSvcHost.EndGetContext(ar);
+                System.Net.HttpListenerRequest request = context.Request;
+                System.Net.HttpListenerResponse response = context.Response;
 
+                using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8))
+                {
+                    string requestJson = reader.ReadToEnd();
+                    System.Net.HttpStatusCode statusCode = 0;
+                    apth = request.Url.AbsolutePath;
+                    string respstr = HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out statusCode);
+                    string logContent = "";
+                    logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}";
+                    logContent += $"\r\n[request]{requestJson}";
+                    logContent += $"\r\n[response]{respstr}";
+                    _ = Task.Run(() =>
+                    {
+                        Conn.榛樿鏃ュ織?.Info(logContent);
+                    });
+                    byte[] bytstr = Encoding.UTF8.GetBytes(respstr);
+                    response.StatusCode = (int)statusCode;
+                    response.SendChunked = false;
+                    response.ContentLength64 = bytstr.Length;
+                    //response.OutputStream.Write(bytstr, 0, bytstr.Length);
+                    if (request.Url.AbsolutePath.ToLower().Contains(".js"))
+                        response.ContentType = "application/javascript";
+                    else if (request.Url.AbsolutePath.ToLower().Contains(".svg"))
+                        response.ContentType = "image/svg+xml";
+                    // 寮傛鍐欏叆鍝嶅簲
+                    await response.OutputStream.WriteAsync(bytstr, 0, bytstr.Length);
+                }
+            }
+            catch (Exception ex)
+            {
+                _ = Task.Run(() =>
+                {
+                    Conn.榛樿鏃ュ織.Error(ex.ToString());
+                });
+            }
+            finally
+            {
+                context?.Response.Close();
+                Console.WriteLine(apth + "<<>>" + DateTime.Now.Subtract(data).TotalMilliseconds);
+            }
+        }
+        private System.String HttpSvcListenerCallback_he(System.String method, System.String path, System.String requestJson, out System.Net.HttpStatusCode statusCode)
+        {
+            try
+            {
+                switch (method)
+                {
+                    case "POST":
+                        {
+                            switch (path)
+                            {
+                                case "/agv/agvCallbackService/agvCallback":
+                                    {
+                                        statusCode = System.Net.HttpStatusCode.OK;
 
+                                        LogHelper.Info("ExecuteState Request-haikang锛� + requestJson);
+                                        var model = JsonConvert.DeserializeObject<HaiKangOrderInfo>(requestJson);
+                                        AutoThread.Instance.OperateHKTaskStatus(model);
+                                        return JsonConvert.SerializeObject(new HkReturnResult { reqCode = model.reqCode });
+                                    }
+                                case "/api/Wcs/CreateTask":
+                                    {
+                                        statusCode = System.Net.HttpStatusCode.OK;
+
+                                        LogHelper.Info("/api/Wcs/CreateTask锛� + requestJson);
+                                        var model = JsonConvert.DeserializeObject<ToWMSMES.CreateTask>(requestJson);
+                                        var res = ToWMSMES.CreateTask.CreatemesTask(model);
+                                        return JsonConvert.SerializeObject(res);
+                                    }
+                                case "/api/Wcs/TestRequestTask":
+                                    {
+                                        statusCode = System.Net.HttpStatusCode.OK;
+                                        LogHelper.Info("/api/Wcs/TestRequestTask锛� + requestJson);
+                                        var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/200", requestJson);
+                                        return str;
+                                    }
+                                case "/api/Wcs/updateStatus":
+                                    {
+                                        statusCode = System.Net.HttpStatusCode.OK;
+                                        LogHelper.Info("/api/Wcs/updateStatus锛� + requestJson);
+                                        var str = Settings.apiHelper.Post(Settings.WMSbaseUrl + "mom-basic/dataTransmission/json/service/201", requestJson);
+                                        return str;
+                                    }
+                                case "/api/Wcs/toMes":
+                                    {
+                                        statusCode = System.Net.HttpStatusCode.OK;
+
+                                        LogHelper.Info("/api/Wcs/toMes锛� + requestJson);
+                                        var str = Settings.apiHelper.Post(Settings.MESbaseUrl + "mom-basic/dataTransmission/json/service/202", requestJson);
+                                        return str;
+                                    }
+                                case "/api/Wcs/CreatePointTask":
+                                    {
+                                        statusCode = System.Net.HttpStatusCode.OK;
+
+                                        LogHelper.Info("/api/Wcs/CreatepointTask锛� + requestJson);
+                                        var model = JsonConvert.DeserializeObject<ToWMSMES.CreateTask>(requestJson);
+                                        var res = ToWMSMES.CreateTask.CreatePointTask(model);
+                                        return JsonConvert.SerializeObject(res);
+                                    }
+                            }
+                            break;
+                        }
+                    case "GET":
+                        {
+                            switch (path)
+                            {
+                                case var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase):
+                                    {
+                                        statusCode = System.Net.HttpStatusCode.OK;
+                                        // 澶嶅埗鍒癱ase 涓�+                                        //var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
+                                        var filePath = /*Directory.GetCurrentDirectory() + "\\Static" + "\\" + path.Substring(1);*/System.IO.Path.Combine(Directory.GetCurrentDirectory() + "\\Static", path.Substring(1));
+                                        return File.ReadAllText(filePath);
+                                    }
+                            }
+                            break;
+                        }
+                }
+                statusCode = System.Net.HttpStatusCode.NotFound;
+                return "";
+            }
+            catch (Exception ex)
+            {
+                Conn.榛樿鏃ュ織.Error(ex.ToString());
+                statusCode = System.Net.HttpStatusCode.InternalServerError;
+                return "";
+            }
+        }
     }
 
     class EnhancedWebSocketServer
@@ -2169,8 +2358,6 @@
         }
 
     }
-
-
 
     internal class WebSocketClient
     {

--
Gitblit v1.9.1