From 6ba24a49c009cca01d9c02b9dae692a53b8be116 Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期三, 24 九月 2025 13:58:30 +0800
Subject: [PATCH] 入库

---
 代码管理/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs |  582 +++++++++++++++++++++++++++++++++------------------------
 1 files changed, 336 insertions(+), 246 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 8f5137d..b702e2e 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"
@@ -12,6 +12,7 @@
 using System.Diagnostics.Eventing.Reader;
 using System.Linq;
 using System.Reflection.Metadata;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Common.Log;
@@ -67,19 +68,17 @@
                     GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
 
                     //璇诲彇璁惧瀹屾垚淇℃伅
-                    if (getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Completed && getStackerObject.CurrentRgvtaskid!=0)
+                    if (getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Completed && getStackerObject.CurrentRgvtaskid != 0)
                     {
-                        _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid);
+                        _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid,2);
                     }
-                    
+
 
                     if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
                         getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
                     {
 
                         //涓嬪彂RGV浠诲姟涔嬪墠锛屽厛璇诲彇涓�涓嬪畨鍏ㄩ棬鐘舵��
-
-
 
                         //鏌ユ壘RGV杩涜涓嬪彂浠诲姟
                         Dt_Task task = GetTask(speStackerCrane.DeviceCode);
@@ -94,6 +93,43 @@
                                 _taskService.UpdateTaskStatusToNext(task);
                             }
                         }
+                        else
+                        {
+                            int HCJGoodsplatform = 1170;    //瀹氫箟鐨勬斁璐х珯鍙�
+
+                            //鍒ゆ柇姣嶈溅鏄惁闇�瑕佽繘琛岀Щ鍔�
+                            AGVStation GdZiche = _agvStationService.Corridorequipment(speStackerCrane.DeviceCode);
+                            if(GdZiche.Station_Area == 1)
+                            {
+                                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;
+                                }
+                            }
+                            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;
+                                }
+                            }
+                        }
+                        
 
                     }
                 }
@@ -124,11 +160,11 @@
         {
             return task.TaskState switch
             {
-                (int)TaskInStatusEnum.RGV_InNew => task,   
-                (int)TaskInStatusEnum.RGV_InPickupFinish => HandlePickupFinish(task),   
-                (int)TaskInStatusEnum.RGV_InReleaseFinish => task,  //闇�瑕佸垽鏂瓙杞︽槸鍐呬晶鍖鸿繕鏄渚у彇璐э紙寰呭畬鎴愶級
+                (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 => HandleZicheReleaseFinish(task),
+                (int)TaskInStatusEnum.RGV_InZicheReleaseFinish => task,
                 (int)TaskInStatusEnum.RGV_InZichemoveFinish => HandleZicheMoveFinish(task),
                 _ => null
             };
@@ -150,6 +186,8 @@
         }
 
         #region 鍏ュ簱鏂规硶
+
+        #region 鍏ュ簱鍙e彇璐у畬鎴愬悗锛岃繘琛屾斁璐э紙HCJ,寮傚父鍑哄簱鍙o級
         private Dt_Task? HandlePickupFinish(Dt_Task task)
         {
             try
@@ -157,8 +195,8 @@
                 //鑾峰彇闇�瑕佸尯鍒嗘槸鍚﹀幓鍏ュ簱涓庡幓涓嶅悎鏍艰浇璐у彴浠诲姟
                 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
                 CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
-                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, task.NextAddress, "HCJ_GoodsStatus");
-                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
+                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetDeviceProDTO(Commonstacker, task.NextAddress, "HCJ_GoodsStatus");
+                int HCJGStatus = GetDeviceAddress.GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                 if (HCJGStatus == 0)    //涓烘棤璐�
                 {
                     return task;
@@ -174,68 +212,306 @@
             return null;
         }
 
-        private Dt_Task? HandleZicheFinish(Dt_Task task)
-        {
-            //鑾峰彇鏀捐揣鍦板潃
-            AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.NextAddress));
+        #endregion
 
