From 83f3c63f1cae6224320a8d19251e3bc0404da096 Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期五, 26 九月 2025 14:54:44 +0800
Subject: [PATCH] 出入库

---
 代码管理/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs |  432 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 259 insertions(+), 173 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 b702e2e..bad479b 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;
@@ -81,7 +82,7 @@
                         //涓嬪彂RGV浠诲姟涔嬪墠锛屽厛璇诲彇涓�涓嬪畨鍏ㄩ棬鐘舵��
 
                         //鏌ユ壘RGV杩涜涓嬪彂浠诲姟
-                        Dt_Task task = GetTask(speStackerCrane.DeviceCode);
+                        Dt_Task task = GetTask(speStackerCrane.DeviceCode,getStackerObject);
                         if (task != null)
                         {
                             //璋冨彇鍐欏叆RGV灏忚溅浠诲姟
@@ -95,46 +96,17 @@
                         }
                         else
                         {
-                            int HCJGoodsplatform = 1170;    //瀹氫箟鐨勬斁璐х珯鍙�
-
-                            //鍒ゆ柇姣嶈溅鏄惁闇�瑕佽繘琛岀Щ鍔�
-                            AGVStation GdZiche = _agvStationService.Corridorequipment(speStackerCrane.DeviceCode);
-                            if(GdZiche.Station_Area == 1)
+                            if(speStackerCrane.DeviceCode=="RGV101" || speStackerCrane.DeviceCode == "RGV101")
                             {
-                                switch (getStackerObject.RGVCurrentlocation)
-                                {
-                                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //鍦ㄧ涓�涓瘝杞︿笂
-                                        RGVMovetask(HCJGoodsplatform, GdZiche.ChildPosiDeviceCode);
-                                        break;
-                                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //鍦ㄧ浜屼釜姣嶈溅涓�
-                                        OutNMotherCar(GdZiche.MotherCarDeviceCode);
-                                        break;
-                                    case int HCJaddress when HCJaddress == GdZiche.HCJStorageaddress:        //鍦℉CJ绔欏彴涓�
-                                        OutHCJMotherCar(GdZiche);
-                                        break;
-                                    default: return null;
-                                }
+                                //褰撴病浠诲姟鐨勬椂鍊欙紝鍒欒繘琛岀Щ鍔�
+                                Returnposition(speStackerCrane.DeviceCode, getStackerObject.RGVCurrentlocation);
                             }
-                            else
-                            {
-                                switch (getStackerObject.RGVCurrentlocation)
-                                {
-                                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //鍦ㄧ涓�涓瘝杞︿笂锛岄渶瑕佸垽鏂渚у瓙杞︽槸鍚﹀湪HCJ涓�
-                                        OutinnerSideNMotherCar(GdZiche);
-                                        break;
-                                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //鍦ㄧ浜屼釜姣嶈溅涓婏紝闇�瑕佸垽鏂瓙杞︿笌澶栦晶姣嶈溅鏄惁鍦ㄨ繃閬撲笂
-                                        OutNMotherCar(GdZiche.MotherCarDeviceCode);
-                                        break;
-                                    default: return null;
-                                }
-                            }
+                                
                         }
                         
 
                     }
                 }
-
-
             }
             catch (Exception ex)
             {
@@ -143,117 +115,91 @@
             return Task.CompletedTask;
         }
 
-        private Dt_Task? GetTask(string DeviceCode)
+        private Dt_Task? GetTask(string DeviceCode, GetStackerObject getStackerObject)
         {
-            Dt_Task task = _taskService.QueryStackerCraneTask(DeviceCode);
-            if (task == null) return null;
-
-            return task.TaskType switch
+            // 鏍规嵁璁惧鍚嶇О锛岃幏鍙栧埌璁惧鐩稿叧鏁版嵁
+            AGVStation RGVTaskdevice = _agvStationService.Corridorequipment(DeviceCode);   //鏍规嵁璁惧鑾峰彇鍒板唴瀹�
+            return RGVTaskdevice.Station_tasktype switch
             {
-                (int)TaskInboundTypeEnum.Inbound => HandleInboundTask(task),
-                (int)TaskOutboundTypeEnum.Outbound => HandleOutboundTask(task),
+                (int)RGVTasktype.Inbound => HandleInboundTask(RGVTaskdevice, getStackerObject),
+                (int)RGVTasktype.Outbound => OutboundEquipmentTask(RGVTaskdevice, getStackerObject),
                 _ => null
             };
-        }
 
