From fd073a00f6813eada92b08f1884b115295ac1177 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 17 六月 2025 17:15:58 +0800
Subject: [PATCH] 添加版权注释

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  195 +++++++++++++++++++++++++++++-------------------
 1 files changed, 118 insertions(+), 77 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 73ce11d..b6be071 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"
@@ -16,6 +16,7 @@
 using WIDESEAWCS_Common.StackerCraneEnum;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Caches;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_IShuttleCar;
 using WIDESEAWCS_ITaskInfoRepository;
@@ -29,6 +30,7 @@
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
 using WIDESEAWCS_TaskInfoService;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
+using WIDESEAWCS_Tasks.ShuttleCarJob;
 using WIDESEAWCS_Tasks.StackerCraneJob;
 
 namespace WIDESEAWCS_Tasks
@@ -41,14 +43,16 @@
         private readonly ITaskRepository _taskRepository;
         private readonly IRouterService _routerService;
         private readonly IShuttleCarService _shuttleCarService;
+        private readonly ICacheService _cacheService;
 
-        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IShuttleCarService shuttleCarService)
+        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IShuttleCarService shuttleCarService, ICacheService cacheService)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskRepository = taskRepository;
             _routerService = routerService;
             _shuttleCarService = shuttleCarService;
+            _cacheService = cacheService;
         }
 
         public Task Execute(IJobExecutionContext context)
@@ -59,32 +63,38 @@
                 if (commonStackerCrane != null)
                 {
                     commonStackerCrane.Communicator.IsReadAfterWrite = false;
+                    #region 鑾峰彇鍫嗗灈鏈轰俊鎭�
+                    StackerCraneTaskCommandR common = ReadCustomer<StackerCraneTaskCommandR>(commonStackerCrane, commonStackerCrane.DeviceCode);
+                    _cacheService.AddOrUpdate(commonStackerCrane.DeviceCode, common);
+                    #endregion
                     #region 淇″彿浜や簰澶勭悊
                     //Heartbeat(commonStackerCrane);
                     ShuttleCarSignal(commonStackerCrane);
                     #endregion
 
                     #region 浠诲姟瀹屾垚
-                    DeviceProtocolDetailDTO? deviceProtocolDetail = commonStackerCrane.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CompleteStatus).ToString() && x.DeviceProParamName == nameof(StackerCraneTaskCommandR.CompleteStatus));
-                    if (deviceProtocolDetail != null)
+                    if (common.CompleteStatus == 2 || common.CompleteStatus == 3)
                     {
-                        MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType);
-                        if (method != null) method.Invoke(this, new object[] { commonStackerCrane });
+                        NormalCompleted(commonStackerCrane);
                     }
+                    //DeviceProtocolDetailDTO? deviceProtocolDetail = commonStackerCrane.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CompleteStatus).ToString() && x.DeviceProParamName == nameof(StackerCraneTaskCommandR.CompleteStatus));
+                    //if (deviceProtocolDetail != null)
+                    //{
+                    //    MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType);
+                    //    if (method != null) method.Invoke(this, new object[] { commonStackerCrane });
+                    //}
                     #endregion
                     #region 浠诲姟閫昏緫澶勭悊
