From 0e022ecccc0cccd486df4cd208658c332ddbdf3b Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期一, 20 十月 2025 19:58:45 +0800
Subject: [PATCH] 1

---
 代码管理/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs | 1287 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 894 insertions(+), 393 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs"
index 9438dc7..6790f09 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs"
@@ -3,6 +3,7 @@
 using Microsoft.AspNetCore.Hosting;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using Quartz;
 using System;
 using System.Collections;
@@ -11,7 +12,9 @@
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.Eventing.Reader;
 using System.Linq;
+using System.Net;
 using System.Reflection.Metadata;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Common.Log;
@@ -56,9 +59,6 @@
             _agvStationService = agvStationService;
         }
 
-        public string ziche001 = "RGV104";
-        public string ziche002 = "RGV107";
-
 
         public Task Execute(IJobExecutionContext context)
         {
@@ -69,39 +69,52 @@
                 {
                     GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
 
-                    //璇诲彇璁惧瀹屾垚淇℃伅
-                    if (getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Completed && getStackerObject.CurrentRgvtaskid!=0)
+                    if (getStackerObject.RGVInitializationValue == RGVInitialize.Initialized)
                     {
-                        _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid);
-                    }
-                    
-
-                    if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
-                        getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
-                    {
-
-                        //涓嬪彂RGV浠诲姟涔嬪墠锛屽厛璇诲彇涓�涓嬪畨鍏ㄩ棬鐘舵��
-
-
-
-                        //鏌ユ壘RGV杩涜涓嬪彂浠诲姟
-                        Dt_Task task = GetTask(speStackerCrane.DeviceCode);
-                        if (task != null)
+                        //璇诲彇璁惧瀹屾垚淇℃伅
+                        if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Completed || getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.AbnormalCompletion)
                         {
-                            //璋冨彇鍐欏叆RGV灏忚溅浠诲姟
-                            RgvCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
-                            bool sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand);
-                            if (sendFlag)
-                            {
-                                //淇敼浠诲姟鐘舵��
-                                _taskService.UpdateTaskStatusToNext(task);
-                            }
+                            CommonStackerCrane_AGVTaskCompletedEventHandler(getStackerObject, speStackerCrane);
                         }
 
+                        if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
+                        getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
+                        {
+                            //鏌ユ壘RGV杩涜涓嬪彂浠诲姟
+                            Dt_Task task = GetTask(speStackerCrane.DeviceCode, getStackerObject);
+                            if (task != null)
+                            {
+                                //璋冨彇鍐欏叆RGV灏忚溅浠诲姟
+                                RgvCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
+                                if (stackerCraneTaskCommand != null)
+                                {
+                                    bool sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand);
+                                    if (sendFlag)
+                                    {
+                                        //淇敼浠诲姟鐘舵��
+                                        _taskService.UpdateTaskStatusToNext(task);
+                                    }
+                                }
+
+                            }
+                            else
+                            {
+                                if (GetDeviceAddress.OutbounMotherChildCartbool(speStackerCrane.DeviceCode))
+                                {
+                                    //褰撴病浠诲姟鐨勬椂鍊欙紝鍒欒繘琛岀Щ鍔�
+                                    Returnposition(speStackerCrane.DeviceCode, getStackerObject.RGVCurrentlocation, (int)getStackerObject.RgvCraneStatusValue);
+
+                                }
+                                else if (GetDeviceAddress.OutbounMotherChildCartbool2(speStackerCrane.DeviceCode))
+                                {
+                                    InReturnposition(speStackerCrane.DeviceCode, getStackerObject.RGVCurrentlocation, (int)getStackerObject.RgvCraneStatusValue);
+                                }
+
+                            }
+                        }
                     }
+
                 }
-
-
             }
             catch (Exception ex)
             {
@@ -110,361 +123,853 @@
             return Task.CompletedTask;
         }
 
-        /// <summary>
-        /// 鑾峰彇浠诲姟锛堟殏鏃舵柟娉昳f鍒ゆ柇锛�
-        /// </summary>
-        /// <param name="DeviceCode"></param>
-        /// <param name="RGVCurrentlocation"></param>
-        /// <returns></returns>
-        private Dt_Task? GetTask(string DeviceCode)
+        #region 浠诲姟瀹屾垚
+        private void CommonStackerCrane_AGVTaskCompletedEventHandler(GetStackerObject getStackerObject, SpeStackerCrane speStackerCrane)
         {
-            Dt_Task task;
-            task = _taskService.QueryStackerCraneTask(DeviceCode);
-            if (task != null)
+            if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Completed && getStackerObject.CurrentRgvtaskid == 30001)
             {
-                //鍒ゆ柇鍏ュ簱浠诲姟
-                if(task.TaskType== (int)TaskInboundTypeEnum.Inbound)
-                {
-                    if(task.TaskState== (int)TaskInStatusEnum.RGV_InNew)
-                    {
-                        return task;
-                    }else if(task.TaskState== (int)TaskInStatusEnum.RGV_InPickupFinish) //鍙栬揣瀹屾垚鍚庯紝杩涜鏀捐揣鐨勬祦绋�
-                    {
-                        //鍒ゆ柇璇CJ鏄惁鍙斁璐�
-                        bool Currebool = QueryCurrentAdder(task); //鍒ゆ柇HCJ鏄惁鍙互鏀捐揣
-                        if (Currebool)
-                        {
-                            return task;
-                        }
-                        else { return null; }
-                    }else if (task.TaskState == (int)TaskInStatusEnum.RGV_InReleaseFinish) //鏀捐揣瀹屾垚鍚庯紝杩涜瀛愯溅鍙栬揣娴佺▼
-                    {
-                        //榛樿瀛愯溅鍦ㄥ彇璐х殑鍦版柟
-                        return task;
-                    }
-                    else if (task.TaskState == (int)TaskInStatusEnum.RGV_InZicheFinish) //瀛愯溅鍙栬揣瀹屾垚鍚庯紝杩涜鏀捐揣娴佺▼
-                    {
-                        //鑾峰彇闇�瑕佹斁璐х殑绔欏彴
-                        AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));   //鑾峰彇鍒拌繃閬撶珯鍙版斁璐т俊鎭�
-                        if (aGVStation.Station_Area == 1)   //琛ㄧず鍦ㄥ娴�
-                        {
-                            bool muchebool=MotherCarMoves(task, aGVStation);
-                            if (muchebool)
-                            {
-                                return task;
-                            }else { return null; }
-                        }
-                        else if(aGVStation.Station_Area == 2)   //琛ㄧず鍦ㄥ唴渚�
-                        {
-                            bool muchebool = MotherCarMovesinside(task, aGVStation);
-                            if (muchebool)
-                            {
-                                return task;
-                            }
-                            else { return null; }
-                        }else if (aGVStation.Station_Area == 3)     //鏀惧湪杩囬亾HCJ
-                        {
-                            bool muchebool = HCJMotherCarMovesinside(task, aGVStation);
-                            if (muchebool)
-                            {
-                                return task;
-                            }
-                            else { return null; }
-                        }
-                    }else if (task.TaskState == (int)TaskInStatusEnum.RGV_InZicheReleaseFinish) //瀛愯溅鏀捐揣瀹屾垚
-                    {
-                        AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));
-                        if(aGVStation.Station_Area == 1)
-                        {
-                            return task;
-                            /*RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(task, "1021");
-                            bool sendFlag = SendCommand2(standardCommands, ziche001);
-                            if (sendFlag)
-                            {
-                                //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                                _taskService.UpdateTaskStatusToNext(task);
-                            }*/
-                        }
-                        else if (aGVStation.Station_Area == 2)      
-                        {
-                            RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(task, "1021");   //娉ㄦ剰锛氾細锛氾細璇ュ瓙杞﹂渶瑕佸緟瀹氬幓鍚�
-                            bool sendFlag = SendCommand2(standardCommands, ziche002);
-                            if (sendFlag)
-                            {
-                                //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                                _taskService.UpdateTaskStatusToNext(task);
-                            }
-                        }
+                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 1);
+                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 0);
+            }
+            else if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Completed && getStackerObject.CurrentRgvtaskid != 0 && getStackerObject.CurrentRgvtaskid != 30001)
+            {
+                _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid);   //姝e父浠诲姟瀹屾垚
+                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 1);
+                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 0);
+            }
+            else if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.AbnormalCompletion && getStackerObject.CurrentRgvtaskid != 0 && getStackerObject.CurrentRgvtaskid != 30001)
+            {
+                //鍐欏叆寮傚父瀹屾垚鎶ヨ淇℃伅
+                speStackerCrane.Communicator.Write<short>("DB101.36", 1);
+            }
+        }
+        #endregion
 
