From cfc2c35552e6a0ec66e962b52d120b34bc10fc83 Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期五, 12 九月 2025 15:42:57 +0800
Subject: [PATCH] 出入库

---
 代码管理/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs |  451 ++++++++++++++++++++++++-------------------------------
 1 files changed, 198 insertions(+), 253 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..8f5137d 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"
@@ -56,9 +56,6 @@
             _agvStationService = agvStationService;
         }
 
-        public string ziche001 = "RGV104";
-        public string ziche002 = "RGV107";
-
 
         public Task Execute(IJobExecutionContext context)
         {
@@ -110,280 +107,219 @@
             return Task.CompletedTask;
         }
 
-        /// <summary>
-        /// 鑾峰彇浠诲姟锛堟殏鏃舵柟娉昳f鍒ゆ柇锛�
-        /// </summary>
-        /// <param name="DeviceCode"></param>
-        /// <param name="RGVCurrentlocation"></param>
-        /// <returns></returns>
         private Dt_Task? GetTask(string DeviceCode)
         {
-            Dt_Task task;
-            task = _taskService.QueryStackerCraneTask(DeviceCode);
-            if (task != null)
+            Dt_Task task = _taskService.QueryStackerCraneTask(DeviceCode);
+            if (task == null) return null;
+
+            return task.TaskType switch
             {
-                //鍒ゆ柇鍏ュ簱浠诲姟
-                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);
-                            }
-                        }
-
-                        //杩涜绉诲姩瀛愯溅
-
-                    }
-                    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)
-                {
-                    if (task.TaskState == (int)TaskOutStatusEnum.OutNew)
-                    {
-                        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 null;
+                (int)TaskInboundTypeEnum.Inbound => HandleInboundTask(task),
+                (int)TaskOutboundTypeEnum.Outbound => HandleOutboundTask(task),
+                _ => null
+            };
         }
 
-        //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆
-        private bool MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
+        private Dt_Task? HandleInboundTask(Dt_Task task)
         {
-            int mcadder = GetMothercarlocation(_Task, aGVStation.Motherinlaw);
-            if(mcadder != 0)
+            return task.TaskState switch
             {
-                if (mcadder == int.Parse(_Task.CurrentAddress))       //鍒ゆ柇瀛愯溅瑕佸幓鐨勪綅缃紝姣嶈溅鏄惁鍦ㄨ浣嶇疆
-                {
-                    return true;
-                }
-                else
-                {
-                    //涓嬪彂姣嶈溅绉诲姩鍑烘潵鎺ヨ揣浠诲姟
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, _Task.CurrentAddress);
-                    
-                    bool sendFlag = SendCommand2(standardCommands, aGVStation.ChildPosiDeviceCode);
-                    if (sendFlag)
-                    {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
-                    }
-                }
-            }
-
-            return false;
+                (int)TaskInStatusEnum.RGV_InNew => task,   
+                (int)TaskInStatusEnum.RGV_InPickupFinish => HandlePickupFinish(task),   
+                (int)TaskInStatusEnum.RGV_InReleaseFinish => task,  //闇�瑕佸垽鏂瓙杞︽槸鍐呬晶鍖鸿繕鏄渚у彇璐э紙寰呭畬鎴愶級
+                (int)TaskInStatusEnum.RGV_InZicheFinish => HandleZicheFinish(task),
+                (int)TaskInStatusEnum.RGV_InZicheReleaseFinish => HandleZicheReleaseFinish(task),
+                (int)TaskInStatusEnum.RGV_InZichemoveFinish => HandleZicheMoveFinish(task),
+                _ => null
+            };
         }
 