-                    var onlinestate = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Onlinestate);
-                    var writeStatus = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WriteStatus);
-                    if (onlinestate == (short)Onlinestate.online && writeStatus == (short)WriteStatus.Permit)
+                    if (common.Onlinestate == (short)Onlinestate.online)
                     {
                         #region 鏌ヨ浠诲姟,閫昏緫澶勭悊
-                        if (Enum.Parse<RunStatus>(commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.RunStatus).ToString()) == RunStatus.Standby)
+                        if (common.RunStatus == (short)RunStatus.Standby)
                         {
-                            var Task = _taskService.GetTaskState(TaskType: (int)TaskOtherTypeEnum.RelocationCar);//鑾峰彇绉昏溅浠诲姟
-                            var Task1 = _taskService.GetTaskState((int)CarChargingTask.ShuttleCar_Finish, (int)TaskOtherTypeEnum.RelocationCarCharging);//鑾峰彇绉昏溅鍏呯數浠诲姟
+                            var Task = _taskService.GetTaskState((int)TaskCarStatusEnum.ShuttleCar_Finish, (int)TaskOtherTypeEnum.RelocationCar);//鑾峰彇绉昏溅浠诲姟
+                            var Task1 = _taskService.GetTaskState((int)CarChargingTaskEnum.CarCharging_Finish, (int)TaskOtherTypeEnum.RelocationCarCharging);//鑾峰彇绉昏溅鍏呯數浠诲姟
                             if (Task != null)
                             {
-                                if (Task.TaskState == (int)TaskCarStatusEnum.ShuttleCar_Finish) SendTask(commonStackerCrane, Task);
+                                SendTask(commonStackerCrane, Task);
                             }
                             else if (Task1 != null)
                             {
@@ -92,28 +102,55 @@
                             }
                             else
                             {
-                                Dt_Task? task = GetTask(commonStackerCrane);//鑾峰彇鍫嗗灈鏈哄嚭鍏ュ簱浠诲姟
+                                Dt_Task? task = GetTask(commonStackerCrane);//鑾峰彇鍫嗗灈鏈轰换鍔�
                                 if (task != null)
                                 {
                                     if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)//绉诲簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅
                                     {
-                                        var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//绉诲簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅
-                                        if (task.TargetIsPickPlace && ShuttleCar != null)//绉昏蛋
+                                        if (task.SourceIsPickPlace && task.TaskState == (int)TaskRelocationStatusEnum.RelocationNew)
                                         {
-                                            _taskService.AddRelocationCarTask(task.TargetAddress, "", ShuttleCar.ShuttleCarCode);
+                                            var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//绉诲簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅
+                                            if (ShuttleCar == null)
+                                            {
+                                                _taskService.AddRelocationCarTask("", task.TargetAddress);
+                                            }
+                                            else
+                                                SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔�
                                         }
-                                        else if (!task.TargetIsPickPlace && ShuttleCar == null)
+                                        else if (!task.SourceIsPickPlace && task.TaskState == (int)TaskRelocationStatusEnum.RelocationNew && task.ShuttleCarCode == null)
                                         {
-                                            _taskService.AddRelocationCarTask("", task.TargetAddress);
+                                            var ShuttleCar = GetShuttleCarInfo(task.SourceAddress);//绉诲簱浠诲姟鍒ゆ柇璧风偣鏄惁鏈夌┛姊溅
+                                            if (ShuttleCar != null)
+                                            {
+                                                task.ShuttleCarCode = ShuttleCar.ShuttleCarCode;
+                                                _taskService.UpdateData(task);
+                                            }
+                                            else _taskService.AddRelocationCarTask("", task.SourceAddress);
                                         }
-                                        else
+                                        else if (/*!task.TargetIsPickPlace &&*/ task.TaskState == (int)TaskRelocationStatusEnum.CarSource_Finish)
                                         {
-                                            task.ShuttleCarCode = ShuttleCar?.ShuttleCarCode;
-                                            _taskService.UpdateData(task);
-                                            SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔�
+                                            var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//绉诲簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅
+                                            if (task.TargetIsPickPlace && ShuttleCar != null)//绉昏蛋
+                                            {
+                                                _taskService.AddRelocationCarTask(task.TargetAddress, "", ShuttleCar.ShuttleCarCode);
+                                            }
+                                            else if (!task.TargetIsPickPlace && ShuttleCar == null)
+                                            {
+                                                _taskService.AddRelocationCarTask("", task.TargetAddress);
+                                                #region 鏌ヨ
+                                                task = _taskService.QueryCarOutFinish();
+                                                if (task != null) SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔�
+                                                #endregion
+                                            }
+                                            else
+                                            {
+                                                task.ShuttleCarCode = ShuttleCar?.ShuttleCarCode;
+                                                _taskService.UpdateData(task);
+                                                SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔�
+                                            }
                                         }
                                     }
-                                    else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
+                                    else if (_taskService.TaskInboundTypes.Contains(task.TaskType))
                                     {
                                         var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//鍏ュ簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅
                                         if (task.TargetIsPickPlace && ShuttleCar != null)//绉昏蛋
@@ -161,19 +198,11 @@
                 {
                     if (commonStackerCrane.SetValue(StackerCraneDBName.CommandSend, sendFlag))
                     {
-                        //if (task.TaskType != (int)TaskOtherTypeEnum.RelocationCar) 
-                        commonStackerCrane.LastTaskType = task.TaskType;
+                        if (_taskService.TaskInboundTypes.Contains(task.TaskType) ||
+                            _taskService.TaskOutboundTypes.Contains(task.TaskType))
+                            commonStackerCrane.LastTaskType = task.TaskType;
                         _taskService.UpdateTaskStatusToNext(task.TaskNum);
                     }
-                    //    DeviceProDTO? deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault((DeviceProDTO x) => x.DeviceProParamName == StackerCraneDBName.CommandSend.ToString());
-                    //if (deviceProDTO != null)
-                    //{
-                    //    if (commonStackerCrane.Communicator.Write<bool>(deviceProDTO.DeviceProAddress, sendFlag))
-                    //    {
-                    //        if (task.TaskType != (int)TaskOtherTypeEnum.RelocationCar) commonStackerCrane.LastTaskType = task.TaskType;
-                    //        _taskService.UpdateTaskStatusToNext(task.TaskNum);
-                    //    }
-                    //}
                 }
             }
         }
@@ -205,12 +234,8 @@
         {
             if (commonStackerCrane != null)
             {
-                //if (_taskService.GetTaskInfo(commonStackerCrane.CurrentTaskNum) != null)
-                //{
-                //Console.Out.WriteLine($"鍫嗗灈鏈轰换鍔″畬鎴愶細[{commonStackerCrane.CurrentTaskNum}]锛泏DateTime.Now}");
-                _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
-                commonStackerCrane.SetValue(StackerCraneDBName.ConfirmComplete, true);
-                //}
+                var content = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
+                commonStackerCrane.SetValue(StackerCraneDBName.ConfirmComplete, content.Status);
             }
         }
         /// <summary>
@@ -221,52 +246,68 @@
         private Dt_Task? GetTask(SpeStackerCrane commonStackerCrane)
         {
             Dt_Task task = _taskService.QueryStackerCraneRelocationTask(commonStackerCrane.DeviceCode);//鑾峰彇绉诲簱浠诲姟
-            if (task != null) return task;
-            if (commonStackerCrane.LastTaskType == null)
+            #region 瀛樺湪绉诲簱浠诲姟蹇呴』鍏堟墽琛岀Щ搴撲换鍔�
+            if (task != null)
             {
-                task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
+                return task;
+                //if (task.SourceIsPickPlace && task.ShuttleCarCode != null)
+                //    return task;
+                //else return null;
             }
+            #endregion
+
+            #region 鍑哄叆搴撲换鍔�
             else
             {
-                if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+                task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
+                if (task != null) return task;
+                if (commonStackerCrane.LastTaskType == null)
                 {
-                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode) ?? _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
-                    if (task == null)
-                    {
-                        task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
-                    }
+                    task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
                 }
                 else
                 {
-                    task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
-                    if (task == null)
+                    if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                     {
+                        task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode) ?? _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
+                        if (task == null)
+                        {
+                            task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
+                        }
+                    }
+                    else
+                    {
+                        task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode) ?? _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+                        if (task == null)
+                        {
+                            task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+                        }
+                    }
+                }
+
+                if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+                {
+                    if (OutTaskStationIsOccupied(task) != null)
+                    {
+                        return task;
+                    }
+                    else
+                    {
+                        List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList();
+                        List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes);
+                        foreach (var item in tasks)
+                        {
+                            if (OutTaskStationIsOccupied(item) != null)
+                            {
+                                return item;
+                            }
+                        }
                         task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                     }
                 }