-                        //杩涜绉诲姩瀛愯溅
 
-                    }
-                    else if(task.TaskState == (int)TaskInStatusEnum.RGV_InZichemoveFinish) //瀛愯溅绉诲姩瀹屾垚鍚庯紝杩涜
-                    {
-                        //鑾峰彇闇�瑕佹斁璐х殑绔欏彴
-                        AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));   //鑾峰彇鍏ュ簱绔欏彴淇℃伅
-                        if (aGVStation.Station_Area == 1)   //鍏ュ簱鍙e尯鍩熺殑1琛ㄧず鍐欏叆鍥哄畾鐨�1鍙峰瓙杞�104
-                        {
-                            //鍒ゆ柇瀛愯溅鍦ㄥ摢涓綅缃�
-                            int zicheadder = GetZichelocation(task, ziche001);
-                            if(zicheadder!= int.Parse(aGVStation.ZicheMotherinlaw))
-                            {
-                                return task;
-                            }
-                        }
-                        else if(aGVStation.Station_Area == 2)      //鍏ュ簱鍙e尯鍩熺殑1琛ㄧず鍐欏叆鍥哄畾鐨�1鍙峰瓙杞�107
-                        {
-                            int zicheadder = GetZichelocation(task, ziche002);
-                            if (zicheadder != int.Parse(aGVStation.ZicheMotherinlaw))
-                            {
-                                return task;
-                            }
-                        }
-                    }
-                }
-                else if(task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+
+        private Dt_Task? GetTask(string DeviceCode, GetStackerObject getStackerObject)
+        {
+            // 鏍规嵁璁惧鍚嶇О锛岃幏鍙栧埌璁惧鐩稿叧鏁版嵁
+            AGVStation RGVTaskdevice = _agvStationService.Corridorequipment(DeviceCode);   //鏍规嵁璁惧鑾峰彇鍒板唴瀹�
+            return RGVTaskdevice.Station_tasktype switch
+            {
+                (int)RGVTasktype.Inbound => HandleInboundTask(RGVTaskdevice, getStackerObject),
+                (int)RGVTasktype.Outbound => OutboundEquipmentTask(RGVTaskdevice, getStackerObject),    //鍑哄簱
+                _ => null
+            };
+
+
+        }
+
+        #region 鍏ュ簱鏂规硶
+        private Dt_Task? HandleInboundTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
+        {
+            return (RGVTaskdevice.Station_material, getStackerObject.RgvCraneStatusValue) switch
+            {
+                ((int)RGVEquipment.InRGVForklift, RgvEquipmentStatus.NoCargo)   //鍙夎溅寮廟GV鏃犺揣,涓嬪彂鍙栬揣浠诲姟
+                    => _taskService.PickupWarehouse(RGVTaskdevice.ChildPosiDeviceCode),
+
+                ((int)RGVEquipment.InRGVForklift, RgvEquipmentStatus.HasCargo)
+                    => ForkliftUnloading(RGVTaskdevice),    //鍙夎溅寮忚繘琛屾斁璐э紙宸插畬鎴愶級
+
+                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.NoCargo)
+                    => ZichePickUpAisle(RGVTaskdevice, getStackerObject),   //杩囬亾瀛愯溅杩涜鍙栬揣锛堝凡瀹屾垚锛�
+
+                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.HasCargo)
+                    => GoodsPlacedCorridor(RGVTaskdevice),    //瀛愯溅鏀捐揣浠诲姟(宸插畬鎴�)
+
+                ((int)RGVEquipment.Mothertrailer, RgvEquipmentStatus.HasCargo)
+                    => MotherVehicleMovement(RGVTaskdevice),        //锛堝凡瀹屾垚锛�
+
+                _ => null
+            };
+
+        }
+
+        #region 鍙夎溅寮忚繘琛屾斁璐э紙宸插畬鎴愶級
+        public Dt_Task? ForkliftUnloading(AGVStation RGVTaskdevice)
+        {
+            Dt_Task dt_Task = _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode);
+
+            //鍒ゆ柇HCJ鏄惁鏈夎揣
+            if (GetDeviceAddress.HCJIsstock(dt_Task.NextAddress))
+            {
+                //鍒ゆ柇瀛愯溅鏄惁鍦ㄦ帴椹冲彴涓�
+                var zichestation = _agvStationService.OutGetZicheDeepHCJ(1061);
+                int ziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+                if ((ziche == zichestation.WaitmomentOne || ziche == zichestation.WaitmomentTwo || ziche == zichestation.MotherCarDeviceCode || ziche == zichestation.MotherCardeputy || ziche == zichestation.HCJStorageaddress) && ziche != 1021)
                 {
-                    if (task.TaskState == (int)TaskOutStatusEnum.OutNew)
+                    //鑾峰彇杩欎釜鎺ラ┏鍙版槸鍚︽湁鍙栬揣浠诲姟
+                    Dt_Task zitask = _taskService.ViceChariotPickupTask2(RGVTaskdevice.ChildPosiDeviceCode);
+                    if (zitask == null)
                     {
-                        return task;
-                    }else if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutMothercarFinish)
-                    {
-                        return task;
-                    }
-                    else if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutZicheFinish)
-                    {
-                        return task;
-                    }else if(task.TaskState == (int)TaskOutStatusEnum.RGV_OutZicheReleaseFinish)
-                    {
-                        return task;
-                    }else if(task.TaskState == (int)TaskOutStatusEnum.RGV_OutPickupFinish && task.CurrentAddress != "")
-                    {
-                        return task;
+
+                        return dt_Task;
                     }
                 }
             }
+            return null;
+        }
+        #endregion
 
