From 16749e23b489ee24f993fe9e87346680b7bcf63a Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期五, 10 十月 2025 21:14:49 +0800
Subject: [PATCH] 代码提交

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  118 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 71 insertions(+), 47 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
index 38fd11b..4eec051 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
@@ -37,12 +37,12 @@
         private readonly ICacheService _cacheService;
         private readonly INoticeService _noticeService;
         private readonly IDt_StationManagerRepository _stationManagerRepository;
-        private readonly ITask_HtyRepository _htyRepository;
+        private readonly ITask_HtyRepository _task_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, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository htyRepository, ISys_ConfigService sys_ConfigService)
+        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository task_htyRepository, ISys_ConfigService sys_ConfigService)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
@@ -51,7 +51,7 @@
             _cacheService = cacheService;
             _noticeService = noticeService;
             _stationManagerRepository = stationManagerRepository;
-            _htyRepository = htyRepository;
+            _task_htyRepository = task_htyRepository;
             _sys_ConfigService = sys_ConfigService;
         }
 
@@ -233,29 +233,39 @@
                     var task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
 
                     if (task == null) commonStackerCrane.SetValue(StackerCraneDBName.FinishConfirm, 1);
-                    string x = $"銆恵commonStackerCrane.StackerCraneWorkStatusValue}銆�";
-
-                    //if(task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-                    //{
-                    //    CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1001") as CommonConveyorLine;
-                    //    if (conveyorLine != null)
-                    //    {
-                    //        short InteractiveSignal = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, "101");
-                    //        var structs = BitConverter.GetBytes(InteractiveSignal).Reverse().ToArray().ToBoolArray();
-                    //        if (structs[0])
-                    //        {
-                    //            conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, "9999", "101");
-                    //        }
-                    //    }
-                    //}
+                    string WorkStatus = $"銆恵commonStackerCrane.StackerCraneWorkStatusValue}銆�";
 
                     var content = _taskService.StackCraneTaskCompleted(e.TaskNum);
+
+                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+                    {
+                        CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1001") as CommonConveyorLine;
+                        if (conveyorLine != null)
+                        {
+                            short InteractiveSignal = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, "LK001");
+                            var structs = BitConverter.GetBytes(InteractiveSignal).Reverse().ToArray().ToBoolArray();
+                            if (structs[0])
+                            {
+                                bool x = conveyorLine.Communicator.WriteNoRead("DB100.0", 9999);
+                                if (!x)
+                                {
+                                    return;
+                                }
+                            }
+                        }
+                        var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress);
+                        if (station != null)
+                        {
+                            _taskService.SendAgvTask(station.stationRemark, task.TaskNum);
+                            _taskService.UpdateTaskStatusToNext(task.TaskNum);
+                        }
+                    }
 
                     var isWorkType = commonStackerCrane.SetValue(StackerCraneDBName.FinishConfirm, 1);
 
 
                     str = $"{commonStackerCrane.DeviceName}銆慦MS|WCS浠诲姟瀹屾垚锛氥�恵content.Status}{content.Message}銆�,鍫嗗灈鏈哄畬鎴愪俊鍙峰啓鍏ワ細銆恵isWorkType}銆�,浠诲姟鍙凤細銆恵e.TaskNum}銆戞椂闂淬�恵DateTime.Now}銆�";
-                    WriteInfo(commonStackerCrane.DeviceName, str+x);
+                    WriteInfo(commonStackerCrane.DeviceName, str + WorkStatus);
                     ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                 }
             }
@@ -298,30 +308,44 @@
 
             if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
             {
-                //    // 妫�鏌ュ綋鍓嶅嚭搴撲换鍔$珯鍙版槸鍚﹀厑璁告斁璐�
-                //    var occupiedStation = OutTaskStationIsOccupied(task);
-                //    if (occupiedStation == null)
-                //    {
-                //        // 濡傛灉褰撳墠鍑哄簱浠诲姟绔欏彴涓嶅厑璁告斁璐э紝鎺掗櫎褰撳墠浠诲姟锛屾煡鎵惧叾浠栧嚭搴撲换鍔�
-
-                //        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;
-                //    }
-                return task;
+                var InTask = _taskRepository.QueryFirst(x => x.TaskState > (int)TaskInStatusEnum.InNew && x.TaskState< (int)TaskInStatusEnum.SC_InExecuting);
+                var OutTask = _taskRepository.QueryFirst(x => x.TaskState > (int)TaskOutStatusEnum.OutNew && x.TaskState < (int)TaskOutStatusEnum.AGV_OutExecuting);
+                if (InTask != null)
+                {
+                    return null;
+                }
+                else if (OutTask != null)
+                {
+                    return null;
+                }
+                else
+                {
+                    CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x=>x.DeviceCode =="1001") as CommonConveyorLine;
+                    if (conveyorLine != null)
+                    {
+                        short InteractiveSignal = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, "LK001");
+                        var structs = BitConverter.GetBytes(InteractiveSignal).Reverse().ToArray().ToBoolArray();
+                        if (structs[0] && !structs[2] && !structs[1])
+                        {
+                            conveyorLine.Communicator.WriteNoRead("DB100.0", 9990);
+                        }
+                        if (structs[0] && structs[2])
+                        {
+                            conveyorLine.Communicator.WriteNoRead("DB100.0", 9990);
+                            return task;
+                        }
+                        else
+                        {
+                            task.ExceptionMessage = "璇锋鏌ヨ緭閫佺嚎鏄惁鏄嚜鍔ㄦā寮忔垨宸茬粡绉诲姩鍒板嚭搴撳彛";
+                            return null;
+                        }
+                    }
+                    else
+                    {
+                        task.ExceptionMessage = "杈撻�佺嚎璁惧鏂紑杩炴帴";
+                        return null;
+                    }
+                }   
             }
             else if (task == null)
             {
@@ -412,7 +436,8 @@
             stackerCraneTaskCommand.StartCommand = Convert.ToInt16(1);
             if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
             {
-                string[] sourceCodes = task.CurrentAddress.Split("-");
+                var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.stationChildCode == task.CurrentAddress);
+                string[] sourceCodes = station.stationLocation.Split("-");
                 if (sourceCodes.Length == 3)
                 {
                     stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2;
@@ -425,7 +450,6 @@
                     _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍑哄簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
                     return null;
                 }
-
                 string[] targetCodes = task.NextAddress.Split("-");
                 if (targetCodes.Length == 3)
                 {
@@ -455,8 +479,8 @@
                     _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍑哄簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
                     return null;
                 }
-
-                string[] targetCodes = task.NextAddress.Split("-");
+                var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.stationChildCode == task.NextAddress);
+                string[] targetCodes = station.stationLocation.Split("-");
                 if (targetCodes.Length == 3)
                 {
                     stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2;

--
Gitblit v1.9.3