-        private Dt_Task? HandleInboundTask(Dt_Task task)
-        {
-            return task.TaskState switch
-            {
-                (int)TaskInStatusEnum.RGV_InNew => task,
-                (int)TaskInStatusEnum.RGV_InPickupFinish => HandlePickupFinish(task),
-                (int)TaskInStatusEnum.RGV_InReleaseFinish => HandInneRouterSides(task),
-                (int)TaskInStatusEnum.RGV_InZicheFinish => HandleZicheFinish(task),
-                (int)TaskInStatusEnum.RGV_InZicheReleaseFinish => task,
-                (int)TaskInStatusEnum.RGV_InZichemoveFinish => HandleZicheMoveFinish(task),
-                _ => null
-            };
-        }
 
-        private Dt_Task? HandleOutboundTask(Dt_Task task)
-        {
-            // 鍑哄簱浠诲姟鐨勭姸鎬佸垽鏂浉瀵圭畝鍗曪紝鍙互鐩存帴杩斿洖
-            int[] validStates =
-            {
-                (int)TaskOutStatusEnum.OutNew,
-                (int)TaskOutStatusEnum.RGV_OutMothercarFinish,
-                (int)TaskOutStatusEnum.RGV_OutZicheFinish,
-                (int)TaskOutStatusEnum.RGV_OutZicheReleaseFinish,
-                (int)TaskOutStatusEnum.RGV_OutPickupFinish
-            };
-
-            return validStates.Contains(task.TaskState) ? task : null;
         }
 
         #region 鍏ュ簱鏂规硶
-
-        #region 鍏ュ簱鍙e彇璐у畬鎴愬悗锛岃繘琛屾斁璐э紙HCJ,寮傚父鍑哄簱鍙o級
-        private Dt_Task? HandlePickupFinish(Dt_Task task)
+        private Dt_Task? HandleInboundTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
         {
-            try
+            if(RGVTaskdevice.Station_material== (int)RGVEquipment.InRGVForklift && getStackerObject.RgvCraneStatusValue== RgvEquipmentStatus.NoCargo)
             {
-                //鑾峰彇闇�瑕佸尯鍒嗘槸鍚﹀幓鍏ュ簱涓庡幓涓嶅悎鏍艰浇璐у彴浠诲姟
-                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
-                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
-                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetDeviceProDTO(Commonstacker, task.NextAddress, "HCJ_GoodsStatus");
-                int HCJGStatus = GetDeviceAddress.GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
-                if (HCJGStatus == 0)    //涓烘棤璐�
-                {
-                    return task;
-                }
+                return _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode, 1);
             }
-            catch (Exception ex)
+            else if (RGVTaskdevice.Station_material == (int)RGVEquipment.InRGVForklift && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
             {
-                //璁板綍寮傚父鎯呭喌
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍒ゆ柇HCJ绔欏彴鏄惁鏈夎揣淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
-                throw;
+                return _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode, 2);
+            }else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
+            {
+                return ZichePickUpAisle(RGVTaskdevice, getStackerObject);
+            }else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
+            {
+                return GoodsPlacedCorridor(RGVTaskdevice, getStackerObject);
             }
+            else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
+            {
+                return ZicheMobile(RGVTaskdevice, getStackerObject);
+            }
+            else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Mothertrailer && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
+            {
+                return MotherVehicleMovement(RGVTaskdevice);
+            }
+            else { return null; }
 
-            return null;
         }
 
-        #endregion
 
