From 29f20b28392d212c04c0c40a512894f8622cfa53 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 16 四月 2025 09:32:01 +0800
Subject: [PATCH] 合并

---
 CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  147 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 95 insertions(+), 52 deletions(-)

diff --git a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index c753604..268b344 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
@@ -262,29 +256,63 @@
                     }
 
                     // 鏌ヨ骞冲彴淇℃伅
-                    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();
-                        foreach (var ite in strings)
+                        if (platform.PlatCode == "1299" || platform.PlatCode == "1295" || platform.PlatCode == "1291" || platform.PlatCode == "1287" || platform.PlatCode == "1283")
                         {
-                            // 璇诲彇浠诲姟鍛戒护
-                            ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite);
-                            if (command1.InteractiveSignal != 2)
+                            Platform platformJZ = _platFormRepository.QueryFirst(x => x.PlatCode == "10086" && x.Status == "Active");
+                            if (platformJZ != null)
                             {
-                                command.InteractiveSignal = writeInteractiveSignal;
-                                int count = strings.Count;
-                                // 鑾峰彇澶勭悊鏂规硶
-                                MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod);
-                                if (method != null)
+                                var strings = platform.Location.Split(',').ToList();
+                                foreach (var ite in strings)
                                 {
-                                    command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
-                                    // 璋冪敤澶勭悊鏂规硶
-                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
+                                    // 璇诲彇浠诲姟鍛戒护
+                                    ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite);
+                                    if (command1.InteractiveSignal != 2)
+                                    {
+                                        command.InteractiveSignal = writeInteractiveSignal;
+                                        int count = strings.Count;
+                                        // 鑾峰彇澶勭悊鏂规硶
+                                        MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod);
+                                        if (method != null)
+                                        {
+                                            command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
+                                            // 璋冪敤澶勭悊鏂规硶
+                                            method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
+                                        }
+                                        
+                                    }
                                 }
-                                ;
                             }
+                            //else
+                            //{
+                            //    //ConsoleHelper.WriteErrorLine("闈欑疆绌烘墭涓嶅厑璁稿嚭鏂�");
+                            //}
                         }
+                        else
+                        {
+                            var strings = platform.Location.Split(',').ToList();
+                            foreach (var ite in strings)
+                            {
+                                // 璇诲彇浠诲姟鍛戒护
+                                ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite);
+                                if (command1.InteractiveSignal != 2)
+                                {
+                                    command.InteractiveSignal = writeInteractiveSignal;
+                                    int count = strings.Count;
+                                    // 鑾峰彇澶勭悊鏂规硶
+                                    MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod);
+                                    if (method != null)
+                                    {
+                                        command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
+                                        // 璋冪敤澶勭悊鏂规硶
+                                        method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
+                                    }
+                                    
+                                }
+                            }
+                        } 
                     }
                     //if (conveyorLine.DeviceCode == "1001")
                     //{
@@ -329,8 +357,18 @@
                     }
                     else
                     {
-                        // 鑾峰彇浠诲姟鐨勪笅涓�鐩爣鍦板潃
-                        var next = task.NextAddress;
+                        if (task.Roadway.Contains("JZ"))
+                        {
+                            if (StaticVariable.isStackerRun)
+                            {
+                                StaticVariable.isLineRun = false;
+                                ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
+                            }
+                        }
+                        else
+                        {
+                            // 鑾峰彇浠诲姟鐨勪笅涓�鐩爣鍦板潃
+                            var next = task.NextAddress;
                         // 灏嗕换鍔℃槧灏勪负鍛戒护
                         var taskCommand = MapTaskCommand(task, command);
                         // 鎭㈠浠诲姟鐨勪笅涓�鐩爣鍦板潃
@@ -349,19 +387,28 @@
                         ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                         // 鏇存柊浠诲姟鐘舵�佷负涓嬩竴鐘舵��
                         _taskService.UpdateTaskStatusToNext(task);
+                        }
                     }
                 }
                 else
                 {
-                    // 濡傛灉浠诲姟涓虹┖涓旀潯鐮佷笉涓�"NoRead"涓旀潯鐮佷笉涓虹┖锛屽垯澶勭悊鏂颁换鍔�
-                    if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull())
+                    var taskInTray = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+                    if (taskInTray != null && taskInTray.TaskType == (int)TaskInboundTypeEnum.InTray)
                     {
-                        // 鏌ヨ鏉$爜瀵瑰簲鐨勪换鍔�
-                        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);
+                            }
                         }
                     }
                 }