+        #region 杩囬亾瀛愯溅杩涜鍙栬揣锛堝凡瀹屾垚锛�
+        public Dt_Task? ZichePickUpAisle(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
+        {
+            //鑾峰彇瀛愯溅鍙栬揣浠诲姟
+            Dt_Task dt_Task = _taskService.ViceChariotPickupTask(RGVTaskdevice.ChildPosiDeviceCode);
+            if (dt_Task == null) return null;
+            if (RGVTaskdevice.Station_Area == 6)    //澶栦晶杩涘彇璐э紝鍒欓渶瑕佸垽鏂瓙杞﹀綋鍓嶄綅缃�
+            {
+                if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentOne)
+                {
+                    //杩橀渶瑕佸垽鏂叆搴撳彛鍙夎溅鏄惁鏀跺洖鍙夎溅浜�
+
+                    //鍦ㄧ瓑寰呯偣1锛屽垯闇�瑕佸垽鏂�1鍙锋瘝杞﹀湪鍫嗗灈鏈哄彇璐у彛
+                    var mu1rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
+                    int mu1 = GetDeviceAddress.GetEquipmentlocation(mu1rgv.ChildPosiDeviceCode); //姝ゆ椂鐨凴GV搴旇鏃犺揣
+                    bool ywh = GetDeviceAddress.Mucheywhaddres(mu1rgv.ChildPosiDeviceCode);
+                    if (mu1 == mu1rgv.Motherinlaw || (ywh && mu1 == mu1rgv.ZicheMotherinlaw))   //鍦ㄥ爢鍨涙満鍙栬揣鍙�
+                    {
+                        //=============================鏂板褰撳幓鍙栬揣鏃惰繘琛屽垽鏂贩閬擄紝鐪嬭兘涓嶈兘鎻愬墠鎷夊嚭姣嶈溅
+                        if (int.Parse(dt_Task.TargetAddress) == (int)StorageAisleEnum.LaneTwo)
+                        {
+                            int taraddress = int.Parse(dt_Task.TargetAddress);
+                            var InMotherVehicle = _agvStationService.ObtainCcordingTunnel(taraddress);    //鑾峰彇鍒伴渶瑕佸叆搴撶殑姣嶈溅(2宸烽亾)
+                            int mu2 = GetDeviceAddress.GetEquipmentlocation(InMotherVehicle.ChildPosiDeviceCode); //姝ゆ椂鐨凴GV搴旇鏃犺揣
+                            if (GetDeviceAddress.Mucheywhaddres(InMotherVehicle.ChildPosiDeviceCode))   //鍒ゆ柇鏃犺揣
+                            {
+                                if (mu2 == InMotherVehicle.ZicheMotherinlaw)
+                                {
+                                    return dt_Task;
+                                }
+                                else if (mu2 == InMotherVehicle.Motherinlaw)
+                                {
+                                    RGVMovetask(InMotherVehicle.ZicheMotherinlaw, InMotherVehicle.ChildPosiDeviceCode);
+                                }
+                            }
+                        }
+                        //=============================鏂板褰撳幓鍙栬揣鏃惰繘琛屽垽鏂贩閬擄紝鐪嬭兘涓嶈兘鎻愬墠鎷夊嚭姣嶈溅
+                        return dt_Task;
+                    }
+                    //鍘绘帀鍘熷洜锛氬湪璇ュ嚭瀛愯溅鍘诲彇璐э紝鍙洿鎺ョ┛杩囨棤璐ф瘝杞︼紝鎷栬溅
+                    /*else 
+                    {
+                        Dt_Task task = _taskService.MothermachinemovementTask2(RGVTaskdevice.ChildPosiDeviceCode);
+                        if (task == null)
+                        {
+                            RGVMovetask(mu1rgv.Motherinlaw, mu1rgv.ChildPosiDeviceCode);
+                        }
+                    }*/
+
+                }
+                else if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentTwo)    //鍒欓渶瑕佸垽鏂袱涓瘝杞︾殑浣嶅瓙
+                {
+                    //鍒ゆ柇涓や釜瀛愯溅鏄惁鍦ㄥ爢鍨涙満鍙栬揣鍙�
+
+                    //姣嶈溅1
+                    var mu1rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
+                    int mu1 = GetDeviceAddress.GetEquipmentlocation(mu1rgv.ChildPosiDeviceCode); //姝ゆ椂鐨凴GV搴旇鏃犺揣
+                    bool m1Isitstock1 = GetDeviceAddress.Mucheywhaddres(mu1rgv.ChildPosiDeviceCode);
+
+                    var mu2rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCardeputy);
+                    int mu2 = GetDeviceAddress.GetEquipmentlocation(mu2rgv.ChildPosiDeviceCode); //姝ゆ椂鐨凴GV搴旇鏃犺揣
+                    bool m1Isitstock2 = GetDeviceAddress.Mucheywhaddres(mu2rgv.ChildPosiDeviceCode);
+
+                    // 鎻愬彇鍙鎬у彉閲�
+                    bool mu1AtHome = mu1 == mu1rgv.Motherinlaw;
+                    bool mu2AtHome = mu2 == mu2rgv.Motherinlaw;
+                    bool mu1Ready = mu1 == mu1rgv.ZicheMotherinlaw && m1Isitstock1;
+                    bool mu2Ready = mu2 == mu2rgv.ZicheMotherinlaw && m1Isitstock2;
+
+                    // 鍚堝苟鎵�鏈夋弧瓒虫潯浠剁殑鎯呭喌
+                    if ((mu1AtHome && mu2AtHome) ||        // 閮藉湪鍒濆浣嶇疆
+                        (mu1Ready && mu2Ready) ||          // 閮藉湪灏辩华浣嶇疆涓旀棤璐�
+                        (mu1AtHome && mu2Ready) ||         // 1鍦ㄥ垵濮嬩綅缃紝2灏辩华
+                        (mu1Ready && mu2AtHome))           // 1灏辩华锛�2鍦ㄥ垵濮嬩綅缃�
+                    {
+                        return dt_Task;
+                    }
+
+                    /*else
+                    {
+                        //鏃犻渶鎶婃瘝杞︾Щ鍔ㄨ嚦鍙栬揣鍙�,鏃犺揣鐘舵�佺殑瀛愯溅鏃犻渶韪╂墭鐩樿繃鍘诲幓鍙栬揣
+                        if (mu1 != mu1rgv.Motherinlaw)
+                        {
+                            Dt_Task task = _taskService.MothermachinemovementTask2(mu1rgv.ChildPosiDeviceCode);
+                            if (task == null)
+                            {
+                                RGVMovetask(mu1rgv.Motherinlaw, mu1rgv.ChildPosiDeviceCode);
+                            }
+                        }
+                        if (mu2 != mu2rgv.Motherinlaw)
+                        {
+                            Dt_Task task2 = _taskService.MothermachinemovementTask2(mu2rgv.ChildPosiDeviceCode);
+                            if (task2 == null)
+                            {
+                                RGVMovetask(mu2rgv.Motherinlaw, mu2rgv.ChildPosiDeviceCode);
+                            }
+                        }
+                    }*/
+                }
+            }
+            else if (RGVTaskdevice.Station_Area == 5)
+            {
+                if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentOne)
+                {
+                    //闇�瑕佸垽鏂渚у皬杞︽槸鍚﹀湪HCJ涓�
+                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
+                    int waiziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+
+                    if ((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress)
+                    {
+                        return dt_Task;
+                    }
+
+                }
+                else if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentTwo)    //闇�瑕佸垽鏂�3宸烽亾姣嶈溅鏄惁鍦ㄥ彇璐х珯鍙�
+                {
+                    //鍒ゆ柇瀛愯溅鏄惁鍦℉CJ绔欏彴
+                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
+                    int waiziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+
+                    if ((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress)
+                    {
+                        //姣嶈溅1
+                        var mu1rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
+                        int mu1 = GetDeviceAddress.GetEquipmentInformation(mu1rgv.ChildPosiDeviceCode); //姝ゆ椂鐨凴GV搴旇鏃犺揣
+                        if (mu1 == mu1rgv.Motherinlaw)
+                        {
+                            return dt_Task;
+                        }
+                        else
+                        {
+                            Dt_Task task = _taskService.MothermachinemovementTask2(mu1rgv.ChildPosiDeviceCode);
+                            if (task == null)
+                            {
+                                RGVMovetask(mu1rgv.Motherinlaw, mu1rgv.ChildPosiDeviceCode);
+                            }
+                        }
+                    }
+                }
+            }
+            return null;
+        }
+        /// <summary>
+        /// 鍒ゆ柇澶栦晶姣嶈溅鏄惁鍦ㄥ叆鍙e彛
+        /// </summary>
+        /// <param name="task"></param>
+        /// <param name="currentStation"></param>
+        /// <returns></returns>
+        private Dt_Task? HandleMedialCase(Dt_Task task, int currentStation)
+        {
+            AGVStation Muche = _agvStationService.GetMothervehicle(currentStation);
+            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+            if (motherCarAddress == Muche.Motherinlaw) return task;
+            RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
+            return null;
+        }
+        /// <summary>
+        /// 鍒ゆ柇鍐呭渚ф瘝杞︽槸鍚﹀湪鍏ュ簱鍙�
+        /// </summary>
+        /// <param name="task"></param>
+        /// <param name="currentStation"></param>
+        /// <returns></returns>
+        private Dt_Task? HandleMedialCase2(Dt_Task task, AGVStation currentStation)
+        {
+            AGVStation Muche = _agvStationService.GetMothervehicle(currentStation.MotherCarDeviceCode);  //澶栦晶姣嶈溅
+            AGVStation Muche2 = _agvStationService.GetMothervehicle(currentStation.MotherCardeputy);    //鍐呬晶姣嶈溅
+
+            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
+            if (motherCarAddress == 0 || motherCarAddress2 == 0) return null;
+            // 濡傛灉姣嶈溅涓嶅湪棰勬湡浣嶇疆锛屼笅鍙戠Щ鍔ㄤ换鍔�
+            if (motherCarAddress != Muche.Motherinlaw)
+            {
+                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
+            }
+            if (motherCarAddress2 != Muche2.Motherinlaw)
+            {
+                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
+            }
+            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw) return task;
+            // 姣嶈溅宸插湪姝g‘浣嶇疆
             return null;
         }
 
