From c814a981db2a078a3d1021263ad349e2c1de9188 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <1247017146@qq.com>
Date: 星期二, 08 四月 2025 16:52:43 +0800
Subject: [PATCH] 1

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  189 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 120 insertions(+), 69 deletions(-)

diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index 5104d55..23dc750 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -77,79 +77,115 @@
                 CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                 if (conveyorLine != null)
                 {
+                    //ConsoleHelper.WriteColorLine("寮�濮嬶細" + DateTime.Now, ConsoleColor.Cyan);
                     // 鏌ヨ鎵�鏈夊瓙璁惧鐨勪綅缃�
                     List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
+                    // 鑾峰彇鎵�鏈夌珯鐐圭鐞嗗櫒
+                    List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
 
                     // 骞惰澶勭悊姣忎釜瀛愯澶�
                     var tasks = childDeviceCodes.Select(childDeviceCode => ProcessDeviceAsync(conveyorLine, childDeviceCode)).ToList();
+
+                    // 骞惰澶勭悊姣忎釜绔欑偣绠$悊鍣�
+                    tasks = stationManagers.Select(station => Task.Run(async () =>
+                    {
+                        var (command, commandWrite) = ReadCommands(station, conveyorLine);
+                        if (command == null || commandWrite == null)
+                        {
+                            return;
+                        }
+
+                        IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this);
+                        await handler.HandleStationAsync(conveyorLine, station, command, commandWrite);
+                    })).ToList();
+
+                    #region
+                    //foreach (var station in stationManagers)
+                    //{
+                    //    #region
+                    //    //tasks.Add(Task.Run(async () =>
+                    //    //{
+                    //    //    if (station.stationType == 11)
+                    //    //    {
+                    //    //        // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠�
+                    //    //        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
+                    //    //        ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
+                    //    //        if (command != null && commandWrite != null)
+                    //    //        {
+                    //    //            // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍
+                    //    //            var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
+                    //    //            if (structs[0] == true)
+                    //    //            {
+                    //    //                // 杈撳嚭璀﹀憡淇℃伅
+                    //    //                var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戠┖鎵樼洏璇锋眰鎵爜鍏ュ簱";
+                    //    //                ConsoleHelper.WriteWarningLine(log);
+
+                    //    //                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
+                    //    //                WriteInfo(conveyorLine.DeviceName, log);
+
+                    //    //                // 澶勭悊鍏ュ簱璇锋眰
+                    //    //                NGRequestTaskInbound(conveyorLine, command, station, 0);
+                    //    //            }
+                    //    //            else
+                    //    //            {
+                    //    //                // 鍙戦�佸畬鎴愪俊鍙�
+                    //    //                ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
+                    //    //            }
+                    //    //        }
+                    //    //    }
+                    //    //    else if (station.stationType == 5)
+                    //    //    {
+                    //    //        // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠�
+                    //    //        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
+                    //    //        ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
+                    //    //        if (command != null && commandWrite != null)
+                    //    //        {
+                    //    //            // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍
+                    //    //            var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
+                    //    //            if (structs[0] == true)
+                    //    //            {
+                    //    //                // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ换鍔�
+                    //    //                if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0)
+                    //    //                {
+                    //    //                    return;
+                    //    //                }
+                    //    //                // 杈撳嚭璀﹀憡淇℃伅
+                    //    //                var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戝紓甯稿彛璇锋眰鎵爜鍏ュ簱";
+                    //    //                ConsoleHelper.WriteWarningLine(log);
+
+                    //    //                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
+                    //    //                WriteInfo(conveyorLine.DeviceName, log);
+
+                    //    //                // 澶勭悊鏂颁换鍔�
+                    //    //                await HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0);
+                    //    //            }
+                    //    //            else
+                    //    //            {
+                    //    //                // 鍙戦�佸畬鎴愪俊鍙�
+                    //    //                ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
+                    //    //            }
+                    //    //        }
+                    //    //    }
+                    //    //}));
+                    //    #endregion
+
+                    //    tasks.Add(Task.Run(async () =>
+                    //    {
+                    //        var (command, commandWrite) = ReadCommands(station, conveyorLine);
+                    //        if (command == null || commandWrite == null)
+                    //        {
+                    //            return;
+                    //        }
+
+                    //        IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this);
+                    //        await handler.HandleStationAsync(conveyorLine, station, command, commandWrite);
+                    //    }));
+                    //}
+                    #endregion
+
                     await Task.WhenAll(tasks);
 