+                if (task != null && !string.IsNullOrEmpty(task.TargetAddress)) return task;//鍏ュ簱浠诲姟鍒ゆ柇鏄惁宸插垎閰嶈揣浣嶏紝WMS鍒ゆ柇璐т綅鐘舵�佹槸鍚﹀厑璁告斁璐�
             }
-
-            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-            {
-                if (OutTaskStationIsOccupied(task) != null)
-                {
-                    return task;
-                }
-                else
-                {
-                    List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList();
-                    List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes);
-                    foreach (var item in tasks)
-                    {
-                        if (OutTaskStationIsOccupied(item) != null)
-                        {
-                            return item;
-                        }
-                    }
-                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
-                }
-            }
-            if (task != null && !string.IsNullOrEmpty(task.TargetAddress)) return task;//鍏ュ簱浠诲姟鍒ゆ柇鏄惁宸插垎閰嶈揣浣嶏紝WMS鍒ゆ柇璐т綅鐘舵�佹槸鍚﹀厑璁告斁璐�
+            #endregion
             return task;
         }
 
@@ -330,7 +371,7 @@
                     if (targetCodes.Length == 3)
                     {
                         var EndRow = Convert.ToInt16(targetCodes[0]);
-                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow);
+                        stackerCraneTaskCommand.EndRow = EndRow;// Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow);
                         stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                         stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                     }
@@ -360,7 +401,7 @@
                     if (sourceCodes.Length == 3)
                     {
                         var StartRow = Convert.ToInt16(sourceCodes[0]);
-                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(StartRow > 1 ? StartRow - 1 : StartRow);
+                        stackerCraneTaskCommand.StartRow = StartRow;// Convert.ToInt16(StartRow > 1 ? StartRow - 1 : StartRow);
                         stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                         stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                     }
@@ -383,7 +424,7 @@
                 if (targetCodes.Length == 3)
                 {
                     var EndRow = Convert.ToInt16(targetCodes[0]);
-                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow);
+                    stackerCraneTaskCommand.EndRow = EndRow;// Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow);
                     stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                     stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                 }
@@ -397,7 +438,7 @@
                 if (sourceCodes.Length == 3)
                 {
                     var SourceRow = Convert.ToInt16(sourceCodes[0]);
-                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(SourceRow > 1 ? SourceRow - 1 : SourceRow);
+                    stackerCraneTaskCommand.StartRow = SourceRow;// Convert.ToInt16(SourceRow > 1 ? SourceRow - 1 : SourceRow);
                     stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                     stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                 }

--
Gitblit v1.9.3