-        //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆
-        private bool MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
+
+        #endregion
+
+        #region 杩囬亾瀛愯溅杩涜鏀捐揣
+        public Dt_Task? GoodsPlacedCorridor(AGVStation RGVTaskdevice)
         {
-            int mcadder = GetMothercarlocation(_Task, aGVStation.Motherinlaw);
-            if(mcadder != 0)
+            Dt_Task task = _taskService.ViceChariotPlacingTask(RGVTaskdevice.ChildPosiDeviceCode);  //鑾峰彇鍒版斁璐т换鍔�
+            if (task == null) return null;
+            int nexaddres = int.Parse(task.NextAddress);    //鍒ゆ柇鏄斁璐у湪鍝殑浠诲姟
+            switch (nexaddres)
             {
-                if (mcadder == int.Parse(_Task.CurrentAddress))       //鍒ゆ柇瀛愯溅瑕佸幓鐨勪綅缃紝姣嶈溅鏄惁鍦ㄨ浣嶇疆
+                case int Whcjaddress when Whcjaddress == RGVTaskdevice.MotherCarDeviceCode:    //鏀捐揣鐐瑰湪绗竴涓繃閬撶偣(宸插畬鎴�)
+                    return MotherCarMoves(task, RGVTaskdevice);
+                case int Waddress when Waddress == RGVTaskdevice.MotherCardeputy:              //鏀捐揣鐐瑰湪绗簩涓繃閬撶偣(宸插畬鎴�)
+                    return MotherCarMovesinside(task, RGVTaskdevice);
+                case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress:        //鏀捐揣鐐瑰湪HCJ涓婏紙宸插畬鎴愶級
+                    return HCJMotherCarMovesinside(task, RGVTaskdevice);
+                default: return null;
+            }
+        }
+
+
+        //鍖哄煙涓�鍒ゆ柇姣嶈溅鏄惁鍒颁綅锛屽彲绔嬪嵆鏀捐揣
+        private Dt_Task? MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
+        {
+            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);
+            Dt_Task task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //鑾峰彇鍒版瘝杞︾Щ鍔ㄤ换鍔�
+            if (task == null)
+            {
+                GetStackerObject getStackerObject = GetDeviceAddress.GetChildDeviceCode(Muche.ChildPosiDeviceCode);
+                if (getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)   //鍒ゆ柇姣嶈溅鏄惁鏈夎揣
                 {
-                    return true;
+                    if (getStackerObject.RGVCurrentlocation == Muche.ZicheMotherinlaw)     //鍒ゆ柇姣嶈溅鏄惁鍦ㄨ繃閬撶偣锛�
+                    {
+                        return _Task;
+                    }
+                    else
+                    {
+                        RGVMovetask(Muche.ZicheMotherinlaw, Muche.ChildPosiDeviceCode);  //濡傛灉娌℃湁浠诲姟锛屽垯鍙互杩涜绉诲姩鍑烘潵
+                    }
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇鏀剧浜屼釜姣嶈溅浣嶇疆
+        /// </summary>
+        /// <param name="_Task"></param>
+        /// <param name="aGVStation"></param>
+        /// <returns></returns>
+        private Dt_Task? MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
+        {
+
+            //鍒ゆ柇澶栦晶姣嶈溅鏄惁闇�瑕佺Щ鍔ㄨ嚦鍫嗗灈鏈哄彇璐у彛
+            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);
+            int muche1objet = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+
+            //鍒ゆ柇鍐呬晶姣嶈溅鏄惁鍦ㄦ斁璐х偣
+            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //鍐呬晶姣嶈溅
+            int muche2objet = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
+            bool NoCargobool = GetDeviceAddress.Mucheywhaddres(Muche2.ChildPosiDeviceCode);
+
+            //姝e父鎯呭喌涓嬶紝鎶婁俊鎭弽棣堝嚭鍘�
+            if (muche1objet == Muche.Motherinlaw && muche2objet == Muche2.ZicheMotherinlaw && NoCargobool)
+            {
+                return _Task;
+            }
+            //姣嶈溅1涓嶅湪鍙栬揣鍙�
+            if (muche1objet != Muche.Motherinlaw)     //鍒ゆ柇姣嶈溅鏄惁鍦ㄨ繃閬撶偣锛�
+            {
+                Dt_Task task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //鑾峰彇鍒版瘝杞︾Щ鍔ㄤ换鍔�
+                if (task == null)
+                {
+                    RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);  //濡傛灉娌℃湁浠诲姟锛屽垯鍙互杩涜绉诲姩鍑烘潵
+                }
+            }
+
+            //姣嶈溅2涓嶅湪杩囬亾绔欑偣
+            if (muche2objet != Muche2.ZicheMotherinlaw)     //鍒ゆ柇姣嶈溅鏄惁鍦ㄨ繃閬撶偣锛�
+            {
+                Dt_Task task = _taskService.MothermachinemovementTask2(Muche2.ChildPosiDeviceCode);   //鑾峰彇鍒版瘝杞︾Щ鍔ㄤ换鍔�
+                if (task == null)
+                {
+                    RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);  //濡傛灉娌℃湁浠诲姟锛屽垯鍙互杩涜绉诲姩鍑烘潵
+                }
+            }
+            return null;
+        }
+        /// <summary>
+        /// 鍒ゆ柇鏀惧湪HCJ涓婇潰
+        /// </summary>
+        /// <param name="_Task"></param>
+        /// <param name="aGVStation"></param>
+        /// <returns></returns>
+        private Dt_Task? HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
+        {
+            //鍏堝垽鏂璈CJ绔欏彴鐐规槸鍚︽湁璐э紝鏈変换鍔�
+            if (GetDeviceAddress.HCJIsstock(_Task.NextAddress))
+            {
+                //鍒ゆ柇鍐呰溅瀛愯溅鏄惁鍦ㄧ瓑寰呯偣
+                AGVStation neiziche = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //鍐呬晶瀛愯溅
+                int neizichecurraddres = GetDeviceAddress.GetEquipmentlocation(neiziche.ChildPosiDeviceCode);
+
+
+                Dt_Task task = _taskService.ViceChariotPickupTask2(neiziche.ChildPosiDeviceCode);   //鑾峰彇鍒板唴渚у瓙杞﹀彇璐т换鍔�
+                if ((neizichecurraddres != neiziche.WaitmomentOne && neizichecurraddres != neiziche.WaitmomentTwo) || task != null)     //鍐呬晶瀛愯溅涓嶅湪涓や釜缂撳瓨鐐�
+                {
+                    return null;
+                }
+                AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //澶栦晶姣嶈溅
+                int mucheaddre1 = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+                AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //鍐呬晶姣嶈溅
+                int mucheaddre2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
+
+                if ((neizichecurraddres == neiziche.WaitmomentOne || neizichecurraddres == neiziche.WaitmomentTwo) && task == null && mucheaddre1 == Muche.Motherinlaw && mucheaddre2 == Muche2.Motherinlaw)
+                {
+                    return _Task;
+                }
+                //鍒ゆ柇涓や釜姣嶈溅浣嶇疆
+                if (mucheaddre1 != Muche.Motherinlaw)     //鍒ゆ柇姣嶈溅鏄惁鍦ㄨ繃閬撶偣锛�
+                {
+                    Dt_Task muche1task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //鑾峰彇鍒版瘝杞︾Щ鍔ㄤ换鍔�
+                    if (muche1task == null)
+                    {
+                        RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);  //濡傛灉娌℃湁浠诲姟锛屽垯鍙互杩涜绉诲姩鍑烘潵
+                    }
+                }
+                if (mucheaddre2 != Muche2.Motherinlaw)     //鍒ゆ柇姣嶈溅鏄惁鍦ㄨ繃閬撶偣锛�
+                {
+                    Dt_Task muche2task = _taskService.MothermachinemovementTask2(Muche2.ChildPosiDeviceCode);   //鑾峰彇鍒版瘝杞︾Щ鍔ㄤ换鍔�
+                    if (muche2task == null)
+                    {
+                        RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);  //濡傛灉娌℃湁浠诲姟锛屽垯鍙互杩涜绉诲姩鍑烘潵
+                    }
+                }
+            }
+            return null;
+        }
+        #endregion
+
+        #region 姣嶈溅绉诲姩浠诲姟
+        public Dt_Task? MotherVehicleMovement(AGVStation RGVTaskdevice)
+        {
+            Dt_Task task = _taskService.MothermachinemovementTask(RGVTaskdevice.ChildPosiDeviceCode);
+            if (task == null) return null;
+
+            AGVStation GdZiche = _agvStationService.GetMotheaisle(RGVTaskdevice.ZicheMotherinlaw);
+            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(GdZiche.ChildPosiDeviceCode);
+            if (GdZiche.WaitmomentOne == motherCarAddress || GdZiche.WaitmomentTwo == motherCarAddress)
+            {
+                return task;
+            }
+            return null;
+        }
+        #endregion
+
+        #endregion
+
+        #region 鍑哄簱鏂规硶(鍙繘琛屾祴璇�)
+        public Dt_Task? OutboundEquipmentTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
+        {
+            return (RGVTaskdevice.Station_material, getStackerObject.RgvCraneStatusValue) switch
+            {
+                ((int)RGVEquipment.Mothertrailer, RgvEquipmentStatus.HasCargo)      //涓嬪彂姣嶈溅鍑烘潵鍒拌繃閬撲笂
+                    => Mothertaskdistribution(RGVTaskdevice),//宸插畬鎴�   
+
+                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.NoCargo)         //鏌ユ壘瀛愯溅鍑烘潵鍙栬揣
+                    => ChildPickupAddres(RGVTaskdevice, getStackerObject.RGVCurrentlocation),   //宸插畬鎴�
+
+                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.HasCargo)
+                    => Findshippingtask(RGVTaskdevice, getStackerObject.RGVCurrentlocation),    //瀛愯溅鍙栬揣鍚庯紝杩涜鏀捐揣锛堝凡瀹屾垚锛�
+
+                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.NoCargo)
+                    => OutboundGateVehicle(RGVTaskdevice),              //鍑哄簱鍙GV鍙栬揣锛堝凡瀹屾垚锛�
+
+                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.HasCargo)
+                    => _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
+                       RGVTaskdevice.HCJStorageaddress.ToString()),
+
+                _ => null
+            };
+        }
+
+        #region 涓嬪彂姣嶈溅浠诲姟锛岄渶瑕佸垽鏂綋鍓嶈灏忚溅鍦ㄥ摢涓綅瀛�(宸插畬鎴�)
+
+        private Dt_Task? Mothertaskdistribution(AGVStation GdZiche)
+        {
+            // 鎻愬墠妫�鏌ユ棤鏁堢殑Area鍊�
+            if (GdZiche.Station_Area < 1 || GdZiche.Station_Area > 4)
+                return null;
+
+            //鏍规嵁姣嶈溅鍦板潃锛岃幏鍙栧綋鍓嶈閬撶殑瀛愯溅
+            AGVStation ZicheinnerSide = _agvStationService.GetMotheaisle(GdZiche.ZicheMotherinlaw);
+            int zichecurraddre = GetDeviceAddress.GetEquipmentlocation(ZicheinnerSide.ChildPosiDeviceCode);   //鑾峰彇鍒板瓙杞﹀疄渚�
+
+            if (zichecurraddre != ZicheinnerSide.WaitmomentOne && zichecurraddre != ZicheinnerSide.WaitmomentTwo) return null;
+
+            //鍒ゆ柇鏄摢涓贩閬撶殑姣嶈溅
+            return GdZiche.Station_Area switch
+            {
+                4 => OutboundSideAisle4(zichecurraddre, ZicheinnerSide),    //鍦�4宸烽亾杩涜鍑哄簱鐨勪换鍔★紙宸插畬鎴愶級
+                3 => OutboundSideAisle3(zichecurraddre, ZicheinnerSide),    //鍦�3宸烽亾杩涜鍑哄簱鐨勪换鍔★紙宸插畬鎴愶級
+                2 => OutboundSideAisle2(ZicheinnerSide),                                   //鍦ㄤ簩宸烽亾杩涜鍑哄簱鐨勪换鍔★紙宸插畬鎴愶級
+                1 => _taskService.ObtainMuChetask(GdZiche.ZicheMotherinlaw.ToString()),   //鏍规嵁姣嶈溅瀛愬湴鍧�锛屾煡鎵炬槸鍚︽湁闇�瑕佺Щ鍔ㄧ殑浠诲姟锛堝凡瀹屾垚锛�
+                _ => null
+            };
+
+        }
+
+        public Dt_Task? OutboundSideAisle1(AGVStation ZicheinnerSide)
+        {
+            //鑾峰彇1宸烽亾姣嶈溅鏄惁鏈変换鍔�
+            Dt_Task Muche1Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCarDeviceCode.ToString());
+            if (Muche1Task == null) return null;
+
+            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
+            if (zicheTASK != null) return null;
+
+            return Muche1Task;
+        }
+
+        public Dt_Task? OutboundSideAisle2(AGVStation ZicheinnerSide)
+        {
+            //鑾峰彇2宸烽亾姣嶈溅鏄惁鏈変换鍔�
+            Dt_Task Muche2Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCardeputy.ToString());
+            if (Muche2Task == null) return null;
+
+            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
+            if (zicheTASK != null) return null;
+
+            return Muche2Task;
+        }
+        public Dt_Task? OutboundSideAisle3(int curraddZiChe, AGVStation ZicheinnerSide)
+        {
+            //鑾峰彇3宸烽亾姣嶈溅鏄惁鏈変换鍔�
+            Dt_Task Muche3Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCarDeviceCode.ToString());
+            if (Muche3Task == null) return null;
+
+            //鍒ゆ柇瀛愯溅鏄惁鏈夋湁闇�瑕佸彇璐х殑浠诲姟
+            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
+            if (zicheTASK != null) return null;
+
+            if (curraddZiChe == ZicheinnerSide.WaitmomentTwo || curraddZiChe == ZicheinnerSide.WaitmomentOne)
+            {
+                return Muche3Task;
+            }
+            return null;
+        }
+        public Dt_Task? OutboundSideAisle4(int curraddZiChe, AGVStation ZicheinnerSide)
+        {
+            //鑾峰彇褰撳墠姣嶈溅鏄惁鏈変换鍔�
+            Dt_Task Muche4Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCardeputy.ToString());
+            if (Muche4Task == null) return null;
+
+            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
+            if (zicheTASK != null) return null;
+
+            if (curraddZiChe == ZicheinnerSide.WaitmomentOne)
+            {
+
+            }
+
+            
+
+            
+
+
+
+            if ( || curraddZiChe == ZicheinnerSide.WaitmomentTwo)
+            {
+                return Muche4Task;
+            }
+            return null;
+        }
+
+        #endregion
+
+        #region 鍒ゆ柇宸茬Щ鍔ㄥ嚭鏉ョ殑姣嶈溅锛屽啀鍒ゆ柇灏忚溅浣嶇疆(宸插畬鎴�)
+        public Dt_Task? ChildPickupAddres(AGVStation GdZiche, int curraderr)
+        {
+            if (curraderr == GdZiche.WaitmomentOne || curraderr == GdZiche.WaitmomentTwo)
+            {
+                Dt_Task dtTasks = _taskService.ChildVehicleMission(GdZiche);
+                if (dtTasks == null) return null;
+                if (GdZiche.Station_Area == 5)
+                {
+                    if (dtTasks.CurrentAddress == GdZiche.MotherCardeputy.ToString())   //鍙栬揣鐨勭偣鍦�2宸烽亾锛屽垯瀛愯溅鏃犺鍦ㄥ摢涓瓑寰呯偣锛岄兘鍙互鍙栬揣
+                    {
+                        return dtTasks;
+                    }
+                    else if (dtTasks.CurrentAddress == GdZiche.MotherCarDeviceCode.ToString())     //鍙�1宸烽亾鐨勮揣
+                    {
+                        if (curraderr == GdZiche.WaitmomentOne)     //瀛愯溅鍒氬ソ鍦ㄦ梺杈癸紝鍙珛椹彇璐�
+                        {
+                            return dtTasks;
+                        }
+                        else if (curraderr == GdZiche.WaitmomentTwo)
+                        {
+                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
+                            int muche2addres = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);  //鑾峰彇2宸烽亾姣嶈溅瀹炰緥
+                            if (muche2addres == muchestation.Motherinlaw)
+                            {
+                                return dtTasks;
+                            }
+                        }
+                    }
+                }
+                else if (GdZiche.Station_Area == 6)
+                {
+                    //HCJ绔欏彴娌′换鍔�
+                    if (dtTasks.CurrentAddress == GdZiche.MotherCardeputy.ToString())       //浼樺厛鍒ゆ柇鏄惁鏄渶澶栭潰鐨勪换鍔�
+                    {
+                        if (curraderr == GdZiche.WaitmomentTwo)
+                        {
+                            return dtTasks;
+                        }
+                        else
+                        {
+                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
+                            int muche3x = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
+                            if (muche3x == muchestation.Motherinlaw)
+                            {
+                                return dtTasks;
+                            }
+                        }
+                    }
+                    else if (dtTasks.CurrentAddress == GdZiche.MotherCarDeviceCode.ToString())    //璇ヤ换鍔′负鍙�3宸烽亾
+                    {
+                        if (curraderr == GdZiche.WaitmomentOne)
+                        {
+                            return dtTasks;
+                        }
+                        else if(curraderr == GdZiche.WaitmomentTwo)
+                        {
+                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
+                            int muche4x = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
+                            if (muche4x == muchestation.Motherinlaw)
+                            {
+                                return dtTasks;
+                            }
+                        }
+
+                    }
+                    else if (dtTasks.CurrentAddress == GdZiche.HCJStorageaddress.ToString())
+                    {
+                        //鍒ゆ柇鍐呬晶瀛愯溅鐨勪綅缃�
+                        AGVStation neiziche = _agvStationService.GetOutZicheDeep(GdZiche.HCJStorageaddress);    //鍐呬晶瀛愯溅
+                        int neizichecurraddres = GetDeviceAddress.GetEquipmentlocation(neiziche.ChildPosiDeviceCode);
+                        if ((neiziche.WaitmomentOne == neizichecurraddres || neiziche.WaitmomentTwo == neizichecurraddres || neiziche.MotherCarDeviceCode == neizichecurraddres || neiziche.MotherCardeputy == neizichecurraddres) && neiziche.HCJStorageaddress != neizichecurraddres)
+                        {
+                            if (curraderr == GdZiche.WaitmomentTwo)
+                            {
+                                var mu1rgv = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
+                                int mu1 = GetDeviceAddress.GetEquipmentlocation(mu1rgv.ChildPosiDeviceCode);
+
+                                var mu2rgv = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
+                                int mu2 = GetDeviceAddress.GetEquipmentlocation(mu2rgv.ChildPosiDeviceCode);
+
+                                if (mu1 == mu1rgv.Motherinlaw && mu2 == mu2rgv.Motherinlaw)
+                                {
+                                    return dtTasks;
+                                }
+                            }
+                            else if (curraderr == GdZiche.WaitmomentOne)
+                            {
+                                return dtTasks;
+                            }
+                        }
+                    }
+
+
+                }
+
+            }
+            return null;
+        }
+        #endregion
+
+        #region 鏌ユ壘瀛愯溅鏀捐揣浠诲姟(宸插畬鎴�)
+        public Dt_Task? Findshippingtask(AGVStation GdZiche, int curraderr)
+        {
+            Dt_Task task = _taskService.GetFinhuoTask(GdZiche.ChildPosiDeviceCode);
+            if (task == null) return null;
+            if (GetDeviceAddress.HCJIsstock(task.NextAddress))
+            {
+                if (GdZiche.Station_Area == 5)
+                {
+                    //闇�瑕佸垽鏂渚у皬杞︽槸鍚﹀湪HCJ涓�
+                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(GdZiche.HCJStorageaddress);
+                    int waiziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+                    if ((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode) && waiziche != zichestation.HCJStorageaddress)
+                    {
+                        //鍒ゆ柇褰撳墠浣嶇疆
+                        if (task.CurrentAddress == GdZiche.MotherCarDeviceCode.ToString())
+                        {
+                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
+                            int muche2 = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
+                            if (muche2 == muchestation.Motherinlaw)
+                            {
+                                return task;
+                            }
+                        }
+                        else if (task.CurrentAddress == GdZiche.MotherCardeputy.ToString())
+                        {
+                            return task;
+                        }
+                    }
+                }
+                else if (GdZiche.Station_Area == 6)
+                {
+                    if (GdZiche.HCJStorageaddress == curraderr)
+                    {
+                        //鍒ゆ柇3宸烽亾姣嶈溅
+                        var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
+                        int mucboject3 = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
+                        if (mucboject3 == muchestation.Motherinlaw)
+                        {
+                            //鍒ゆ柇4宸烽亾姣嶈溅
+                            var muchestation2 = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
+                            int mucboject4 = GetDeviceAddress.GetEquipmentlocation(muchestation2.ChildPosiDeviceCode);
+                            if (mucboject4 == muchestation2.Motherinlaw)
+                            {
+                                return task;
+                            }
+
+                        }
+                    }
+                    else if (GdZiche.MotherCarDeviceCode == curraderr)
+                    {
+                        //鍒ゆ柇4宸烽亾姣嶈溅
+                        var muchestation2 = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
+                        int mucboject4 = GetDeviceAddress.GetEquipmentlocation(muchestation2.ChildPosiDeviceCode);
+                        if (mucboject4 == muchestation2.Motherinlaw)
+                        {
+                            return task;
+                        }
+                    }
+                    else if (GdZiche.MotherCardeputy == curraderr) return task;
+                }
+            }
+            return null;
+        }
+        #endregion
+
+        #region 鍑哄簱鍙e瓙杞﹀彇璐�(宸插畬鎴�)
+        public Dt_Task OutboundGateVehicle(AGVStation GdZiche)
+        {
+            //闇�瑕佸垽鏂瓙杞︽槸鍚﹀湪HCJ涓�
+            var zichestation = _agvStationService.OutGetZicheDeepHCJ(1131);
+            int ziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+
+            if (ziche != GdZiche.HCJStorageaddress && (ziche == zichestation.HCJStorageaddress || ziche == zichestation.WaitmomentOne || ziche == zichestation.WaitmomentTwo || ziche == zichestation.MotherCardeputy || ziche == zichestation.MotherCarDeviceCode))
+            {
+                return _taskService.GetOutchachekouFinhuoTask(GdZiche.ChildPosiDeviceCode, GdZiche.HCJStorageaddress.ToString());
+            }
+            return null;
+        }
+        #endregion
+
+        #endregion
+
+        #region 鍑哄簱灏忚溅绉诲姩浠诲姟涓嬪彂(宸插畬鎴�)
+        public void Returnposition(string DeviceCode, int RGVCurrentlocation, int RgvCraneStatusValue)
+        {
+            AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);
+            if (GdZiche.Station_material == (int)RGVEquipment.Mothertrailer)
+            {
+                if (GdZiche.Motherinlaw == RGVCurrentlocation) return;
+                if (RgvCraneStatusValue == (int)RgvEquipmentStatus.HasCargo) return;
+
+                //姣嶄翰鍥炲爢鍨涙満鍙d换鍔★紝鍒ゆ柇瀛愯溅鐨勪綅缃槸鍚﹀湪姣嶈溅涓�
+                var zichestation = _agvStationService.GetMotheaisle(GdZiche.ZicheMotherinlaw);
+
+                //鑾峰彇瀛愯溅鏄惁鏈変换鍔℃潵璇ヤ綅缃彇璐�
+                Dt_Task Muche2Task = _taskService.OutPickupZiche(zichestation.ChildPosiDeviceCode.ToString());
+                if (Muche2Task != null) return;
+                GetStackerObject getStackerObject = GetDeviceAddress.GetChildDeviceCode(zichestation.ChildPosiDeviceCode);
+
+                if (getStackerObject.StaclerkJobJobStatusValue != RGV_Rgvtaskstutas.Executing && getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic
+                     && (getStackerObject.RGVCurrentlocation == zichestation.WaitmomentOne || getStackerObject.RGVCurrentlocation == zichestation.WaitmomentTwo) && getStackerObject.RGVCurrentlocation != zichestation.ZicheMotherinlaw)
+                {
+                    RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
+                }
+            }
+            else if (GdZiche.Station_material == (int)RGVEquipment.Corridorcar)
+            {
+                if (RgvCraneStatusValue == (int)RgvEquipmentStatus.HasCargo) return;
+                if (GdZiche.Station_Area == 5)
+                {
+                    if (GdZiche.MotherCardeputy == RGVCurrentlocation || GdZiche.HCJStorageaddress == RGVCurrentlocation)
+                    {
+                        RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
+                    }
+                    else if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation)
+                    {
+                        RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
+                    }
                 }
                 else
                 {
-                    //涓嬪彂姣嶈溅绉诲姩鍑烘潵鎺ヨ揣浠诲姟
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, _Task.CurrentAddress);
-                    
-                    bool sendFlag = SendCommand2(standardCommands, aGVStation.ChildPosiDeviceCode);
-                    if (sendFlag)
+                    if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation || GdZiche.HCJStorageaddress == RGVCurrentlocation)
                     {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
+                        RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
+                    }
+                    else if (GdZiche.MotherCardeputy == RGVCurrentlocation && RGVCurrentlocation == 1171)
+                    {
+                        RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
                     }
                 }
             }