@@ -370,6 +417,10 @@
             {
                 // 鎹曡幏骞惰緭鍑哄紓甯镐俊鎭�
                 Console.Out.WriteLine(ex.ToString());
+            }
+            finally
+            {
+                StaticVariable.isLineRun = true;
             }
         }
 
@@ -382,31 +433,29 @@
                 if (platform != null && !string.IsNullOrEmpty(platform.Location))
                 {
                     var Location = platform.Location.Split(',').ToList();
-                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == platform.PLCCode);
+                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == platform.DeviceCode);
                     if (device != null)
                     {
-                        int x = 3;
                         CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                         foreach (var item in Location)
                         {
-                            x--;
                             ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item);
                             if (command1.InteractiveSignal != 2)
                             {
-                                var tasks = _taskRepository.QueryData(x => (x.TaskType == (int)TaskInboundTypeEnum.InTray || x.TaskType == (int)TaskOutboundTypeEnum.OutTray) && x.TargetAddress == childDeviceCode);
+                                var tasks = _taskRepository.QueryData(x => x.TargetAddress == childDeviceCode);
 
                                 // 濡傛灉宸叉湁浠诲姟鏁伴噺灏忎簬鎸囧畾绱㈠紩
-                                if (tasks.Count < Location.Count && tasks.Count < x)
+                                if (tasks.Count < Location.Count)
                                 {
                                     return childDeviceCode;
                                 }
                                 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;
                                 }
                             }
@@ -443,11 +492,6 @@
 
             _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);
-            //}
 
             Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
             if (task != null)
@@ -470,6 +514,8 @@
                         WriteInfo(conveyorLine.DeviceName, logs);
 
                         conveyorLine.SendCommand(taskCommand, childDeviceCode);
+
+                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                     }
                 }
             }
@@ -854,7 +900,6 @@
 
                 // 瑙f瀽浠诲姟鏁版嵁
                 taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
-                WriteInfo("鍑哄簱", $"銆恵JsonConvert.SerializeObject(taskDTO)}銆�");
 
                 #endregion 璋冪敤WMS鑾峰彇鍑哄簱浠诲姟
 
@@ -869,7 +914,6 @@
         public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO)
         {
             var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
-            WriteInfo("鍑哄簱", $"銆恵JsonConvert.SerializeObject(content)}銆�");
             if (content.Status)
             {
                 Console.WriteLine($"{taskDTO.TargetAddress}鍛煎彨鎴愬姛");
@@ -911,7 +955,6 @@
 
             if (result1.Success)
             {
-                ConsoleHelper.WriteWarningLine("1");
                 var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList();
                 if (serialNosError.Count > 0)
                 {
@@ -922,7 +965,7 @@
                 //璁惧NG澶勭悊
                 if (stationManager.remark == "DeviceNG")
                 {
-                    ConsoleHelper.WriteWarningLine($"銆恵stationManager.stationChildCode}NG绔欏彴鍏ュ簱銆�");
+                    ConsoleHelper.WriteWarningLine($"銆恵stationManager.stationChildCode}NG绔欏彴瀹炴墭鍏ュ簱銆�");
                     if (result1.SerialNos.Count <= 0)
                     {
                         ConsoleHelper.WriteWarningLine("1000");
@@ -931,7 +974,7 @@
                     }
                     else
                     {
-                        ConsoleHelper.WriteWarningLine("2");
+                        ConsoleHelper.WriteWarningLine($"銆恵stationManager.stationChildCode}NG绔欏彴绌烘墭鍏ヨ澶囥��");
                         ConsoleHelper.WriteWarningLine(stationManager.stationLocation);
                         conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode);
                         conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, stationManager.stationLocation, stationManager.stationChildCode);
@@ -942,14 +985,14 @@
                 {
                     if (result1.SerialNos.Count <= 0)
                     {
-                        ConsoleHelper.WriteWarningLine("2");
+                        ConsoleHelper.WriteWarningLine($"銆恵stationManager.stationChildCode}NG绔欏彴绌烘墭鍏ュ簱銆�");
                         ConsoleHelper.WriteWarningLine(stationManager.stationLocation);
                         conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode);
                         conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, stationManager.stationLocation, stationManager.stationChildCode);
                     }
                     else
                     {
-                        ConsoleHelper.WriteWarningLine("1000");
+                        ConsoleHelper.WriteWarningLine($"銆恵stationManager.stationChildCode}NG绔欏彴瀹炴墭鍏ヨ澶囥��");
                         conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode);
                         conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, 1000, stationManager.stationChildCode);
                     }

--
Gitblit v1.9.3