-            //鍒�3鍖哄煙杩涜鏀捐揣
-            return aGVStation.Station_Area switch
+        #region 鍏ュ簱鍙f斁璐у畬鎴愬悗锛岃繘琛屽彇璐у唴瀹�
+        private Dt_Task? HandInneRouterSides(Dt_Task task)
+        {
+            // 鏍规嵁璁惧鍚嶇О锛岃幏鍙栧埌璁惧鐩稿叧鏁版嵁
+            AGVStation currentStation = _agvStationService.Corridorequipment(task.Roadway);
+
+            // 鑾峰彇瀛愯溅浣嶇疆
+            int zicheAddress = GetDeviceAddress.GetEquipmentlocation(currentStation.ChildPosiDeviceCode);
+            if (currentStation.Station_Area == 1)
             {
-                1 => CheckMotherCarMove(task, aGVStation, MotherCarMoves),  //澶栦晶鏀捐揣
-                2 => CheckMotherCarMove(task, aGVStation, MotherCarMovesinside),    //鍐呬晶鏀捐揣
-                3 => CheckMotherCarMove(task, aGVStation, HCJMotherCarMovesinside),     //浜ゆ帴鐐规斁璐�
-                _ => null
-            };
+                // 鏍规嵁瀛愯溅浣嶇疆澶勭悊涓嶅悓鎯呭喌
+                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;
+                }
+            }
+            else
+            {
+                //鍙朒CJ浣嶇殑鏂欏垽鏂�
+                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);
+                    default: return null;
+                }
+            }
         }
 
-        private Dt_Task? CheckMotherCarMove(Dt_Task task, AGVStation station, Func<Dt_Task, AGVStation, bool> moveFunc)
+        /// <summary>
+        /// 鍒ゆ柇澶栦晶姣嶈溅鏄惁鍦ㄥ叆鍙e彛
+        /// </summary>
+        /// <param name="task"></param>
+        /// <param name="currentStation"></param>
+        /// <returns></returns>
+        private Dt_Task? HandleMedialCase(Dt_Task task, int currentStation)
         {
-            return moveFunc(task, station) ? task : null;
+            AGVStation Muche = _agvStationService.GetMothervehicle(currentStation);
+            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+            if (motherCarAddress == Muche.Motherinlaw) return task;
+            RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
+            return null;
         }
-
-        private Dt_Task? HandleZicheReleaseFinish(Dt_Task task)
+        /// <summary>
+        /// 鍒ゆ柇鍐呭渚ф瘝杞︽槸鍚﹀湪鍏ュ簱鍙�
+        /// </summary>
+        /// <param name="task"></param>
+        /// <param name="currentStation"></param>
+        /// <returns></returns>
+        private Dt_Task? HandleMedialCase2(Dt_Task task, AGVStation currentStation)
         {
-            AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));   //褰撳墠鍦板潃锛屾瘝杞︿笂锛屼笅涓�涓湴鍧�鍫嗗灈鏈哄彇璐у彛
-            if (aGVStation.Station_Area == 1 && aGVStation.Station_Area == 2)
-            {
-                return task;    //杩斿洖瀛愯溅绉诲姩浠诲姟
-            }
-            else if (aGVStation.Station_Area == 3)  //褰撳墠鍦板潃涓篐CJ绔欏彴锛屼笖AGV浠诲姟涓哄彇璐�
-            {
-                return task;    //鍘诲彇璐э紝闇�瑕佸垽鏂瓙杞﹀綋鍓嶄綅瀛愶紝锛堝悗缁紭鍖栵級
-            }
+            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;
         }
 