-
-            return false;
         }
+        #endregion
 
-        //鍒ゆ柇鍐呬晶姣嶈溅浣嶇疆
-        private bool MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
+        #region 鍏ュ簱灏忚溅绉诲姩浠诲姟涓嬪彂(宸插畬鎴�)
+        public void InReturnposition(string DeviceCode, int RGVCurrentlocation, int RgvCraneStatusValue)
         {
-            //鑾峰彇澶栦晶姣嶈溅浣嶇疆
-            int mcadder = GetMothercarlocation(_Task, aGVStation.MotherCarDeviceCode);
-            //鑾峰彇鍐呬晶姣嶈溅浣嶇疆
-            int ncadder = GetMothercarlocation(_Task, _Task.CurrentAddress);    //浼犲叆杩囬亾鐨勫湴鍧�
-
-            if (mcadder != int.Parse(aGVStation.MotherCarDeviceCode) && ncadder == aGVStation.Station_code)       //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆
+            AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);//鑾峰彇鍒拌绉诲姩鐨勫瓙杞�
+            if (GdZiche.Station_material == (int)RGVEquipment.Corridorcar)
             {
-                return true;
-            }
-            else
-            {
-                if (mcadder == int.Parse(aGVStation.MotherCarDeviceCode))    //澶栦晶姣嶈溅闇�瑕佺Щ鍔�
+                if (GdZiche.Station_Area == 5)
                 {
-                    //涓嬪彂姣嶈溅寰�閲岄潰璧扮殑浠诲姟
-                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCarDeviceCode);    //鍫嗗灈鏈哄叆搴撳彛
-
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVSta.Station_code.ToString()); //涓嬪彂姣嶈溅绉诲姩鑷冲叆搴撶珯鍙颁綅
-                    bool sendFlag = SendCommand2(standardCommands, aGVSta.ChildPosiDeviceCode);
-                    if (sendFlag)
+                    if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation || GdZiche.HCJStorageaddress == RGVCurrentlocation)
                     {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
+                        RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
+                    }
+                    else if (GdZiche.MotherCardeputy == RGVCurrentlocation)
+                    {
+                        RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
                     }
                 }
