From 6db89a97e81e6c26bb2d2ccb3db79ed8858462a2 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期四, 17 七月 2025 20:38:16 +0800
Subject: [PATCH] 优化异常库位出库功能

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |   76 ++++++++++++++++++++++++++++++++++----
 1 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
index c3c0fc5..5d5f6c9 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -39,6 +39,8 @@
         private readonly IDt_StationManagerRepository _stationManagerRepository;
         private readonly ITask_HtyRepository _htyRepository;
         private readonly ISys_ConfigService _sys_ConfigService;
+        private static List<string>? userTokenIds;
+        private static List<int>? userIds;
 
         public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository htyRepository, ISys_ConfigService sys_ConfigService)
         {
@@ -85,6 +87,8 @@
                                     if (taskNum == 0)
                                     {
                                         ConsoleHelper.WriteColorLine($"銆恵commonStackerCrane.DeviceName}銆戜换鍔″彿涓恒�恵0}銆�,浠诲姟鍙蜂笉涓�鑷村彲浠ヤ笅鍙戜换鍔�", ConsoleColor.DarkBlue);
+
+                                        Thread.Sleep(1000);
                                         bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                         if (sendFlag)
                                         {
@@ -98,6 +102,8 @@
                                             builder.AppendLine();
                                             ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
                                             commonStackerCrane.LastTaskType = task.TaskType;
+
+
                                             _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                         }
                                     }
@@ -156,12 +162,32 @@
             {
                 if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
                 {
-                    string str = $"銆恵commonStackerCrane.DeviceName}銆戜换鍔″畬鎴�,浠诲姟鍙凤細銆恵e.TaskNum}銆�";
+                    ConsoleHelper.WriteColorLine($"銆恵commonStackerCrane.DeviceName}銆戝爢鍨涙満浣滀笟鐘舵�侊細銆恵(int)commonStackerCrane.StackerCraneWorkStatusValue}銆戞椂闂淬�恵DateTime.Now}銆�", ConsoleColor.Magenta);
+
+                    string str = $"銆恵commonStackerCrane.DeviceName}銆戜换鍔″畬鎴�,浠诲姟鍙凤細銆恵e.TaskNum}銆戞椂闂淬�恵DateTime.Now}銆�";
                     WriteInfo(commonStackerCrane.DeviceName, str);
                     ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                     var task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
 
                     if (task == null) commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+
+                    if (commonStackerCrane.DeviceCode.Contains("CW") && task.TaskType==(int)TaskOutboundTypeEnum.InToOut)
+                    {
+                        var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1017" && x.stationType == 10 && x.Roadway == commonStackerCrane.DeviceCode);
+
+                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationinfo.stationPLC);
+                        if (device != null)
+                        {
+                            CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device;
+                            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(1815), stationinfo.stationChildCode);
+                            Thread.Sleep(100);
+                            conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, 1000, stationinfo.stationChildCode);
+                        }
+                        WriteInfo(commonStackerCrane.DeviceName, $"銆愭墜鍔ㄥ嚭搴撹褰曘��");
+                    }
+
+
+
 
                     if (commonStackerCrane.DeviceCode.Contains("GW") && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                     {
@@ -190,15 +216,16 @@
                     {
                         task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
                         Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
+                        _taskService.UpdateData(newTask);
                     }
-                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && (task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001"))
+                    if ((task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && (task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001"))|| task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm)
                     {
                         var TASKHTY = task.Adapt<Dt_Task_Hty>();
                         _taskRepository.DeleteData(task);
                         _htyRepository.AddData(TASKHTY);
                     }
                     var isWorkType = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
-                    str = $"WMS|WCS浠诲姟瀹屾垚锛氥�恵content.Status}銆�,鍫嗗灈鏈哄畬鎴愪俊鍙峰啓鍏ワ細銆恵isWorkType}銆�,浠诲姟鍙凤細銆恵e.TaskNum}銆�,鎵樼洏鍙凤細銆恵task.PalletCode}銆�";
+                    str = $"{commonStackerCrane.DeviceName}銆慦MS|WCS浠诲姟瀹屾垚锛氥�恵content.Status}銆�,鍫嗗灈鏈哄畬鎴愪俊鍙峰啓鍏ワ細銆恵isWorkType}銆�,浠诲姟鍙凤細銆恵e.TaskNum}銆戞椂闂淬�恵DateTime.Now}銆�";
                     WriteInfo(commonStackerCrane.DeviceName, str);
                     ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                 }
@@ -213,6 +240,12 @@
         private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
         {
             Dt_Task task;
+            task = _taskService.QueryOutFireAlarmTask(commonStackerCrane.DeviceCode);
+            if (task != null)
+            {
+                return task;
+            }
+
             if (commonStackerCrane.LastTaskType == null)
             {
                 task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
@@ -241,19 +274,30 @@
                 if (occupiedStation == null)
                 {
                     // 濡傛灉褰撳墠鍑哄簱浠诲姟绔欏彴涓嶅厑璁告斁璐э紝鎺掗櫎褰撳墠浠诲姟锛屾煡鎵惧叾浠栧嚭搴撲换鍔�
-                    ConsoleHelper.WriteErrorLine($"浠诲姟鍙凤細銆恵task.TaskNum}銆戝嚭搴撳湴鍧�锛氥�恵task.NextAddress}銆戜笉鍏佽鏀捐揣");
+
+                    var log = $"浠诲姟鍙凤細銆恵task.TaskNum}銆戝嚭搴撳湴鍧�锛氥�恵task.NextAddress}銆戜笉鍏佽鏀捐揣";
+                    ConsoleHelper.WriteErrorLine(log);
+
+                    _noticeService.Logs(userTokenIds, new { commonStackerCrane.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
+                    WriteInfo(commonStackerCrane.DeviceName, log);
+
                     task = FindAnotherOutboundTask(commonStackerCrane.DeviceCode, task.TaskId);
+
+                    if (task == null)
+                    {
+                        task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+                    }
                 }
                 else
                 {
                     return task;
                 }
+
             }
             else if (task == null)
             {
                 task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
             }
-
             return task;
         }
 
@@ -368,7 +412,11 @@
                 {
                     return candidateTask;
                 }
-                ConsoleHelper.WriteErrorLine($"浠诲姟鍙凤細銆恵candidateTask.TaskNum}銆戝嚭搴撳湴鍧�锛氥�恵candidateTask.NextAddress}銆戜笉鍏佽鏀捐揣");
+                var log = $"浠诲姟鍙凤細銆恵candidateTask.TaskNum}銆戝嚭搴撳湴鍧�锛氥�恵candidateTask.NextAddress}銆戜笉鍏佽鏀捐揣";
+                ConsoleHelper.WriteErrorLine(log);
+
+                _noticeService.Logs(userTokenIds, new { deviceCode, log = log, time = DateTime.Now.ToString("G"), color = "red" });
+                WriteInfo(deviceCode, log);
             }
 
             return null;
@@ -389,6 +437,7 @@
             stackerCraneTaskCommand.WorkType = 1;
             stackerCraneTaskCommand.TrayType = 0;
             stackerCraneTaskCommand.StartCommand = 1;
+            stackerCraneTaskCommand.FireCommand = Convert.ToInt16(task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm ? 2 : 0);
             if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
             {
                 var value = _sys_ConfigService.GetByConfigKey(CateGoryConst.CONFIG_SYS_InStation, SysConfigKeyConst.JZNGInBoundStation).ConfigValue;
@@ -454,7 +503,7 @@
             }
             else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
             {
-                if (task.Roadway.Contains("GW"))
+                if (task.Roadway.Contains("GW")|| task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm)
                 {
                     string[] endCodes = task.NextAddress.Split("-");
                     stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]);
@@ -467,7 +516,18 @@
                 }
                 else
                 {
-                    if (task.TargetAddress == "002-021-001" && task.Roadway.Contains("JZ") && task.TaskType == (int)TaskOutboundTypeEnum.OutTray)
+                    if ( task.TaskType == (int)TaskOutboundTypeEnum.InToOut)
+                    {
+                        string[] endCodes = task.TargetAddress.Split("-");
+                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]);
+                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(endCodes[1]);
+                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(endCodes[2]);
+                        string[] sourceCodes = task.SourceAddress.Split("-");
+                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
+                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
+                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
+                    }
+                    else if (((task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001") && task.Roadway.Contains("JZ")) || task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm)
                     {
                         string[] endCodes = task.NextAddress.Split("-");
                         stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]);

--
Gitblit v1.9.3