+        #endregion
+
+        #region 鍙栬揣瀹屾垚鍚庯紝杩涜鏀捐揣鎿嶄綔
+        private Dt_Task? HandleZicheFinish(Dt_Task task)
+        {
+            // 鏍规嵁璁惧鍚嶇О锛岃幏鍙栧埌璁惧鐩稿叧鏁版嵁
+            AGVStation GdaoRgvStation = _agvStationService.Corridorequipment(task.Roadway);
+            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);
+                default: return null;
+            }
+        }
+
+
+        //鍖哄煙涓�鍒ゆ柇姣嶈溅鏄惁鍒颁綅锛屽彲绔嬪嵆鏀捐揣
+        private Dt_Task? MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
+        {
+            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.ZicheMotherinlaw);
+            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+            if (motherCarAddress == Muche.ZicheMotherinlaw) return _Task;
+            RGVMovetask(Muche.ZicheMotherinlaw, aGVStation.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);  //澶栦晶姣嶈溅
+            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.ZicheMotherinlaw)
+            {
+                RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);
+            }
+            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.ZicheMotherinlaw) return _Task;
+            // 姣嶈溅宸插湪姝g‘浣嶇疆
+            return null;
+        }
+        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);
+            // 濡傛灉姣嶈溅涓嶅湪棰勬湡浣嶇疆锛屼笅鍙戠Щ鍔ㄤ换鍔�
+            if (motherCarAddress != Muche.Motherinlaw)
+            {
+                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
+            }
+            if (motherCarAddress2 != Muche2.Motherinlaw)
+            {
+                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
+            }
+            if(ZiCarAddress3== Ziche3.HCJStorageaddress)
+            {
+                //鍒ゆ柇鐩爣绔欏彴鏄叆搴撳埌鍑犲彿鍫嗗灈鏈�
+                if (_Task.TargetAddress == "3")     //鍏ュ簱鑷�3鍙峰爢鍨涙満
+                {
+                    //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆锛�2鍖哄煙锛�
+                    AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode);  //澶栦晶姣嶈溅
+                    int motNCarAddress = GetDeviceAddress.GetEquipmentlocation(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)
+                    {
+                        RGVMovetask(MucheN.Motherinlaw, MucheN.ChildPosiDeviceCode);
+                    }
+                    AGVStation MucheN2 = _agvStationService.GetMothervehicle(Ziche3.MotherCardeputy);  //澶栦晶姣嶈溅
+                    int motNCarAddress2 = GetDeviceAddress.GetEquipmentlocation(MucheN2.ChildPosiDeviceCode); //鑾峰彇鍒版瘝杞﹀綋鍓嶄綅缃�
+                    if (MucheN2.ZicheMotherinlaw != motNCarAddress2)
+                    {
+                        RGVMovetask(MucheN2.ZicheMotherinlaw, MucheN2.ChildPosiDeviceCode);
+                    }
+
+                    if(MucheN.Motherinlaw == motNCarAddress && MucheN2.ZicheMotherinlaw == motNCarAddress2)
+                    {
+                        RGVMovetask(Ziche3.MotherCardeputy, Ziche3.ChildPosiDeviceCode);
+                    }
+                }
+            }
+
+            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw && ZiCarAddress3 != Ziche3.HCJStorageaddress) return _Task;
+            // 姣嶈溅宸插湪姝g‘浣嶇疆
+            return null;
+        }
+        #endregion
+
+        #region 姣嶈溅绉诲姩鑷冲叆搴撳彛
         private Dt_Task? HandleZicheMoveFinish(Dt_Task task)
         {
-            AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));
-            int zicheAddress = GetZichelocation(task, task.CurrentAddress);
+            int curradder = int.Parse(task.CurrentAddress);
+            AGVStation GdZiche = _agvStationService.GetMotheaisle(curradder);
+            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(GdZiche.ChildPosiDeviceCode);
+            if (motherCarAddress != curradder) return task;
+            RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
+            return null;
+        }
+        #endregion
 
-            //濡傛灉瀛愯溅鍦ㄦ瘝杞︿笂锛屽垯闇�瑕佺Щ搴撴瘝杞︼紙寰呬紭鍖栵級
-            return zicheAddress != int.Parse(aGVStation.ZicheMotherinlaw) ? task : null;
+        #endregion
+
+
+        #region 鍑哄簱鏂规硶
+
+        #region 澶栦晶灏忚溅鍥炲綊鍒拌捣濮嬬偣浣�
+        /// <summary>
+        /// 鍒ゆ柇鏀剧浜屼釜姣嶈溅浣嶇疆
+        /// </summary>
+        /// <param name="_Task"></param>
+        /// <param name="aGVStation"></param>
+        /// <returns></returns>
+        private void OutNMotherCar(int MotherCarDeviceCode)
+        {
+            AGVStation Muche = _agvStationService.GetMothervehicle(MotherCarDeviceCode);  //澶栦晶姣嶈溅
+            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
+            if (motherCarAddress != Muche.Motherinlaw)
+            {
+                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
+            }
+        }
+        private void OutHCJMotherCar(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);
+            }
         }
         #endregion
 
 