-
-                if (ncadder != aGVStation.Station_code)    //涓嬪彂姣嶈溅
+                else
                 {
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVStation.Station_code.ToString());
-                    bool sendFlag = SendCommand2(standardCommands, aGVStation.ChildPosiDeviceCode);
-                    if (sendFlag)
+                    Dt_Task task = _taskService.GetChariotTaskBool(GdZiche.ChildPosiDeviceCode);
+                    if (task == null && RgvCraneStatusValue == (int)RgvEquipmentStatus.NoCargo)
                     {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
+                        if (GdZiche.HCJStorageaddress == RGVCurrentlocation)
+                        {
+                            //濡傛灉鍦�2宸烽亾鐨勬瘝杞︼紝鍒欏彲浠ユ斁瀛愯溅鏉�1鍙风瓑寰呯偣锛屽鏋滃湪HCJ鍒欏彲浠ヨ瀛愯溅鍘�2鍙�
+                            RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
+                        }
+                        else if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation || GdZiche.MotherCardeputy == RGVCurrentlocation)
+                        {
+                            RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
+                        }
+                        else if (RGVCurrentlocation == 1021)
+                        {
+                            //鍔犲叆鍒ゆ柇锛屽鏋滃湪1021绔欏彴锛屽垯闇�瑕佸垽鏂�1鍙峰贩閬撴瘝杞︽槸鍚﹀湪鍫嗗灈鏈哄彇璐у彛
+                            var zichestation = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
+                            int ziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+                            if (GetDeviceAddress.Mucheywhaddres(zichestation.ChildPosiDeviceCode) && (ziche == zichestation.ZicheMotherinlaw || ziche == zichestation.Motherinlaw))
+                            {
+                                RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
+                            }
+
+                        }
                     }
                 }
             }