-                    // 鑾峰彇鎵�鏈夌珯鐐圭鐞嗗櫒
-                    List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
-                    foreach (var station in stationManagers)
-                    {
-                        if (station.stationType == 11)
-                        {
-                            // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠�
-                            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
-                            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
-                            if (command != null && commandWrite != null)
-                            {
-                                // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍
-                                var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
-                                if (structs[0] == true)
-                                {
-                                    // 杈撳嚭璀﹀憡淇℃伅
-                                    var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戠┖鎵樼洏璇锋眰鎵爜鍏ュ簱";
-                                    ConsoleHelper.WriteWarningLine(log);
-
-                                    await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
-                                    WriteInfo(conveyorLine.DeviceName, log);
-
-                                    // 澶勭悊鍏ュ簱璇锋眰
-                                    NGRequestTaskInbound(conveyorLine, command, station, 0);
-                                }
-                                else
-                                {
-                                    // 鍙戦�佸畬鎴愪俊鍙�
-                                    ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
-                                }
-                            }
-                        }
-                        else if (station.stationType == 5)
-                        {
-                            // 璇诲彇浠诲姟鍛戒护鍜岃澶囧懡浠�
-                            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
-                            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
-                            if (command != null && commandWrite != null)
-                            {
-                                // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍
-                                var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
-                                if (structs[0] == true)
-                                {
-                                    // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ换鍔�
-                                    if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0)
-                                    {
-                                        return;
-                                    }
-                                    // 杈撳嚭璀﹀憡淇℃伅
-                                    var log = $"銆恵conveyorLine.DeviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵station.stationChildCode}銆戝紓甯稿彛璇锋眰鎵爜鍏ュ簱";
-                                    ConsoleHelper.WriteWarningLine(log);
-
-                                    await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
-                                    WriteInfo(conveyorLine.DeviceName, log);
-
-                                    // 澶勭悊鏂颁换鍔�
-                                    await HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0);
-                                }
-                                else
-                                {
-                                    // 鍙戦�佸畬鎴愪俊鍙�
-                                    ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
-                                }
-                            }
-                        }
-                    }
+                    //ConsoleHelper.WriteColorLine("缁撴潫锛�" + DateTime.Now, ConsoleColor.Cyan);
                 }
             }
             catch (Exception ex)
@@ -221,7 +257,7 @@
                     }
 
                     // 鏌ヨ骞冲彴淇℃伅
-                    Platform platform = _platFormRepository.QueryFirst(x => x.PLCCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active");
+                    Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active");
                     if (platform != null && !string.IsNullOrEmpty(platform.Location))
                     {
                         var strings = platform.Location.Split(',').ToList();
@@ -732,7 +768,7 @@
                 }
                 var wmsIpAddress = wmsBase + requestTrayOutTask;
 
-                var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1" && x.DeviceRemark == platform.Id.ToString());
+                var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1");
                 var deviceCode = device.Select(x => x.DeviceCode).ToList();
 
                 // 鍙戦�丠TTP POST璇锋眰鑾峰彇浠诲姟鏁版嵁
@@ -762,7 +798,7 @@
             var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
             if (content.Status)
             {
-                Console.WriteLine($"{taskDTO.TaskType}鍛煎彨鎴愬姛");
+                Console.WriteLine($"{taskDTO.TargetAddress}鍛煎彨鎴愬姛");
             }
             return content;
         }
@@ -853,5 +889,20 @@
         }
 
         #endregion 璁惧NG鍙e叆搴�
+
+        public async Task LogAndWarn(string deviceName, string log, string color = "red")
+        {
+            ConsoleHelper.WriteWarningLine(log);
+            await _noticeService.Logs(userTokenIds, new { deviceName, log = log, time = DateTime.Now.ToString("G"), color = color });
+            WriteInfo(deviceName, log);
+        }
+
+        private (ConveyorLineTaskCommand, ConveyorLineTaskCommandWrite) ReadCommands(Dt_StationManager station, CommonConveyorLine conveyorLine)
+        {
+            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
+            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
+            return (command, commandWrite);
+        }
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3