-        //鍒ゆ柇鍐呬晶姣嶈溅浣嶇疆
-        private bool MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
+        private Dt_Task? HandleOutboundTask(Dt_Task task)
         {
-            //鑾峰彇澶栦晶姣嶈溅浣嶇疆
-            int mcadder = GetMothercarlocation(_Task, aGVStation.MotherCarDeviceCode);
-            //鑾峰彇鍐呬晶姣嶈溅浣嶇疆
-            int ncadder = GetMothercarlocation(_Task, _Task.CurrentAddress);    //浼犲叆杩囬亾鐨勫湴鍧�
-
-            if (mcadder != int.Parse(aGVStation.MotherCarDeviceCode) && ncadder == aGVStation.Station_code)       //鍒ゆ柇澶栦晶姣嶈溅浣嶇疆
+            // 鍑哄簱浠诲姟鐨勭姸鎬佸垽鏂浉瀵圭畝鍗曪紝鍙互鐩存帴杩斿洖
+            int[] validStates =
             {
-                return true;
-            }
-            else
-            {
-                if (mcadder == int.Parse(aGVStation.MotherCarDeviceCode))    //澶栦晶姣嶈溅闇�瑕佺Щ鍔�
-                {
-                    //涓嬪彂姣嶈溅寰�閲岄潰璧扮殑浠诲姟
-                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCarDeviceCode);    //鍫嗗灈鏈哄叆搴撳彛
+                (int)TaskOutStatusEnum.OutNew,
+                (int)TaskOutStatusEnum.RGV_OutMothercarFinish,
+                (int)TaskOutStatusEnum.RGV_OutZicheFinish,
+                (int)TaskOutStatusEnum.RGV_OutZicheReleaseFinish,
+                (int)TaskOutStatusEnum.RGV_OutPickupFinish
+            };
 
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVSta.Station_code.ToString()); //涓嬪彂姣嶈溅绉诲姩鑷冲叆搴撶珯鍙颁綅
-                    bool sendFlag = SendCommand2(standardCommands, aGVSta.ChildPosiDeviceCode);
-                    if (sendFlag)
-                    {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
-                    }
-                }
-
-                if (ncadder != aGVStation.Station_code)    //涓嬪彂姣嶈溅
-                {
-                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVStation.Station_code.ToString());
-                    bool sendFlag = SendCommand2(standardCommands, aGVStation.ChildPosiDeviceCode);
-                    if (sendFlag)
-                    {
-                        //璁板綍涓嬪彂杩囨瘝杞︾Щ鍔ㄤ换鍔�
-                        _taskService.UpdateTaskStatusToNext(_Task);
-                    }
-                }
-            }
-            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;
+            return validStates.Contains(task.TaskState) ? task : null;
         }
 
-        
-
-        public bool QueryCurrentAdder(Dt_Task task)
+        #region 鍏ュ簱鏂规硶
+        private Dt_Task? HandlePickupFinish(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");
+                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, task.NextAddress, "HCJ_GoodsStatus");
                 int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                 if (HCJGStatus == 0)    //涓烘棤璐�
                 {
-                    return true;
+                    return task;
                 }
             }
             catch (Exception ex)
             {
                 //璁板綍寮傚父鎯呭喌
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum,$"鍒ゆ柇HCJ绔欏彴鏄惁鏈夎揣淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
+                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍒ゆ柇HCJ绔欏彴鏄惁鏈夎揣淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
                 throw;
             }
 
