From b7796f5e4d6594976ea948905af769eca863f27c Mon Sep 17 00:00:00 2001
From: helongyang <647556386@qq.com>
Date: 星期一, 07 七月 2025 15:28:15 +0800
Subject: [PATCH] 代码更新

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/阻焊仓/AGV_ZHExtend.cs |  169 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 145 insertions(+), 24 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\351\230\273\347\204\212\344\273\223/AGV_ZHExtend.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\351\230\273\347\204\212\344\273\223/AGV_ZHExtend.cs"
index 83d05a6..9d6beb7 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\351\230\273\347\204\212\344\273\223/AGV_ZHExtend.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\351\230\273\347\204\212\344\273\223/AGV_ZHExtend.cs"
@@ -9,57 +9,178 @@
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_Tasks.StackerCraneJob;
 
 namespace WIDESEAWCS_Tasks
 {
     public partial class AGV_ZHJob
     {
+        /// <summary>
+        /// 涓嬪彂浠诲姟
+        /// </summary>
         public void SendAGVTask()
         {
             try
             {
-                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.New.ObjToInt() || x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()) && nameof(AGV_PPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
-                foreach (var task in newTasks)
+                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt() && !string.IsNullOrEmpty(x.DeviceCode) && nameof(AGV_ZHJob).Contains(x.DeviceCode)).OrderByDescending(x => x.Grade).OrderBy(x => x.CreateDate).ToList();
+                if (newTasks.Count > 0)
                 {
-                    try
+                    foreach (var agvTask in newTasks)
                     {
-                        AgvTaskDTO TaskDTO = new AgvTaskDTO()
+                        try
                         {
-                            TaskCode = task.AgvTaskNum,
-                            ReqCode = DateTime.Now.ToString("yyyyMMddHHmmss") + task.AgvTaskNum,
-                            TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "FLC" : "FLR",
-                            ctnrCode = task.PalletCode,
-                            PositionCodePath = new List<CodePath>()
-                        {
+                            AgvTaskDTO taskDTO = new AgvTaskDTO()
+                            {
+                                ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
+                                TaskTyp = "22",
+                                PositionCodePath = new List<CodePath>()
+                            {
                             new CodePath()
                             {
                                 type="00",
-                                positionCode=task.CurrentAddress
+                                positionCode=agvTask.CurrentAddress
                             },
                             new CodePath()
                             {
-                                type="00",
-                                positionCode=task.NextAddress
+                                type="04",
+                                positionCode=agvTask.NextAddress
                             }
-                        },
-                        };
-                        WebResponseContent content = _taskService.AgvSendTask(TaskDTO, APIEnum.Agv_ZHSendTask);
-                        if (!content.Status) throw new Exception(content.Message);
-                        task.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
+                            },
+                                TaskCode = agvTask.AgvTaskNum,
+                                PodTyp = agvTask.PalletType < 2 ? "XX" : "DD",
+                            };
+                            WebResponseContent content = _taskService.AgvSendTask(taskDTO);
+                            if (content.Status)
+                            {
+                                agvTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
+                                //agvTask.Remark = content.Data.ObjToString();
+                                _taskService.UpdateTask(agvTask, TaskStatusEnum.AGV_Executing);
+                            }
+                            else
+                            {
+                                agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
+                                //agvTask.Remark = content.Data.ObjToString();
+                                agvTask.ExceptionMessage = content.Message;
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
+                            //agvTask.Remark = content.Data.ObjToString();
+                            agvTask.ExceptionMessage = ex.Message;
+                            WriteError(nameof(AGV_ZHJob), ex.Message, ex);
+                        }
                     }
-                    catch (Exception ex)
-                    {
-                        task.TaskState = TaskStatusEnum.Exception.ObjToInt();
-                        task.ExceptionMessage = ex.Message;
-                    }
+                    _taskService.UpdateData(newTasks);
                 }
-                _taskService.UpdateData(newTasks);
             }
             catch (Exception ex)
             {
                 WriteError(nameof(AGV_FLJob), ex.Message, ex);
             }
         }
+        /// <summary>
+        /// 涓嬪彂AGV缁х画鎵ц浠诲姟
+        /// </summary>
+        public void SendAGVWaitToTask()
+        {
+            try
+            {
+                var WaitToTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt() && nameof(AGV_ZHJob).Contains(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
+                foreach (var WaitToTask in WaitToTasks)
+                {
+                    AgvSecureReplyDTO replyDTO = new AgvSecureReplyDTO();
+                    if (WaitToTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
+                    {
+                        if (WaitToTasks.FirstOrDefault(x => x.TaskState == TaskStatusEnum.AGV_Puting.ObjToInt() || x.TaskState == TaskStatusEnum.Finish.ObjToInt()) != null)
+                        {
+                            continue;
+                        }
+                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == WaitToTask.NextAddress);
+                        if (stationManger == null)
+                        {
+                            continue;
+                        }
+                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
+                        if (device == null)
+                        {
+                            continue;
+                        }
+                        OtherDevice otherDevice = (OtherDevice)device;
+                        bool canPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode);
+                        bool requestPut = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_PutRequest, stationManger.StationCode);
+                        if (!requestPut)
+                        {
+                            otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode);
+                            continue;
+                        }
+                        else if (!canPut)
+                        {
+                            continue;
+                        }
+                        otherDevice.SetValue(GroundStationDBName.W_PutPalletType, WaitToTask.PalletType, stationManger.StationCode);
+
+                        replyDTO.ReqCode = Guid.NewGuid().ToString().Replace("-", "");//WaitToTask.TaskNum.ToString(),
+                        replyDTO.taskCode = WaitToTask.AgvTaskNum;
+                        replyDTO.nextPositionCode = new CodePath()
+                        {
+                            type="00",
+                            positionCode= stationManger.AGVStationCode
+                        };
+                    }
+                    else
+                    {
+                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == WaitToTask.CurrentAddress);
+                        if (stationManger == null)
+                        {
+                            continue;
+                        }
+                        IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
+                        if (device == null)
+                        {
+                            continue;
+                        }
+                        OtherDevice otherDevice = (OtherDevice)device;
+                        bool canTake = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanTake, stationManger.StationCode);
+                        bool requestTake = otherDevice.GetValue<GroundStationDBName, bool>(GroundStationDBName.W_TakeRequest, stationManger.StationCode);
+                        if (!requestTake)
+                        {
+                            otherDevice.SetValue(GroundStationDBName.W_TakeRequest, true, stationManger.StationCode);
+                            continue;
+                        }
+                        else if (!canTake)
+                        {
+                            continue;
+                        }
+                        replyDTO.ReqCode = Guid.NewGuid().ToString().Replace("-", "");//WaitToTask.TaskNum.ToString(),
+                        replyDTO.taskCode = WaitToTask.AgvTaskNum;
+                    }
+                    WebResponseContent content = _taskService.AgvSecureReply(replyDTO);
+                    if (content.Status && WaitToTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
+                    {
+                        WaitToTask.TaskState = TaskStatusEnum.AGV_Puting.ObjToInt();
+                        _taskService.UpdateTask(WaitToTask, TaskStatusEnum.AGV_Puting);
+                        break;
+                    }
+                    else if (content.Status && WaitToTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+                    {
+                        WaitToTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
+                        _taskService.UpdateTask(WaitToTask, TaskStatusEnum.AGV_Executing);
+                    }
+                    else
+                    {
+                        WaitToTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
+                        WaitToTask.ExceptionMessage = content.Message;
+                        _taskService.UpdateTask(WaitToTask, TaskStatusEnum.Exception);
+                    }
+                }
+                _taskService.UpdateData(WaitToTasks);
+            }
+            catch (Exception ex)
+            {
+                Console.Out.WriteLine(nameof(AGV_ZHJob) + ":" + ex.Message);
+            }
+        }
     }
 }

--
Gitblit v1.9.3