-        #region 鍏ュ簱鍙f斁璐у畬鎴愬悗锛岃繘琛屽彇璐у唴瀹�
-        private Dt_Task? HandInneRouterSides(Dt_Task task)
+        #region 杩囬亾瀛愯溅杩涜鍙栬揣
+        public Dt_Task? ZichePickUpAisle(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
         {
-            // 鏍规嵁璁惧鍚嶇О锛岃幏鍙栧埌璁惧鐩稿叧鏁版嵁
-            AGVStation currentStation = _agvStationService.Corridorequipment(task.Roadway);
-
-            // 鑾峰彇瀛愯溅浣嶇疆
-            int zicheAddress = GetDeviceAddress.GetEquipmentlocation(currentStation.ChildPosiDeviceCode);
-            if (currentStation.Station_Area == 1)
+            //鑾峰彇瀛愯溅鍙栬揣浠诲姟
+            Dt_Task dt_Task = _taskService.GetInzicheTask(RGVTaskdevice.ChildPosiDeviceCode,1);
+            if(dt_Task.CurrentAddress== getStackerObject.RGVCurrentlocation.ToString())
             {
-                // 鏍规嵁瀛愯溅浣嶇疆澶勭悊涓嶅悓鎯呭喌
-                switch (zicheAddress)
-                {
-                    case int Whcjaddress when Whcjaddress == int.Parse(task.CurrentAddress):
-                        return task;
-                    case int Waddress when Waddress == currentStation.MotherCarDeviceCode:
-                        return task;
-                    case int Naddress when Naddress == currentStation.MotherCardeputy:
-                        return HandleMedialCase(task, currentStation.MotherCarDeviceCode);
-                    case int HCJaddress when HCJaddress == currentStation.HCJStorageaddress:
-                        return HandleMedialCase2(task, currentStation);
-                    default: return null;
-                }
+                return dt_Task;
             }
             else
             {
-                //鍙朒CJ浣嶇殑鏂欏垽鏂�
-                switch (zicheAddress)
+                //濡傛灉涓嶇瓑浜庯紝鍒欒繘琛屽垽鏂瓙杞﹀湪鍝釜浣嶇疆
+                if (RGVTaskdevice.Station_Area == 1)
                 {
-                    case int Whcjaddress when Whcjaddress == int.Parse(task.CurrentAddress):
-                        return task;
-                    case int Waddress when Waddress == currentStation.MotherCarDeviceCode:
-                        return task;
-                    case int Naddress when Naddress == currentStation.MotherCardeputy:
-                        return HandleMedialCase(task, currentStation.MotherCarDeviceCode);
-                    default: return null;
+                    // 鏍规嵁瀛愯溅浣嶇疆澶勭悊涓嶅悓鎯呭喌
+                    switch (getStackerObject.RGVCurrentlocation)
+                    {
+                        case int Waddress when Waddress == RGVTaskdevice.MotherCarDeviceCode:
+                            return dt_Task;
+                        case int Naddress when Naddress == RGVTaskdevice.MotherCardeputy:
+                            return HandleMedialCase(dt_Task, RGVTaskdevice.MotherCarDeviceCode);
+                        case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress:
+                            return HandleMedialCase2(dt_Task, RGVTaskdevice);
+                        default: return null;
+                    }
                 }
+                else
+                {
+                    //鍙朒CJ浣嶇殑鏂欏垽鏂�
+                    switch (getStackerObject.RGVCurrentlocation)
+                    {
+                        case int Waddress when Waddress == RGVTaskdevice.MotherCarDeviceCode:
+                            return dt_Task;
+                        case int Naddress when Naddress == RGVTaskdevice.MotherCardeputy:
+                            return HandleMedialCase(dt_Task, RGVTaskdevice.MotherCarDeviceCode);
+                        default: return null;
+                    }
+                }
+
             }
         }
-
         /// <summary>
         /// 鍒ゆ柇澶栦晶姣嶈溅鏄惁鍦ㄥ叆鍙e彛
         /// </summary>
@@ -296,22 +242,22 @@
             return null;
         }
 
+
         #endregion
 