-
-
-        //鍖哄煙涓�鍒ゆ柇姣嶈溅鏄惁鍒颁綅锛屽彲绔嬪嵆鏀捐揣
-        private bool MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
+        #region 澶栦晶灏忚溅鍥炲綊鍒拌捣濮嬬偣浣�
+        /// <summary>
+        /// 鍦ㄧ涓�涓綅缃紝鍒欏垽鏂渚у瓙杞︽槸鍚﹀湪HCJ绔欏彴涓嬮潰
+        /// </summary>
+        /// <param name="_Task"></param>
+        /// <param name="aGVStation"></param>
+        /// <returns></returns>
+        private void OutinnerSideNMotherCar(AGVStation aGVStation)
         {
-            int mcadder = GetMothercarlocation(_Task.TaskNum, aGVStation.Motherinlaw);      //鑾峰彇鍒版瘝杞﹀渚т綅缃�
-            if(mcadder != 0)
+            AGVStation Ziche3 = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //鍐呬晶瀛愯溅
+            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentlocation(Ziche3.ChildPosiDeviceCode);
+            if (ZiCarAddress3 == Ziche3.HCJStorageaddress)
             {
-                if (mcadder == int.Parse(_Task.CurrentAddress))
-                {
-                    return true;
-                }
-                 RGVMovetask(_Task.CurrentAddress, aGVStation.ChildPosiDeviceCode,_Task.TaskId);
+
             }
-            return false;
+            else
+            {
+                //RGVMovetask(Muche.Motherinlaw, Muche.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);
+            }
+        }
+        #endregion
+
+
+        #endregion
+
+
 
         /// <summary>
         /// 瀛愭瘝杞︾Щ鍔ㄤ换鍔�
@@ -243,164 +519,12 @@
         /// <param name="RGVAdders">鐩爣鍦板潃</param>
         /// <param name="ChildPosiDeviceCode">璁惧缂栧彿</param>
         /// <returns></returns>
-        private bool RGVMovetask(string RGVAdders,string ChildPosiDeviceCode,int taskid)
+        private bool RGVMovetask(int RGVAdders, string ChildPosiDeviceCode)
         {
             RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(RGVAdders);
             bool sendFlag = SendCommand2(standardCommands, ChildPosiDeviceCode);
-            _taskExecuteDetailService.AddTaskExecuteDetail(taskid, $"绯荤粺鑷姩娴佺▼锛屾墽琛屾瘝杞︾Щ鍔ㄤ换鍔★紝姣嶈溅缂栧彿锛歿ChildPosiDeviceCode}锛岀Щ鍔ㄥ湴鍧�锛歿RGVAdders}锛屾槸鍚︿笅鍙戞垚鍔燂細{sendFlag}");
-
             return sendFlag;
         }
