From 0d9fb6555efa42e27de4d57d3fb7b8d82a78ef45 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 27 三月 2025 14:10:43 +0800
Subject: [PATCH] 优化任务处理逻辑并清理代码

---
 CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |   71 +++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index b3c67f3..1138106 100644
--- a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
+++ b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -1,14 +1,9 @@
 锘縰sing AutoMapper;
 using HslCommunication;
-using Microsoft.AspNetCore.Components.Routing;
-using NetTaste;
 using Newtonsoft.Json;
 using Quartz;
 using SqlSugar;
-using System.Drawing;
 using System.Reflection;
-using System.Security.Policy;
-using System.Threading.Tasks;
 using WIDESEAWCS_BasicInfoRepository;
 using WIDESEAWCS_BasicInfoService;
 using WIDESEAWCS_Common;
@@ -31,7 +26,6 @@
 using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_SignalR;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
-using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
 using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
 
 namespace WIDESEAWCS_Tasks
@@ -281,7 +275,8 @@
                                     command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
                                     // 璋冪敤澶勭悊鏂规硶
                                     method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
-                                };
+                                }
+                                ;
                             }
                         }
                     }
@@ -296,6 +291,7 @@
             }
             return Task.CompletedTask;
         }
+
         #region 鍏ュ簱
 
         /// <summary>
@@ -351,15 +347,23 @@
                 }
                 else
                 {
-                    // 濡傛灉浠诲姟涓虹┖涓旀潯鐮佷笉涓�"NoRead"涓旀潯鐮佷笉涓虹┖锛屽垯澶勭悊鏂颁换鍔�
-                    if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull())
+                    task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+                    if (task != null)
                     {
-                        // 鏌ヨ鏉$爜瀵瑰簲鐨勪换鍔�
-                        task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode);
-                        if (task == null)
+                        RequestInNextAddress(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
+                    }
+                    else
+                    {
+                        // 濡傛灉浠诲姟涓虹┖涓旀潯鐮佷笉涓�"NoRead"涓旀潯鐮佷笉涓虹┖锛屽垯澶勭悊鏂颁换鍔�
+                        if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull())
                         {
-                            // 寮傛澶勭悊鏂颁换鍔�
-                            await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
+                            // 鏌ヨ鏉$爜瀵瑰簲鐨勪换鍔�
+                            task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode);
+                            if (task == null)
+                            {
+                                // 寮傛澶勭悊鏂颁换鍔�
+                                await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
+                            }
                         }
                     }
                 }
@@ -371,7 +375,7 @@
             }
         }
 
-        public string RequestInboundPlatform(string childDeviceCode,string productLine,bool IsTrayBarcode)
+        public string RequestInboundPlatform(string childDeviceCode, string productLine, bool IsTrayBarcode)
         {
             try
             {
@@ -398,11 +402,11 @@
                                 }
                                 else
                                 {
-                                    var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew);
-                                    if (Hastask != null && Hastask.Count > 0)
-                                    {
-                                        //doto澶勭悊闄堝寲鏈墽琛岀殑绌烘墭鍑哄簱浠诲姟
-                                    }
+                                    //var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew);
+                                    //if (Hastask != null && Hastask.Count > 0)
+                                    //{
+                                    //    //doto澶勭悊闄堝寲鏈墽琛岀殑绌烘墭鍑哄簱浠诲姟
+                                    //}
                                     return null;
                                 }
                             }
@@ -420,7 +424,7 @@
             {
                 ConsoleHelper.WriteErrorLine($"鏂规硶RequestInboundPlatform锛歿ex.Message}");
             }
-            
+
             return null;
         }
 
@@ -432,20 +436,19 @@
         /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
         /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
-        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode,int ProtocalDetailValue)
+        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
         {
             var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣姹傚叆搴撲笅涓�鍦板潃";
             ConsoleHelper.WriteWarningLine(log);
 
             _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
             WriteInfo(conveyorLine.DeviceName, log);
-            if (childDeviceCode == "1279")
-            {
-                var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
-                CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue, stationManager);
-            }
+            //if (childDeviceCode == "1279")
+            //{
+            //    var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
+            //    CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue, stationManager);
+            //}
 
-            
             Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
             if (task != null)
             {
@@ -467,6 +470,8 @@
                         WriteInfo(conveyorLine.DeviceName, logs);
 
                         conveyorLine.SendCommand(taskCommand, childDeviceCode);
+
+                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                     }
                 }
             }
@@ -744,8 +749,8 @@
 
         #endregion 鍑哄簱
 
-
         #region 杈撻�佺嚎浜や簰瀹屾垚
+
         /// <summary>
         /// 杈撻�佺嚎浜や簰瀹屾垚
         /// </summary>
@@ -776,8 +781,8 @@
                 conveyorLine.Communicator.Write(DeviceProAddress, value);
             }
         }
-        #endregion
 
+        #endregion
 
         #region 妫�娴嬬┖鐩樺疄鐩樹换鍔�
 
@@ -851,6 +856,7 @@
 
                 // 瑙f瀽浠诲姟鏁版嵁
                 taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
+                WriteInfo("鍑哄簱", $"銆恵JsonConvert.SerializeObject(taskDTO)}銆�");
 
                 #endregion 璋冪敤WMS鑾峰彇鍑哄簱浠诲姟
 
@@ -865,6 +871,7 @@
         public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO)
         {
             var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
+            WriteInfo("鍑哄簱", $"銆恵JsonConvert.SerializeObject(content)}銆�");
             if (content.Status)
             {
                 Console.WriteLine($"{taskDTO.TargetAddress}鍛煎彨鎴愬姛");
@@ -959,8 +966,8 @@
 
         #endregion 璁惧NG鍙e叆搴�
 
-
         #region 杈撳嚭鏃ュ織
+
         public async Task LogAndWarn(string deviceName, string log, string color = "red")
         {
             ConsoleHelper.WriteWarningLine(log);
@@ -970,13 +977,11 @@
 
         #endregion
 
-
         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