-        #region 鍙栬揣瀹屾垚鍚庯紝杩涜鏀捐揣鎿嶄綔
-        private Dt_Task? HandleZicheFinish(Dt_Task task)
+        #region 杩囬亾瀛愯溅杩涜鏀捐揣
+        public Dt_Task? GoodsPlacedCorridor(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
         {
-            // 鏍规嵁璁惧鍚嶇О锛岃幏鍙栧埌璁惧鐩稿叧鏁版嵁
-            AGVStation GdaoRgvStation = _agvStationService.Corridorequipment(task.Roadway);
+            Dt_Task task = _taskService.GetInzicheTask(RGVTaskdevice.ChildPosiDeviceCode, 2);
             int nexaddres = int.Parse(task.NextAddress);
             switch (nexaddres)
             {
-                case int Whcjaddress when Whcjaddress == GdaoRgvStation.MotherCarDeviceCode:    //鏀捐揣鐐瑰湪绗竴涓繃閬撶偣
-                    return MotherCarMoves(task, GdaoRgvStation);
-                case int Waddress when Waddress == GdaoRgvStation.MotherCardeputy:              //鏀捐揣鐐瑰湪绗簩涓繃閬撶偣
-                    return MotherCarMovesinside(task, GdaoRgvStation);
-                case int HCJaddress when HCJaddress == GdaoRgvStation.HCJStorageaddress:        //鏀捐揣鐐瑰湪HCJ涓�
-                    return HCJMotherCarMovesinside(task, GdaoRgvStation);
+                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;
             }
         }
@@ -321,9 +267,11 @@
         private Dt_Task? MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
         {
             AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.ZicheMotherinlaw);
-            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+            
+            int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
             if (motherCarAddress == Muche.ZicheMotherinlaw) return _Task;
-            RGVMovetask(Muche.ZicheMotherinlaw, aGVStation.ChildPosiDeviceCode);
+            if(motherCarAddress!=0) RGVMovetask(Muche.ZicheMotherinlaw, aGVStation.ChildPosiDeviceCode);
+
             return null;
         }
 
@@ -338,14 +286,14 @@
             AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //澶栦晶姣嶈溅
             AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //鍐呬晶姣嶈溅
 
-            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
-            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
+            int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
+            int motherCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(Muche2.ChildPosiDeviceCode);
             // 濡傛灉姣嶈溅涓嶅湪棰勬湡浣嶇疆锛屼笅鍙戠Щ鍔ㄤ换鍔�
-            if (motherCarAddress != Muche.Motherinlaw)
+            if (motherCarAddress != Muche.Motherinlaw && motherCarAddress != 0)
             {
                 RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
             }
-            if (motherCarAddress2 != Muche2.ZicheMotherinlaw)
+            if (motherCarAddress2 != Muche2.ZicheMotherinlaw && motherCarAddress2 != 0)
             {
                 RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);
             }
@@ -353,59 +301,67 @@
             // 姣嶈溅宸插湪姝g‘浣嶇疆
             return null;
         }