-            return false;
         }
-        private bool HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)  //浼犺繘鏉ョ殑绔欏彴涓篐CJ
-        {
-            //鑾峰彇澶栦晶姣嶈溅浣嶇疆
-            int mcadder = GetMothercarlocation(_Task, aGVStation.MotherCarDeviceCode);
-            //鑾峰彇鍐呬晶姣嶈溅浣嶇疆
-            int ncadder = GetMothercarlocation(_Task, aGVStation.MotherCardeputy);   
-
-            if (mcadder != int.Parse(aGVStation.MotherCarDeviceCode) && ncadder != int.Parse(aGVStation.MotherCardeputy))       //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆
-            {
-                return true;
-            }
-            else
-            {
-                if (mcadder == int.Parse(aGVStation.MotherCarDeviceCode))    //澶栦晶姣嶈溅闇�瑕佺Щ鍔�
-                {
-                    //涓嬪彂姣嶈溅寰�閲岄潰璧扮殑浠诲姟
-                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCarDeviceCode);    //鍫嗗灈鏈哄叆搴撳彛
-
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVSta.Station_code.ToString()); //涓嬪彂姣嶈溅绉诲姩鑷冲叆搴撶珯鍙颁綅
-                    bool sendFlag = SendCommand2(standardCommands, aGVSta.ChildPosiDeviceCode);
-                    if (sendFlag)
-                    {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
-                    }
-                }
-
-                if (ncadder == int.Parse(aGVStation.MotherCardeputy))    //涓嬪彂姣嶈溅
-                {
-                    //涓嬪彂姣嶈溅寰�閲岄潰璧扮殑浠诲姟
-                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCardeputy);    //鍫嗗灈鏈哄叆搴撳彛
-
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVSta.Station_code.ToString()); //涓嬪彂姣嶈溅绉诲姩鑷冲叆搴撶珯鍙颁綅
-                    bool sendFlag = SendCommand2(standardCommands, aGVSta.ChildPosiDeviceCode);
-                    if (sendFlag)
-                    {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
-                    }
-                }
-            }
-            return false;
-        }
-
-        
-
-        public bool QueryCurrentAdder(Dt_Task task)
-        {
-            try
-            {
-                //鑾峰彇闇�瑕佸尯鍒嗘槸鍚﹀幓鍏ュ簱涓庡幓涓嶅悎鏍艰浇璐у彴浠诲姟
-                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
-                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
-                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, task.CurrentAddress, "HCJ_GoodsStatus");
-                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
-                if (HCJGStatus == 0)    //涓烘棤璐�
-                {
-                    return true;
-                }
-            }
-            catch (Exception ex)
-            {
-                //璁板綍寮傚父鎯呭喌
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum,$"鍒ゆ柇HCJ绔欏彴鏄惁鏈夎揣淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
-                throw;
-            }
-
-            return false;
-        }
-
-        //鍒ゆ柇鏄惁
-        public bool GetMotherCarCurrentAdder(Dt_Task task)
-        {
-            try
-            {
-                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
-                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
-                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, task.CurrentAddress, "HCJ_GoodsStatus");
-                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
-                if (HCJGStatus == 0)    //涓烘棤璐�
-                {
-                    return true;
-                }
-            }
-            catch (Exception ex)
-            {
-                //璁板綍寮傚父鎯呭喌
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍒ゆ柇HCJ绔欏彴鏄惁鏈夎揣淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
-                throw;
-            }
-
-            return false;
-        }
-
-
+        #endregion
 
         /// <summary>
-        /// 浼犲叆杩囬亾鍦板潃锛岃幏鍙栨瘝杞︿綅缃�
+        /// 瀛愭瘝杞︾Щ鍔ㄤ换鍔�
         /// </summary>