-
-
-        /// <summary>
-        /// 鍒ゆ柇鍐呬晶姣嶈溅浣嶇疆
-        /// </summary>
-        /// <param name="_Task"></param>
-        /// <param name="aGVStation"></param>
-        /// <returns></returns>
-        private bool MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
-        {
-            //鑾峰彇澶栦晶姣嶈溅浣嶇疆
-            int mcadder = GetMothercarlocation(_Task.TaskNum, aGVStation.MotherCarDeviceCode);
-            //鑾峰彇鍐呬晶姣嶈溅浣嶇疆
-            int ncadder = GetMothercarlocation(_Task.TaskNum, _Task.NextAddress);
-
-            if (mcadder != int.Parse(aGVStation.MotherCarDeviceCode) && ncadder == aGVStation.Station_code)       
-            {
-                return true;
-            }
-            else
-            {
-                if (mcadder == int.Parse(aGVStation.MotherCarDeviceCode))  
-                {
-                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCarDeviceCode); 
-
-                    RGVMovetask(aGVSta.ChildPosiDeviceCode, aGVSta.Station_code.ToString(), _Task.TaskId);
-
-                }
-
-                if (ncadder != aGVStation.Station_code)   
-                {
-                    RGVMovetask(aGVStation.ChildPosiDeviceCode, aGVStation.Station_code.ToString(), _Task.TaskId);
-
-                }
-            }
-            return false;
-        }
-        private bool HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)  
-        {
-            //鑾峰彇澶栦晶姣嶈溅浣嶇疆
-            int mcadder = GetMothercarlocation(_Task.TaskNum, aGVStation.MotherCarDeviceCode);
-            //鑾峰彇鍐呬晶姣嶈溅浣嶇疆
-            int ncadder = GetMothercarlocation(_Task.TaskNum, 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);    
-
-                    RGVMovetask(aGVSta.ChildPosiDeviceCode, aGVSta.Station_code.ToString(), _Task.TaskId);
-
-                }
-
-                if (ncadder == int.Parse(aGVStation.MotherCardeputy))   
-                {
-                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCardeputy);    
-
-                    RGVMovetask(aGVSta.ChildPosiDeviceCode, aGVSta.Station_code.ToString(), _Task.TaskId);
-                }
-            }
-            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;
-        }
-
-
-
-        /// <summary>
-        /// 浼犲叆杩囬亾鍦板潃锛岃幏鍙栨瘝杞︿綅缃�
-        /// </summary>
-        /// <param name="task"></param>
-        /// <param name="MotherCarDeviceCode">杩囬亾鍦板潃</param>
-        /// <returns></returns>
-        public int GetMothercarlocation(int TaskNum, string MotherCarDeviceCode)
-        {
-            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(TaskNum, $"鍒ゆ柇姣嶈溅浣嶇疆淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
-                throw;
-            }
-        }
-
-
-        /// <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>
@@ -413,16 +537,16 @@
             short locaticurr = task.RGVTaskType switch
             {
                 _ when task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp ||
-                       task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly
+                       (task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType != (int)TaskInStatusEnum.RGV_InZichemoveFinish)
                     => short.Parse(task.CurrentAddress),
-                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.Placing
+                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.Placing || (task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType== (int)TaskInStatusEnum.RGV_InZichemoveFinish)
                     => short.Parse(task.NextAddress),
                 _ => (short)0
             };
             stackerCraneTaskCommand.RGV_RGVTasklocation = locaticurr;
             stackerCraneTaskCommand.RGV_RGVtasktype = (short)task.RGVTaskType;
-            stackerCraneTaskCommand.RGV_Rgvtaskid = (short)task.TaskNum;         
-            stackerCraneTaskCommand.RGV_Lanjiantaskid = (short)task.TaskNum;    
+            stackerCraneTaskCommand.RGV_Rgvtaskid = (short)task.TaskNum;
+            stackerCraneTaskCommand.RGV_Lanjiantaskid = (short)task.TaskNum;
             return stackerCraneTaskCommand;
         }
 
@@ -433,49 +557,15 @@
         /// <param name="task">浠诲姟瀹炰綋</param>
         /// <returns></returns>
         /// <exception cref="Exception"></exception>
-        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand(string RGVAddress)
+        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand(int RGVAddress)
         {
             RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
-            stackerCraneTaskCommand.RGV_RGVTasklocation = short.Parse(RGVAddress);
+            stackerCraneTaskCommand.RGV_RGVTasklocation = (short)RGVAddress;
             stackerCraneTaskCommand.RGV_RGVtasktype = 3;
             stackerCraneTaskCommand.RGV_Rgvtaskid = 999;          //rgv浠诲姟鍙�
             stackerCraneTaskCommand.RGV_Lanjiantaskid = 999;      //鍏板墤浠诲姟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
@@ -483,8 +573,8 @@
                 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                 CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
 
-                DeviceProDTO? deviceProDTO =  GetDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
-                int MCGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
+                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
+                int MCGStatus = GetDeviceAddress.GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                 if (Commonstacker.IsConnected)
                 {
                     if (MCGStatus == (int)RgvJobCraneStatus.Ready)

--
Gitblit v1.9.3