+        /// <summary>
+        /// 鍒ゆ柇鏀惧湪HCJ涓婇潰
+        /// </summary>
+        /// <param name="_Task"></param>
+        /// <param name="aGVStation"></param>
+        /// <returns></returns>
         private Dt_Task? HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
         {
             AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //澶栦晶姣嶈溅
             AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //鍐呬晶姣嶈溅
-
             AGVStation Ziche3 = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //鍐呬晶瀛愯溅
 
-            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
-            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
-            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentlocation(Ziche3.ChildPosiDeviceCode);
+            int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
+            int motherCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(Muche2.ChildPosiDeviceCode);
+            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentInMuche(Ziche3.ChildPosiDeviceCode);
             // 濡傛灉姣嶈溅涓嶅湪棰勬湡浣嶇疆锛屼笅鍙戠Щ鍔ㄤ换鍔�
-            if (motherCarAddress != Muche.Motherinlaw)
+            if (motherCarAddress != Muche.Motherinlaw && motherCarAddress != 0)
             {
                 RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
             }
-            if (motherCarAddress2 != Muche2.Motherinlaw)
+            if (motherCarAddress2 != Muche2.Motherinlaw && motherCarAddress2 != 0)
             {
                 RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
             }
-            if(ZiCarAddress3== Ziche3.HCJStorageaddress)
+            if (ZiCarAddress3 == Ziche3.HCJStorageaddress && ZiCarAddress3!=0)
             {
                 //鍒ゆ柇鐩爣绔欏彴鏄叆搴撳埌鍑犲彿鍫嗗灈鏈�
                 if (_Task.TargetAddress == "3")     //鍏ュ簱鑷�3鍙峰爢鍨涙満
                 {
                     //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆锛�2鍖哄煙锛�
                     AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode);  //澶栦晶姣嶈溅
-                    int motNCarAddress = GetDeviceAddress.GetEquipmentlocation(MucheN.ChildPosiDeviceCode); //鑾峰彇鍒版瘝杞﹀綋鍓嶄綅缃�
-                    if(MucheN.ZicheMotherinlaw== motNCarAddress)
+                    int motNCarAddress = GetDeviceAddress.GetEquipmentInMuche(MucheN.ChildPosiDeviceCode); //鑾峰彇鍒版瘝杞﹀綋鍓嶄綅缃�
+                    if (motNCarAddress!=0)
                     {
-                        RGVMovetask(Ziche3.MotherCarDeviceCode, Ziche3.ChildPosiDeviceCode);
-                    }
-                    else
-                    {
-                        RGVMovetask(MucheN.ZicheMotherinlaw, MucheN.ChildPosiDeviceCode);
+                        if (MucheN.ZicheMotherinlaw == motNCarAddress)
+                        {
+                            RGVMovetask(Ziche3.MotherCarDeviceCode, Ziche3.ChildPosiDeviceCode);
+                        }
+                        else
+                        {
+                            RGVMovetask(MucheN.ZicheMotherinlaw, MucheN.ChildPosiDeviceCode);
+                        }
                     }
                 }
                 else if (_Task.TargetAddress == "4")    //鍏ュ簱鑷�4鍙峰爢鍨涙満
                 {
                     //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆锛�2鍖哄煙锛�
                     AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode);  //澶栦晶姣嶈溅
-                    int motNCarAddress = GetDeviceAddress.GetEquipmentlocation(MucheN.ChildPosiDeviceCode); //鑾峰彇鍒版瘝杞﹀綋鍓嶄綅缃�
-                    if (MucheN.Motherinlaw != motNCarAddress)
+                    int motNCarAddress = GetDeviceAddress.GetEquipmentInMuche(MucheN.ChildPosiDeviceCode); //鑾峰彇鍒版瘝杞﹀綋鍓嶄綅缃�
+                    if (MucheN.Motherinlaw != motNCarAddress && motNCarAddress!=0)
                     {
                         RGVMovetask(MucheN.Motherinlaw, MucheN.ChildPosiDeviceCode);
                     }
                     AGVStation MucheN2 = _agvStationService.GetMothervehicle(Ziche3.MotherCardeputy);  //澶栦晶姣嶈溅
-                    int motNCarAddress2 = GetDeviceAddress.GetEquipmentlocation(MucheN2.ChildPosiDeviceCode); //鑾峰彇鍒版瘝杞﹀綋鍓嶄綅缃�
-                    if (MucheN2.ZicheMotherinlaw != motNCarAddress2)
+                    int motNCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(MucheN2.ChildPosiDeviceCode); //鑾峰彇鍒版瘝杞﹀綋鍓嶄綅缃�
+                    if (MucheN2.ZicheMotherinlaw != motNCarAddress2 && motNCarAddress2!=0)
                     {
                         RGVMovetask(MucheN2.ZicheMotherinlaw, MucheN2.ChildPosiDeviceCode);
                     }
 
-                    if(MucheN.Motherinlaw == motNCarAddress && MucheN2.ZicheMotherinlaw == motNCarAddress2)
+                    if (MucheN.Motherinlaw == motNCarAddress && MucheN2.ZicheMotherinlaw == motNCarAddress2)
                     {
                         RGVMovetask(Ziche3.MotherCardeputy, Ziche3.ChildPosiDeviceCode);
                     }
@@ -418,13 +374,22 @@
         }
         #endregion
 