-        /// <param name="task"></param>
-        /// <param name="MotherCarDeviceCode">杩囬亾鍦板潃</param>
+        /// <param name="RGVAdders">鐩爣鍦板潃</param>
+        /// <param name="ChildPosiDeviceCode">璁惧缂栧彿</param>
         /// <returns></returns>
-        public int GetMothercarlocation(Dt_Task task,string MotherCarDeviceCode)
+        private bool RGVMovetask(int RGVAdders, string ChildPosiDeviceCode)
         {
-            try
-            {
-                //鍒╃敤鍏ュ簱绔欏彴鍦板潃鑾峰彇姣嶈溅plc
-                AGVStation aGVStation =_agvStationService.GetMothercarCode(MotherCarDeviceCode);
-                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == aGVStation.ChildPosiDeviceCode);
-                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
-                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, aGVStation.ChildPosiDeviceCode, "RGVCurrentlocation");
-                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
-                return HCJGStatus;
-            }
-            catch (Exception ex)
-            {
-                //璁板綍寮傚父鎯呭喌
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍒ゆ柇姣嶈溅浣嶇疆淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
-                throw;
-            }
+            RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(RGVAdders);
+            bool sendFlag = SendCommand2(standardCommands, ChildPosiDeviceCode);
+            return sendFlag;
         }
-
-
-        /// <summary>
-        /// 浼犲叆杩囬亾鍦板潃锛岃幏鍙栧瓙杞﹁溅浣嶇疆
-        /// </summary>
-        /// <param name="task"></param>
-        /// <param name="MotherCarDeviceCode">鍏ュ簱绔欏彴鍦板潃</param>
-        /// <returns></returns>
-        public int GetZichelocation(Dt_Task task, string ChildPosiDeviceCode)
-        {
-            try
-            {
-                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
-                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
-                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, ChildPosiDeviceCode, "RGVCurrentlocation");
-                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
-                return HCJGStatus;
-            }
-            catch (Exception ex)
-            {
-                //璁板綍寮傚父鎯呭喌
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍒ゆ柇瀛愯溅浣嶇疆淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
-                throw;
-            }
-        }
-
-
-
-
         /// <summary>
         /// 浠诲姟瀹炰綋杞崲鎴愬懡浠odel
         /// </summary>
@@ -474,11 +979,37 @@
         public RgvCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
         {
             RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
-            stackerCraneTaskCommand.RGV_RGVTasklocation = short.Parse(task.CurrentAddress);
-            stackerCraneTaskCommand.RGV_RGVtasktype = 2;
-            stackerCraneTaskCommand.RGV_Rgvtaskid = 1;          //rgv浠诲姟鍙�
-            stackerCraneTaskCommand.RGV_Lanjiantaskid = 0;      //鍏板墤浠诲姟id
+
+            short locaticurr = task.TaskType switch
+            {
+                _ when task.TaskType == (int)TaskInboundTypeEnum.Inbound
+                    => InRgvLocaaddres(task),
+                _ when task.TaskType == (int)TaskOutboundTypeEnum.Outbound
+                    => RgvLocaaddres(task),
+                _ => (short)0
+            };
+            if (locaticurr == 0) return null;
+
+            stackerCraneTaskCommand.RGV_RGVTasklocation = locaticurr;
+            stackerCraneTaskCommand.RGV_RGVtasktype = (short)task.RGVTaskType;
+            stackerCraneTaskCommand.RGV_Rgvtaskid = (short)task.TaskNum;
+            stackerCraneTaskCommand.RGV_Lanjiantaskid = (short)task.TaskNum;
             return stackerCraneTaskCommand;
+        }
+
+        public short InRgvLocaaddres(Dt_Task dt_Task)
+        {
+            if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp) return short.Parse(dt_Task.CurrentAddress);
+            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.Placing) return short.Parse(dt_Task.NextAddress);
+            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && dt_Task.TaskState == (int)TaskInStatusEnum.RGV_InZicheReleaseFinish) return short.Parse(dt_Task.NextAddress);
+            return 0;
+        }
+        public short RgvLocaaddres(Dt_Task dt_Task)
+        {
+            if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp) return short.Parse(dt_Task.CurrentAddress);
+            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.Placing) return short.Parse(dt_Task.NextAddress);
+            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && dt_Task.TaskState == (int)TaskOutStatusEnum.OutNew) return short.Parse(dt_Task.NextAddress);
+            return 0;
         }
 
 
@@ -488,66 +1019,34 @@
         /// <param name="task">浠诲姟瀹炰綋</param>
         /// <returns></returns>
         /// <exception cref="Exception"></exception>
-        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand([NotNull] Dt_Task task,string CurrentAddress)
+        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand(int RGVAddress)
         {
             RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
-            stackerCraneTaskCommand.RGV_RGVTasklocation = short.Parse(CurrentAddress);
+            stackerCraneTaskCommand.RGV_RGVTasklocation = (short)RGVAddress;
             stackerCraneTaskCommand.RGV_RGVtasktype = 3;
-            stackerCraneTaskCommand.RGV_Rgvtaskid = 999;          //rgv浠诲姟鍙�
-            stackerCraneTaskCommand.RGV_Lanjiantaskid = 999;      //鍏板墤浠诲姟id
+            stackerCraneTaskCommand.RGV_Rgvtaskid = 30001;          //rgv浠诲姟鍙�
+            stackerCraneTaskCommand.RGV_Lanjiantaskid = 30001;      //鍏板墤浠诲姟id
             return stackerCraneTaskCommand;
         }
-
-
-        public void wcsWriteLog(string SCLLinStack, string Logtype, string Magessadd)
-        {
-            WriteLog.Write_Log("RGV", SCLLinStack + "鍙稲GV", Logtype, new { 淇℃伅 = Magessadd });
-        }
-
-
-
-        //===========================================================HCJ鍗忚璇诲啓鏌�=============================================================================
-        /// <summary>
-        /// 鏌ヨ鍏蜂綋鍦板潃
-        /// </summary>
-        /// <param name="Commonstacker"></param>
-        /// <param name="SCAddress"></param>
-        /// <param name="Interactivet"></param>
-        /// <returns></returns>
-        public DeviceProDTO? GetDeviceProDTO(CommonStackerCrane Commonstacker, string SCAddress, string Interactivet)
-        {
-            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet && x.DeviceProParamType== "ReadDeviceCommand");
-        }
-        /// <summary>
-        /// 鏍瑰湴鍧�璇诲彇杈撻�佺嚎淇℃伅
-        /// </summary>
-        /// <param name="conveyorLine"></param>
-        /// <param name="DeviceProDataBlock"></param>
-        /// <returns></returns>
-        public int GetLine(CommonStackerCrane Commonstacker, string DeviceProDataBlock)
-        {
-            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
-        }
-        //===========================================================HCJ鍗忚璇诲啓鏌�===============================================================================
-
-
         public bool SendCommand2(RgvCraneTaskCommand command, string DeviceCode)
         {
             try
             {
                 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
-                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
+                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
-                DeviceProDTO? deviceProDTO =  GetDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
-                int MCGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
-                if (Commonstacker.IsConnected)
+                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetRGVDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
+                int MCGStatus = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
+
+
+                if (MCGStatus == 0)
                 {
-                    if (MCGStatus == (int)RgvJobCraneStatus.Ready)
+                    if (MCGStatus == (int)RGV_Rgvtaskstutas.Ready)
                     {
-                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVTasklocation, command.RGV_RGVTasklocation);
-                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVtasktype, command.RGV_RGVtasktype);
-                        Commonstacker.SetValue(RgvCraneDBName.RGV_Rgvtaskid, command.RGV_Rgvtaskid);
-                        Commonstacker.SetValue(RgvCraneDBName.RGV_Lanjiantaskid, command.RGV_Lanjiantaskid);
+                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVTasklocationt, command.RGV_RGVTasklocation);
+                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVtasktypet, command.RGV_RGVtasktype);
+                        Commonstacker.SetValue(RgvCraneDBName.RGV_Rgvtaskidt, command.RGV_Rgvtaskid);
+                        Commonstacker.SetValue(RgvCraneDBName.RGV_Lanjiantaskidt, command.RGV_Lanjiantaskid);
                         return true;
                     }
                 }
@@ -559,5 +1058,7 @@
                 return false;
             }
         }
+
+
     }
 }

--
Gitblit v1.9.3