From ca08d1f380987254814242e2fe3ea9de28228132 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 04 一月 2025 09:36:21 +0800
Subject: [PATCH] 代码更新

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGV/AGVExtend.cs |   96 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 80 insertions(+), 16 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGV/AGVExtend.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGV/AGVExtend.cs"
index 42a710a..0afac43 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGV/AGVExtend.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGV/AGVExtend.cs"
@@ -1,6 +1,7 @@
 锘縰sing System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection.Metadata;
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_DTO.Agv;
@@ -8,6 +9,8 @@
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_Model.Models;
+using static Dm.net.buffer.ByteArrayBuffer;
+using WIDESEAWCS_QuartzJob;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -23,11 +26,13 @@
                 var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                 foreach (var agvTask in newTasks)
                 {
-                    AgvTaskDTO taskDTO = new AgvTaskDTO()
+                    try
                     {
-                        ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
-                        TaskTyp = AgvTaskType(agvTask.TaskType, agvTask.DeviceCode),
-                        PositionCodePath = new List<CodePath>()
+                        AgvTaskDTO taskDTO = new AgvTaskDTO()
+                        {
+                            ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
+                            TaskTyp = AgvTaskType(agvTask.TaskType, agvTask.DeviceCode),
+                            PositionCodePath = new List<CodePath>()
                         {
                             new CodePath()
                             {
@@ -40,27 +45,35 @@
                                 positionCode=agvTask.NextAddress
                             }
                         },
-                        TaskCode = agvTask.AgvTaskNum,
-                        PodTyp = agvTask.PalletType < 3 ? "XX" : "DD",
-                    };
-                    WebResponseContent content = _taskService.AgvSendTask(taskDTO);
-                    if (content.Status)
-                    {
-                        agvTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
-                        //agvTask.Remark = content.Data.ObjToString();
+                            TaskCode = agvTask.AgvTaskNum,
+                            PodTyp = agvTask.PalletType < 3 ? "XX" : "DD",
+                        };
+                        WebResponseContent content = _taskService.AgvSendTask(taskDTO);
+                        if (content.Status)
+                        {
+                            agvTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
+                            //agvTask.Remark = content.Data.ObjToString();
+                        }
+                        else
+                        {
+                            agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
+                            //agvTask.Remark = content.Data.ObjToString();
+                            agvTask.ExceptionMessage = content.Message;
+                        }
                     }
-                    else
+                    catch (Exception ex)
                     {
                         agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
                         //agvTask.Remark = content.Data.ObjToString();
-                        agvTask.ExceptionMessage = content.Message;
+                        agvTask.ExceptionMessage = ex.Message;
+                        WriteError(nameof(AGVJob), ex.Message, ex);
                     }
                 }
                 _taskService.UpdateData(newTasks);
             }
             catch (Exception ex)
             {
-                Console.Out.WriteLine(nameof(AGVJob) + ":" + ex.Message);
+                WriteError(nameof(AGVJob), ex.Message, ex);
             }
         }
         /// <summary>
@@ -73,6 +86,57 @@
                 var WaitToTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt()).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                 foreach (var WaitToTask in WaitToTasks)
                 {
+                    if(WaitToTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
+                    {
+                        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;
+                        }
+                    }
+                    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;
+                        }
+                    }
+
                     AgvSecureReplyDTO replyDTO = new AgvSecureReplyDTO()
                     {
                         ReqCode = Guid.NewGuid().ToString().Replace("-", ""), //WaitToTask.TaskNum.ToString(),
@@ -114,7 +178,7 @@
                         else return "22";
                     }
                 default:
-                    throw new NotImplementedException();
+                    throw new Exception($"璁惧缂栧彿閿欒");
             }
         }
     }

--
Gitblit v1.9.3