-        #region 姣嶈溅绉诲姩鑷冲叆搴撳彛
-        private Dt_Task? HandleZicheMoveFinish(Dt_Task task)
+        #region 瀛愯溅绉诲姩浠诲姟(鍚庣画鍙兘闇�瑕佷紭鍖栦竴涓�)
+        public Dt_Task? ZicheMobile(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
         {
+            Dt_Task task = _taskService.GetInzicheTaskMobile(RGVTaskdevice.ChildPosiDeviceCode, 1);
+            return task;
+        }
+        #endregion
+
+        #region 姣嶈溅绉诲姩浠诲姟
+        public Dt_Task? MotherVehicleMovement(AGVStation RGVTaskdevice)
+        {
+            Dt_Task task = _taskService.GetInzicheTaskMobile(RGVTaskdevice.ChildPosiDeviceCode, 2);
             int curradder = int.Parse(task.CurrentAddress);
             AGVStation GdZiche = _agvStationService.GetMotheaisle(curradder);
-            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(GdZiche.ChildPosiDeviceCode);
-            if (motherCarAddress != curradder) return task;
+            int motherCarAddress = GetDeviceAddress.GetEquipmentInformation(GdZiche.ChildPosiDeviceCode);
+            if (motherCarAddress != curradder && motherCarAddress!=0) return task;
             RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
             return null;
         }
@@ -432,8 +397,134 @@
 
         #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),
+
+                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.HasCargo)
+                    => Findshippingtask(RGVTaskdevice),
+
+                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.NoCargo)
+                    => _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
+                       RGVTaskdevice.HCJStorageaddress.ToString(), 1),
+
+                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.HasCargo)
+                    => _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
+                       RGVTaskdevice.HCJStorageaddress.ToString(), 2),
+
+                _ => 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 ZiCarAddress3 = GetDeviceAddress.GetEquipmentInformation(ZicheinnerSide.ChildPosiDeviceCode);
+
+            // 浣跨敤switch璇彞鎻愰珮鍙鎬�
+            return GdZiche.Station_Area switch
+            {
+                4 when ZiCarAddress3 != GdZiche.ZicheMotherinlaw
+                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
+
+                3 when ZiCarAddress3 == ZicheinnerSide.HCJStorageaddress
+                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
+
+                2 when ZiCarAddress3 != GdZiche.MotherCardeputy && ZiCarAddress3 != GdZiche.HCJStorageaddress
+                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
+
+                1 when ZiCarAddress3 == ZicheinnerSide.HCJStorageaddress
+                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
+
+                _ => null
+            };
+        }
+        #endregion
+
+        #region 鍒ゆ柇宸茬Щ鍔ㄥ嚭鏉ョ殑姣嶈溅锛屽啀鍒ゆ柇灏忚溅浣嶇疆
+        public Dt_Task? ChildPickupAddres(AGVStation GdZiche)
+        {
+            if (GdZiche.Station_Area == 5)
+                return _taskService.ChildVehicleMission(GdZiche);
+
+            var task = _taskService.ChildVehicleMission(GdZiche);
+
+            // 蹇�熻繑鍥炴潯浠舵鏌�
+            if (task.CurrentAddress != GdZiche.HCJStorageaddress.ToString())
+                return task;
+
+            var innerStation = _agvStationService.GetZicheDeep(GdZiche.HCJStorageaddress);
+            if (GetDeviceAddress.GetEquipmentInformation(innerStation.ChildPosiDeviceCode) != innerStation.HCJStorageaddress)
+                return task;
+
+            var motherStation = _agvStationService.GetMothervehicle(innerStation.MotherCarDeviceCode);
+            if (GetDeviceAddress.ReturnCurrentStatus(motherStation.ChildPosiDeviceCode))
+                RGVMovetask(innerStation.MotherCarDeviceCode, innerStation.ChildPosiDeviceCode);
+
+            return null;
+        }
+        #endregion
+
+        #region 鏌ユ壘瀛愯溅鏀捐揣浠诲姟
+        public Dt_Task? Findshippingtask(AGVStation GdZiche)
+        {
+            Dt_Task task = _taskService.GetFinhuoTask(GdZiche.ChildPosiDeviceCode);
+            if (GetDeviceAddress.HCJIsstock(task.NextAddress)) return task;
+            return null;
+        }
+        #endregion
+
+        #endregion
+
+        #region 鍑哄簱灏忚溅绉诲姩浠诲姟涓嬪彂
+        public void Returnposition(string DeviceCode, int RGVCurrentlocation)
+        {
+            int HCJGoodsplatform = 1170;    //瀹氫箟鐨勬斁璐х珯鍙�
+                                            //鍒ゆ柇姣嶈溅鏄惁闇�瑕佽繘琛岀Щ鍔�
+            AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);
+            if (GdZiche.Station_Area == 1)
+            {
+                switch (RGVCurrentlocation)
+                {
+                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //鍦ㄧ涓�涓瘝杞︿笂
+                        RGVMovetask(HCJGoodsplatform, GdZiche.ChildPosiDeviceCode);
+                        break;
+                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //鍦ㄧ浜屼釜姣嶈溅涓�
+                        OutNMotherCar(GdZiche.MotherCarDeviceCode);
+                        break;
+                    case int HCJaddress when HCJaddress == GdZiche.HCJStorageaddress:        //鍦℉CJ绔欏彴涓�
+                        OutHCJMotherCar(GdZiche);
+                        break;
+                    default: break;
+                }
+            }
+            else
+            {
+                switch (RGVCurrentlocation)
+                {
+                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //鍦ㄧ涓�涓瘝杞︿笂锛岄渶瑕佸垽鏂渚у瓙杞︽槸鍚﹀湪HCJ涓�
+                        OutinnerSideNMotherCar(GdZiche);
+                        break;
+                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //鍦ㄧ浜屼釜姣嶈溅涓婏紝闇�瑕佸垽鏂瓙杞︿笌澶栦晶姣嶈溅鏄惁鍦ㄨ繃閬撲笂
+                        OutinnerSideMotherCar(GdZiche);
+                        break;
+                    default: break;
+                }
+            }
+        }
 
         #region 澶栦晶灏忚溅鍥炲綊鍒拌捣濮嬬偣浣�
         /// <summary>