+            return null;
+        }
+
+        private Dt_Task? HandleZicheFinish(Dt_Task task)
+        {
+            //鑾峰彇鏀捐揣鍦板潃
+            AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.NextAddress));
+
+            //鍒�3鍖哄煙杩涜鏀捐揣
+            return aGVStation.Station_Area switch
+            {
+                1 => CheckMotherCarMove(task, aGVStation, MotherCarMoves),  //澶栦晶鏀捐揣
+                2 => CheckMotherCarMove(task, aGVStation, MotherCarMovesinside),    //鍐呬晶鏀捐揣
+                3 => CheckMotherCarMove(task, aGVStation, HCJMotherCarMovesinside),     //浜ゆ帴鐐规斁璐�
+                _ => null
+            };
+        }
+
+        private Dt_Task? CheckMotherCarMove(Dt_Task task, AGVStation station, Func<Dt_Task, AGVStation, bool> moveFunc)
+        {
+            return moveFunc(task, station) ? task : null;
+        }
+
+        private Dt_Task? HandleZicheReleaseFinish(Dt_Task task)
+        {
+            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;    //鍘诲彇璐э紝闇�瑕佸垽鏂瓙杞﹀綋鍓嶄綅瀛愶紝锛堝悗缁紭鍖栵級
+            }
+
+            return null;
+        }
+
+        private Dt_Task? HandleZicheMoveFinish(Dt_Task task)
+        {
+            AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));
+            int zicheAddress = GetZichelocation(task, task.CurrentAddress);
+
+            //濡傛灉瀛愯溅鍦ㄦ瘝杞︿笂锛屽垯闇�瑕佺Щ搴撴瘝杞︼紙寰呬紭鍖栵級
+            return zicheAddress != int.Parse(aGVStation.ZicheMotherinlaw) ? task : null;
+        }
+        #endregion
+
+
+
+
+        //鍖哄煙涓�鍒ゆ柇姣嶈溅鏄惁鍒颁綅锛屽彲绔嬪嵆鏀捐揣
+        private bool MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
+        {
+            int mcadder = GetMothercarlocation(_Task.TaskNum, aGVStation.Motherinlaw);      //鑾峰彇鍒版瘝杞﹀渚т綅缃�
+            if(mcadder != 0)
+            {
+                if (mcadder == int.Parse(_Task.CurrentAddress))
+                {
+                    return true;
+                }
+                 RGVMovetask(_Task.CurrentAddress, aGVStation.ChildPosiDeviceCode,_Task.TaskId);
+            }
             return false;
         }
+
+        /// <summary>
+        /// 瀛愭瘝杞︾Щ鍔ㄤ换鍔�
+        /// </summary>
+        /// <param name="RGVAdders">鐩爣鍦板潃</param>
+        /// <param name="ChildPosiDeviceCode">璁惧缂栧彿</param>
+        /// <returns></returns>
+        private bool RGVMovetask(string RGVAdders,string ChildPosiDeviceCode,int taskid)
+        {
+            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)
@@ -417,12 +353,12 @@
         /// <param name="task"></param>
         /// <param name="MotherCarDeviceCode">杩囬亾鍦板潃</param>
         /// <returns></returns>
-        public int GetMothercarlocation(Dt_Task task,string MotherCarDeviceCode)
+        public int GetMothercarlocation(int TaskNum, string MotherCarDeviceCode)
         {
             try
             {
                 //鍒╃敤鍏ュ簱绔欏彴鍦板潃鑾峰彇姣嶈溅plc
-                AGVStation aGVStation =_agvStationService.GetMothercarCode(MotherCarDeviceCode);
+                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");
@@ -432,7 +368,7 @@
             catch (Exception ex)
             {
                 //璁板綍寮傚父鎯呭喌
-                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍒ゆ柇姣嶈溅浣嶇疆淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
+                _taskService.UpdateTaskExceptionMessage(TaskNum, $"鍒ゆ柇姣嶈溅浣嶇疆淇℃伅鍑洪敊锛屽嚭閿欎俊鎭細{ex.Message}");
                 throw;
             }
         }
@@ -474,10 +410,19 @@
         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.RGVTaskType switch
+            {
+                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp ||
+                       task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly
+                    => short.Parse(task.CurrentAddress),
+                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.Placing
+                    => 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;    
             return stackerCraneTaskCommand;
         }
 
@@ -488,10 +433,10 @@
         /// <param name="task">浠诲姟瀹炰綋</param>
         /// <returns></returns>
         /// <exception cref="Exception"></exception>
-        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand([NotNull] Dt_Task task,string CurrentAddress)
+        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand(string RGVAddress)
         {
             RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
-            stackerCraneTaskCommand.RGV_RGVTasklocation = short.Parse(CurrentAddress);
+            stackerCraneTaskCommand.RGV_RGVTasklocation = short.Parse(RGVAddress);
             stackerCraneTaskCommand.RGV_RGVtasktype = 3;
             stackerCraneTaskCommand.RGV_Rgvtaskid = 999;          //rgv浠诲姟鍙�
             stackerCraneTaskCommand.RGV_Lanjiantaskid = 999;      //鍏板墤浠诲姟id

--
Gitblit v1.9.3