@@ -469,7 +560,6 @@
         }
         #endregion
 
-
         #region 澶栦晶灏忚溅鍥炲綊鍒拌捣濮嬬偣浣�
         /// <summary>
         /// 鍦ㄧ涓�涓綅缃紝鍒欏垽鏂渚у瓙杞︽槸鍚﹀湪HCJ绔欏彴涓嬮潰
@@ -479,38 +569,32 @@
         /// <returns></returns>
         private void OutinnerSideNMotherCar(AGVStation aGVStation)
         {
-            AGVStation Ziche3 = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //鍐呬晶瀛愯溅
+            AGVStation Ziche3 = _agvStationService.GetZicheOuterSide(aGVStation.HCJStorageaddress);    //澶栦晶瀛愯溅
             int ZiCarAddress3 = GetDeviceAddress.GetEquipmentlocation(Ziche3.ChildPosiDeviceCode);
             if (ZiCarAddress3 == Ziche3.HCJStorageaddress)
             {
-
+                OutHCJMotherCar(Ziche3);
             }
             else
             {
-                //RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
+                RGVMovetask(aGVStation.HCJStorageaddress, aGVStation.ChildPosiDeviceCode);
             }
         }
         private void OutinnerSideMotherCar(AGVStation aGVStation)
         {
             AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //澶栦晶姣嶈溅
-            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //鍐呬晶姣嶈溅
             int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
-            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
             // 濡傛灉姣嶈溅涓嶅湪棰勬湡浣嶇疆锛屼笅鍙戠Щ鍔ㄤ换鍔�
             if (motherCarAddress != Muche.Motherinlaw)
             {
                 RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
             }
-            if (motherCarAddress2 != Muche2.Motherinlaw)
-            {
-                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
-            }
+            OutinnerSideNMotherCar(aGVStation);
+
         }
         #endregion
 
-
         #endregion
-
 
 
         /// <summary>
@@ -571,10 +655,12 @@
             try
             {
                 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
-                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
+                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
-                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
-                int MCGStatus = GetDeviceAddress.GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
+                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetRGVDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
+                int MCGStatus = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
+
+
                 if (Commonstacker.IsConnected)
                 {
                     if (MCGStatus == (int)RgvJobCraneStatus.Ready)

--
Gitblit v1.9.3