From 7059b12b4901d4307d130b2bc3846a8c6f7174a6 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期五, 12 九月 2025 11:30:55 +0800
Subject: [PATCH] 1

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob_FirstFloor/CommonRGV_FirstFloorJob.cs |  524 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 402 insertions(+), 122 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob_FirstFloor/CommonRGV_FirstFloorJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob_FirstFloor/CommonRGV_FirstFloorJob.cs"
index 1fb6714..82a3be1 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob_FirstFloor/CommonRGV_FirstFloorJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob_FirstFloor/CommonRGV_FirstFloorJob.cs"
@@ -129,12 +129,14 @@
                                                 if (IsExecutingTask.TaskType == (int)TaskInboundTypeEnum.Inbound)
                                                 {
                                                     IsExecutingTask.TargetStation = station.stationRemark;
+                                                    IsExecutingTask.TaskState = (int)TaskInStatusEnum.RGV_TransFer;
                                                 }
                                                 else
                                                 {
                                                     IsExecutingTask.TargetStation = station.remark;
+                                                    IsExecutingTask.TaskState = (int)TaskOutStatusEnum.RGV_TransFer;
                                                 }
-                                                IsExecutingTask.TaskState = (int)TaskInStatusEnum.RGV_TransFer;
+
                                                 _taskRepository.UpdateData(IsExecutingTask);
                                                 Thread.Sleep(1000);
                                             }
@@ -152,62 +154,68 @@
                         }
                         else
                         {
+
                             Dt_Task taskNew = null;
                             taskNew = GetTransFerTask(FirstRgv);
                             if (taskNew == null)
                             {
-                                taskNew = DispatchTask(FirstRgv);
+                                if (IsExistTransTask(FirstRgv))
+                                {
+                                    taskNew = DispatchTask(FirstRgv);
+                                }
                             }
                             if (taskNew != null)
-                            {
-                                RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(taskNew);
-                                if (rgvTaskCommand != null)
                                 {
-                                    Thread.Sleep(1000);
-                                    bool sendFlag = SendCommand(FirstRgv, rgvTaskCommand);
-                                    if (sendFlag)
+                                    RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(taskNew);
+                                    if (rgvTaskCommand != null)
                                     {
-                                        if (taskNew.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)
+                                        Thread.Sleep(1000);
+                                        bool sendFlag = SendCommand(FirstRgv, rgvTaskCommand);
+                                        if (sendFlag)
                                         {
-                                            taskNew.TaskState = (int)TaskInStatusEnum.RGV_InExecuting;
-                                            _taskRepository.UpdateData(taskNew);
-                                            Thread.Sleep(1000);
-                                        }
-                                        else if (taskNew.TaskState == (int)TaskOutStatusEnum.RGV_TransFerFInish)
-                                        {
-                                            taskNew.TaskState = (int)TaskOutStatusEnum.RGV_OutExecuting;
-                                            _taskRepository.UpdateData(taskNew);
-                                            Thread.Sleep(1000);
-                                        }
-                                        else if (taskNew.Remark != null)
-                                        {
-                                            taskNew.RGVName = "RGV02";
-                                            taskNew.CurrentAddress = taskNew.Remark;
-                                            taskNew.Remark = "";
-                                            taskNew.TaskState = (int)TaskOutStatusEnum.RGV_TransFer;
-                                            Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == taskNew.NextAddress);
-                                            taskNew.SourceStation = taskNew.CurrentAddress == "1025" ? 10 : 7;
-                                            if (taskNew.TaskType == (int)TaskInboundTypeEnum.Inbound)
+                                            if (taskNew.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)
                                             {
-                                                taskNew.TargetStation = station.stationRemark;
+                                                taskNew.TaskState = (int)TaskInStatusEnum.RGV_InExecuting;
+                                                _taskRepository.UpdateData(taskNew);
+                                                Thread.Sleep(1000);
+                                            }
+                                            else if (taskNew.TaskState == (int)TaskOutStatusEnum.RGV_TransFerFInish)
+                                            {
+                                                taskNew.TaskState = (int)TaskOutStatusEnum.RGV_OutExecuting;
+                                                _taskRepository.UpdateData(taskNew);
+                                                Thread.Sleep(1000);
+                                            }
+                                            else if (taskNew.Remark != null)
+                                            {
+                                                taskNew.RGVName = "RGV02";
+                                                taskNew.CurrentAddress = taskNew.Remark;
+                                                taskNew.Remark = "";
+                                                taskNew.TaskState = (int)TaskOutStatusEnum.RGV_TransFer;
+                                                Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == taskNew.NextAddress);
+                                                taskNew.SourceStation = taskNew.CurrentAddress == "1025" ? 10 : 7;
+                                                if (taskNew.TaskType == (int)TaskInboundTypeEnum.Inbound)
+                                                {
+                                                    taskNew.TargetStation = station.stationRemark;
+                                                }
+                                                else
+                                                {
+                                                    taskNew.TargetStation = station.remark;
+                                                }
+                                                _taskRepository.UpdateData(taskNew);
+                                                Thread.Sleep(1000);
                                             }
                                             else
                                             {
-                                                taskNew.TargetStation = station.remark;
+                                                taskNew.RGVName = FirstRgv.DeviceCode;
+                                                _taskRepository.UpdateData(taskNew);
+                                                _taskService.UpdateTaskStatusToNext(taskNew.TaskNum);
+                                                Thread.Sleep(1000);
                                             }
-                                            _taskRepository.UpdateData(taskNew);
-                                            Thread.Sleep(1000);
-                                        }
-                                        else
-                                        {
-                                            taskNew.RGVName = FirstRgv.DeviceCode;
-                                            _taskRepository.UpdateData(taskNew);
-                                            _taskService.UpdateTaskStatusToNext(taskNew.TaskNum);
-                                            Thread.Sleep(1000);
                                         }
                                     }
+
                                 }
-                            }
+                            
                         }
                     }
                     #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
@@ -288,15 +296,17 @@
                                                 IsExecutingTask.RGVName = "RGV01";
                                                 IsExecutingTask.CurrentAddress = IsExecutingTask.Remark;
                                                 IsExecutingTask.Remark = "";
-                                                IsExecutingTask.TaskState = (int)TaskInStatusEnum.RGV_TransFer;
+
                                                 Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == IsExecutingTask.NextAddress);
                                                 IsExecutingTask.SourceStation = IsExecutingTask.CurrentAddress == "1025" ? 10 : 7;
                                                 if (IsExecutingTask.TaskType == (int)TaskInboundTypeEnum.Inbound)
                                                 {
+                                                    IsExecutingTask.TaskState = (int)TaskInStatusEnum.RGV_TransFer;
                                                     IsExecutingTask.TargetStation = station.stationRemark;
                                                 }
                                                 else
                                                 {
+                                                    IsExecutingTask.TaskState = (int)TaskOutStatusEnum.RGV_TransFer;
                                                     IsExecutingTask.TargetStation = station.remark;
                                                 }
 
@@ -317,13 +327,16 @@
                         }
                         else
                         {
+
                             Dt_Task taskNew = null;
                             taskNew = GetTransFerTask(SecondRgv);
                             if (taskNew == null)
                             {
-                                taskNew = DispatchTask(SecondRgv);
+                                if (IsExistTransTask(SecondRgv))
+                                {
+                                    taskNew = DispatchTask(SecondRgv);
+                                }
                             }
-
                             if (taskNew != null)
                             {
                                 RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(taskNew);
@@ -364,6 +377,7 @@
                                     }
                                 }
                             }
+
                         }
                     }
                     #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
@@ -433,7 +447,6 @@
                     {
                         if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault))
                         {
-
                             var taskSecond = _taskRepository.QueryFirst(x => x.RGVName == "RGV02" && x.TaskNum == commonRGVSecond.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum) && ((x.TaskType == (int)TaskInboundTypeEnum.Inbound && (x.TaskState < 230||x.TaskState == (int)TaskInStatusEnum.RGV_TransFer|| x.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound)));
                             if (taskSecond != null)
                             {
@@ -447,11 +460,32 @@
 
                                             Thread.Sleep(1000);
 
-                                            if (task.Remark != null)
+                                            if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
                                             {
-                                                return GetDispatchExecutingTask(task);
+                                                task.Remark = "1025";
+                                                _taskRepository.UpdateData(task);
+                                                return GetDispatchExecutingTask(task, taskSecond);
                                             }
+                                            return task;
+                                        }
+                                    }
+                                }
+                                else if ((taskSecond.CurrentAddress == "1025" || taskSecond.CurrentAddress == "1026") && (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InExecuting))
+                                {
+                                    if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
+                                    {
+                                        if (task.TargetStation - taskSecond.SourceStation > 1 && task.TargetStation - taskSecond.TargetStation > 1)
+                                        {
+                                            LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGV.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVSecond.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskSecond)}銆憑commonRGVSecond.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
 
+                                            Thread.Sleep(1000);
+
+                                            if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
+                                            {
+                                                task.Remark = "1025";
+                                                _taskRepository.UpdateData(task);
+                                                return GetDispatchExecutingTask(task, taskSecond);
+                                            }
                                             return task;
                                         }
                                     }
@@ -464,9 +498,11 @@
                                         {
                                             LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGV.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVSecond.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskSecond)}銆憑commonRGVSecond.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
                                             Thread.Sleep(1000);
-                                            if (task.Remark != null)
+                                            if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
                                             {
-                                                return GetDispatchExecutingTask(task);
+                                                task.Remark = "1025";
+                                                _taskRepository.UpdateData(task);
+                                                return GetDispatchExecutingTask(task, taskSecond);
                                             }
                                             return task;
                                         }
@@ -482,6 +518,10 @@
                                 }
                                 if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 35000)
                                 {
+                                    if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running))
+                                    {
+                                        return null;
+                                    }
                                     RGVTaskCommand command = new RGVTaskCommand()
                                     {
                                         PickupLocation = (byte)Convert.ToSByte(15),
@@ -489,16 +529,28 @@
                                         TaskType = (byte)Convert.ToSByte(1)
                                     };
                                     SendCommand(commonRGVSecond, command);
-                                    Thread.Sleep(1000);
+                                    Thread.Sleep(3000);
                                     if (!commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running))
                                     {
                                         return null;
                                     }
                                 }
                                 Thread.Sleep(1000);
+                                if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
+                                {
+                                    task.Remark = "1025";
+                                    _taskRepository.UpdateData(task);
+                                    return GetDispatchExecutingTask(task);
+                                }
                                 return task;
                             }
                         }
+                    }
+                    if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
+                    {
+                        task.Remark = "1025";
+                        _taskRepository.UpdateData(task);
+                        return GetDispatchExecutingTask(task);
                     }
                     return task;
                 }
@@ -521,9 +573,30 @@
                                             LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGV.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVFirst.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskSecond)}銆憑commonRGVFirst.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
                                             Thread.Sleep(1000);
 
-                                            if (task.Remark != null)
+                                            if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
                                             {
-                                                return GetDispatchExecutingTask(task);
+                                                task.Remark = "1026";
+                                                _taskRepository.UpdateData(task);
+                                                return GetDispatchExecutingTask(task, taskSecond);
+                                            }
+                                            return task;
+                                        }
+                                    }
+                                }
+                                else if ((taskSecond.CurrentAddress == "1025" || taskSecond.CurrentAddress == "1026") && (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InExecuting))
+                                {
+                                    if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
+                                    {
+                                        if (taskSecond.SourceStation - task.TargetStation > 1 && taskSecond.TargetStation - task.TargetStation > 1)
+                                        {
+                                            LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGV.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVFirst.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskSecond)}銆憑commonRGVFirst.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
+                                            Thread.Sleep(1000);
+
+                                            if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
+                                            {
+                                                task.Remark = "1026";
+                                                _taskRepository.UpdateData(task);
+                                                return GetDispatchExecutingTask(task, taskSecond);
                                             }
                                             return task;
                                         }
@@ -538,9 +611,11 @@
                                             LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGV.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVFirst.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskSecond)}銆憑commonRGVFirst.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
                                             Thread.Sleep(1000);
 
-                                            if (task.Remark != null)
+                                            if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
                                             {
-                                                return GetDispatchExecutingTask(task);
+                                                task.Remark = "1026";
+                                                _taskRepository.UpdateData(task);
+                                                return GetDispatchExecutingTask(task, taskSecond);
                                             }
                                             return task;
                                         }
@@ -556,6 +631,10 @@
                                 }
                                 if (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) < 420000)
                                 {
+                                    if (commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running))
+                                    {
+                                        return null;
+                                    }
                                     RGVTaskCommand command = new RGVTaskCommand()
                                     {
                                         PickupLocation = (byte)Convert.ToSByte(26),
@@ -563,16 +642,28 @@
                                         TaskType = (byte)Convert.ToSByte(1)
                                     };
                                     SendCommand(commonRGVFirst, command);
-                                    Thread.Sleep(1000);
+                                    Thread.Sleep(3000);
                                     if (!commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running))
                                     {
                                         return null;
                                     }
                                 }
                                 Thread.Sleep(1000);
+                                if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
+                                {
+                                    task.Remark = "1026";
+                                    _taskRepository.UpdateData(task);
+                                    return GetDispatchExecutingTask(task);
+                                }
                                 return task;
                             }
                         }
+                    }
+                    if (task.Remark != null || ((task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV02" && task.TargetAddress == "1002") || (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.RGVName == "RGV01" && (task.TargetAddress == "1030" || task.TargetAddress == "1029"))))
+                    {
+                        task.Remark = "1026";
+                        _taskRepository.UpdateData(task);
+                        return GetDispatchExecutingTask(task);
                     }
                     return task;
                 }
@@ -602,13 +693,13 @@
                         if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault))
                         {
                             var taskSecond = _taskRepository.QueryFirst(x => x.RGVName == "RGV02" && x.TaskNum == commonRGVSecond.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum) && ((x.TaskType == (int)TaskInboundTypeEnum.Inbound && (x.TaskState < 230 || x.TaskState == (int)TaskInStatusEnum.RGV_TransFer || x.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound)));
-                             if (taskSecond != null)
+                            if (taskSecond != null)
                             {
                                 task = GetDispatchTask(tasks, taskSecond);
 
                                 LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆恵commonRGV.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVSecond.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskSecond)}銆憑commonRGVSecond.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
-                                Thread.Sleep(1000);
 
+                                Thread.Sleep(1000);
                                 return task;
                             }
                         }
@@ -623,6 +714,10 @@
                         }
                         if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 35000)
                         {
+                            if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running))
+                            {
+                                return null;
+                            }
                             RGVTaskCommand command = new RGVTaskCommand()
                             {
                                 PickupLocation = (byte)Convert.ToSByte(15),
@@ -630,40 +725,42 @@
                                 TaskType = (byte)Convert.ToSByte(1)
                             };
                             SendCommand(commonRGVSecond, command);
-                            Thread.Sleep(1000);
+                            Thread.Sleep(3000);
                             if (!commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running))
                             {
                                 return null;
                             }
                         }
-
-                        if (tasks.FirstOrDefault(x => x.RGVName == "RGV01") != null)
+                        task = GetDispatchTask(taskNews, "RGV01");
+                        if (task == null)
                         {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆恵commonRGVSecond.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戜綔涓氱姸鎬侊細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running)}銆戣澶囩姸鎬侊細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戞槸鍚︽湁璐э細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.InStock)}銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(taskNews.FirstOrDefault(x => x.RGVName == "RGV01").TaskNum)}銆戙��");
-                            Thread.Sleep(1000);
-                            return taskNews.FirstOrDefault(x => x.RGVName == "RGV01");
+                            return tasks.FirstOrDefault(x => x.RGVName != "RGV02");
                         }
-                        else
-                        {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆恵commonRGVSecond.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戜綔涓氱姸鎬侊細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running)}銆戣澶囩姸鎬侊細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戞槸鍚︽湁璐э細銆恵commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.InStock)}銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(taskNews.FirstOrDefault(x => x.RGVName != "RGV02").TaskNum)}銆戙��");
-                            Thread.Sleep(1000);
-                            return taskNews.FirstOrDefault(x => x.RGVName != "RGV02");
-                        }
+                        return task;
+                        //if (taskNews.FirstOrDefault(x => x.RGVName == "RGV01") != null)
+                        //{
+                        //    return taskNews.FirstOrDefault(x => x.RGVName == "RGV01");
+                        //}
+                        //else
+                        //{
+                        //    return taskNews.FirstOrDefault(x => x.RGVName != "RGV02");
+                        //}
                     }
                     else
                     {
-                        if (tasks.FirstOrDefault(x => x.RGVName == "RGV01") != null)
-                        {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV02璁惧淇℃伅銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName == "RGV01").TaskNum)}銆戙��");
-                            Thread.Sleep(1000);
-                            return tasks.FirstOrDefault(x => x.RGVName == "RGV01");
-                        }
-                        else
-                        {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV02璁惧淇℃伅銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName != "RGV02").TaskNum)}銆戙��");
-                            Thread.Sleep(1000);
-                            return tasks.FirstOrDefault(x => x.RGVName != "RGV02");
-                        }
+                        return GetDispatchTask(tasks, "RGV01");
+                        //if (tasks.FirstOrDefault(x => x.RGVName == "RGV01") != null)
+                        //{
+                        //    LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV02璁惧淇℃伅銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName == "RGV01").TaskNum)}銆戙��");
+                        //    Thread.Sleep(1000);
+                        //    return tasks.FirstOrDefault(x => x.RGVName == "RGV01");
+                        //}
+                        //else
+                        //{
+                        //    LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV02璁惧淇℃伅銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName != "RGV02").TaskNum)}銆戙��");
+                        //    Thread.Sleep(1000);
+                        //    return tasks.FirstOrDefault(x => x.RGVName != "RGV02");
+                        //}
                     }
                 }
                 else
@@ -679,7 +776,7 @@
                             {
                                 task = GetDispatchTask(tasks, taskFirst);
 
-                                LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGVFirst.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVFirst.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskFirst)}銆憑commonRGVFirst.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
+                                LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆恵commonRGVFirst.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVFirst.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskFirst)}銆憑commonRGVFirst.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
                                 Thread.Sleep(1000);
 
                                 return task;
@@ -696,6 +793,10 @@
                         }
                         if (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) < 420000)
                         {
+                            if (commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running))
+                            {
+                                return null;
+                            }
                             RGVTaskCommand command = new RGVTaskCommand()
                             {
                                 PickupLocation = (byte)Convert.ToSByte(26),
@@ -703,43 +804,44 @@
                                 TaskType = (byte)Convert.ToSByte(1)
                             };
                             SendCommand(commonRGVFirst, command);
-                            Thread.Sleep(1000);
+                            Thread.Sleep(3000);
                             if (!commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running))
                             {
                                 return null;
                             }
                         }
-
-                        if (tasks.FirstOrDefault(x => x.RGVName == "RGV02") != null)
+                        task = GetDispatchTask(taskNews, "RGV02");
+                        if (task == null)
                         {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆恵commonRGVFirst.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戜綔涓氱姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戞槸鍚︽湁璐э細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.InStock)}銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(taskNews.FirstOrDefault(x => x.RGVName == "RGV02").TaskNum)}銆戙��");
-                            Thread.Sleep(1000);
-                            return taskNews.FirstOrDefault(x => x.RGVName == "RGV02");
+                            return tasks.FirstOrDefault(x => x.RGVName != "RGV01");
                         }
-                        else
-                        {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆恵commonRGVFirst.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戜綔涓氱姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戞槸鍚︽湁璐э細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.InStock)}銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(taskNews.FirstOrDefault(x => x.RGVName != "RGV01").TaskNum)}銆戙��");
-
-                            Thread.Sleep(1000);
-                            return taskNews.FirstOrDefault(x => x.RGVName != "RGV01");
-                        }
+                        return task;
+                        //if (taskNews.FirstOrDefault(x => x.RGVName == "RGV02") != null)
+                        //{
+                        //    return taskNews.FirstOrDefault(x => x.RGVName == "RGV02");
+                        //}
+                        //else
+                        //{
+                        //    return taskNews.FirstOrDefault(x => x.RGVName != "RGV01");
+                        //}
                     }
                     else
                     {
-                        if (tasks.FirstOrDefault(x => x.RGVName == "RGV02") != null)
-                        {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV01璁惧淇℃伅銆� 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName == "RGV02").TaskNum)}銆戙��");
+                       return GetDispatchTask(tasks, "RGV02");
+                        //if (tasks.FirstOrDefault(x => x.RGVName == "RGV02") != null)
+                        //{
+                        //    LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV01璁惧淇℃伅銆� 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName == "RGV02").TaskNum)}銆戙��");
 
-                            Thread.Sleep(1000);
-                            return tasks.FirstOrDefault(x => x.RGVName == "RGV02");
-                        }
-                        else
-                        {
-                            LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV01璁惧淇℃伅銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName != "RGV01").TaskNum)}銆戙��");
+                        //    Thread.Sleep(1000);
+                        //    return tasks.FirstOrDefault(x => x.RGVName == "RGV02");
+                        //}
+                        //else
+                        //{
+                        //    LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV01璁惧淇℃伅銆戣繑鍥炰换鍔★細銆恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName != "RGV01").TaskNum)}銆戙��");
 
-                            Thread.Sleep(1000);
-                            return tasks.FirstOrDefault(x => x.RGVName != "RGV01");
-                        }
+                        //    Thread.Sleep(1000);
+                        //    return tasks.FirstOrDefault(x => x.RGVName != "RGV01");
+                        //}
                     }
                 }
             }
@@ -767,7 +869,6 @@
                     {
                         if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault))
                         {
-
                             var taskSecond = _taskRepository.QueryFirst(x => x.RGVName == "RGV02" && x.TaskNum == commonRGVSecond.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum) && ((x.TaskType == (int)TaskInboundTypeEnum.Inbound && (x.TaskState < 230 || x.TaskState == (int)TaskInStatusEnum.RGV_TransFer || x.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound)));
                             if (taskSecond != null)
                             {
@@ -799,6 +900,10 @@
                                 }
                                 if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 35000)
                                 {
+                                    if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running))
+                                    {
+                                        return null;
+                                    }
                                     RGVTaskCommand command = new RGVTaskCommand()
                                     {
                                         PickupLocation = (byte)Convert.ToSByte(15),
@@ -806,7 +911,7 @@
                                         TaskType = (byte)Convert.ToSByte(1)
                                     };
                                     SendCommand(commonRGVSecond, command);
-                                    Thread.Sleep(1000);
+                                    Thread.Sleep(3000);
                                     if (!commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running))
                                     {
                                         return null;
@@ -856,7 +961,7 @@
                                 if (taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                                 {
 
-                                    task = tasks.FirstOrDefault(x => ((x.SourceStation - taskFirst.TargetStation > 1 && x.SourceStation - taskFirst.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - taskFirst.TargetStation > 1 && x.TargetStation - taskFirst.SourceStation > 1 && x.SourceStation - taskFirst.SourceStation > 1 && x.TargetStation - taskFirst.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound)) && x.RGVName == "RGV02");
+                                    task = tasks.FirstOrDefault(x => ((taskFirst.TargetStation-x.SourceStation  > 1 &&taskFirst.SourceStation - x.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || ( taskFirst.TargetStation- x.SourceStation > 1 &&  taskFirst.SourceStation- x.TargetStation > 1 &&  taskFirst.SourceStation- x.SourceStation > 1 && taskFirst.TargetStation - x.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound)) && x.RGVName == "RGV02");
 
 
                                     LogAndWarn("涓浆璋冨害浠诲姟鎺у埗", $"銆恵commonRGVFirst.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVFirst.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskFirst)}銆憑commonRGVFirst.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task.TaskNum)}銆戙��");
@@ -882,6 +987,10 @@
                                 }
                                 if (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) < 420000)
                                 {
+                                    if (commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running))
+                                    {
+                                        return null;
+                                    }
                                     RGVTaskCommand command = new RGVTaskCommand()
                                     {
                                         PickupLocation = (byte)Convert.ToSByte(26),
@@ -889,7 +998,7 @@
                                         TaskType = (byte)Convert.ToSByte(1)
                                     };
                                     SendCommand(commonRGVFirst, command);
-                                    Thread.Sleep(1000);
+                                    Thread.Sleep(3000);
                                     if (!commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running))
                                     {
                                         return null;
@@ -934,6 +1043,21 @@
                 return null;
             }
         }
+
+        public bool IsExistTransTask(CommonRGV_FirstFloor commonRGV)
+        {
+            if (commonRGV.DeviceCode == "RGV01")
+            {
+                var task = _taskRepository.QueryFirst(x => x.Floor == "1F" && (x.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish || x.TaskState == (int)TaskOutStatusEnum.RGV_TransFerFInish)&&x.RGVName=="RGV02");
+                return task == null ? true : false;
+            }
+            else
+            {
+                var task = _taskRepository.QueryFirst(x => x.Floor == "1F" && (x.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish || x.TaskState == (int)TaskOutStatusEnum.RGV_TransFerFInish) && x.RGVName == "RGV01");
+                return task == null ? true : false;
+            }  
+        }
+
 
         /// <summary>
         /// RGV浠诲姟瀹屾垚
@@ -1029,24 +1153,49 @@
             return null;
         }
 
-        public Dt_Task? GetDispatchTask(List<Dt_Task> tasks, Dt_Task oldtask)
+        public Dt_Task? GetDispatchTask(List<Dt_Task> tasks,Dt_Task oldtask)
         {
             Dt_Task y = tasks.Where(x => x.Remark != null&& ((x.SourceStation - oldtask.TargetStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.SourceStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TargetStation - oldtask.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound))).FirstOrDefault();
             if (y == null)
             {
-                LogAndWarn("鏌ヨ浠诲姟", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(oldtask)}銆戙��");
+                WriteInfo("鏌ヨ浠诲姟", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(oldtask)}銆戙��");
                 if (oldtask.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || oldtask.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || oldtask.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                 {
-
-                    return tasks.FirstOrDefault(x => (x.SourceStation - oldtask.TargetStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.SourceStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TargetStation - oldtask.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
+                    if (oldtask.RGVName == "RGV01")
+                    {
+                        return tasks.FirstOrDefault(x => (oldtask.TargetStation - x.SourceStation > 1 && oldtask.SourceStation - x.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (oldtask.TargetStation - x.SourceStation > 1 && oldtask.SourceStation - x.TargetStation > 1 && oldtask.SourceStation - x.SourceStation > 1 && oldtask.TargetStation - x.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
+                    }
+                    else
+                    {
+                        return tasks.FirstOrDefault(x => (x.SourceStation - oldtask.TargetStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.SourceStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TargetStation - oldtask.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
+                        
+                    }
                 }
                 else if ((oldtask.CurrentAddress == "1025" || oldtask.CurrentAddress == "1026") && (oldtask.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || oldtask.TaskState == (int)TaskInStatusEnum.RGV_InExecuting))
                 {
-                    return tasks.FirstOrDefault(x => (x.SourceStation - oldtask.TargetStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.SourceStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TargetStation - oldtask.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
+                    if (oldtask.RGVName == "RGV01")
+                    {
+                        return tasks.FirstOrDefault(x => (oldtask.TargetStation - x.SourceStation > 1 && oldtask.SourceStation - x.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (oldtask.TargetStation - x.SourceStation > 1 && oldtask.SourceStation - x.TargetStation > 1 && oldtask.SourceStation - x.SourceStation > 1 && oldtask.TargetStation - x.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
+                    }
+                    else
+                    {
+                        return tasks.FirstOrDefault(x => (x.SourceStation - oldtask.TargetStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.SourceStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TargetStation - oldtask.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
+
+                    }
+
                 }
                 else if (oldtask.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || oldtask.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                 {
-                    return tasks.FirstOrDefault(x => x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.TargetStation > 1);
+                    if (oldtask.RGVName == "RGV01")
+                    {
+                        return tasks.FirstOrDefault(x => oldtask.TargetStation - x.SourceStation > 1 && oldtask.TargetStation - x.TargetStation > 1);
+                        
+                    }
+                    else
+                    {
+                        return tasks.FirstOrDefault(x => x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.TargetStation > 1);
+                    }
+                    
                 }
                 
                 return null;
@@ -1079,6 +1228,10 @@
 
                     return tasks.FirstOrDefault(x => (x.SourceStation - oldtask.TargetStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.SourceStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TargetStation - oldtask.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
                 }
+                else if ((oldtask.CurrentAddress == "1025" || oldtask.CurrentAddress == "1026") && (oldtask.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || oldtask.TaskState == (int)TaskInStatusEnum.RGV_InExecuting))
+                {
+                    return tasks.FirstOrDefault(x => (x.SourceStation - oldtask.TargetStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.SourceStation > 1 && x.SourceStation - oldtask.SourceStation > 1 && x.TargetStation - oldtask.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
+                }
                 else if (oldtask.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || oldtask.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                 {
                     return tasks.FirstOrDefault(x => x.SourceStation - oldtask.TargetStation > 1 && x.TargetStation - oldtask.TargetStation > 1);
@@ -1087,30 +1240,157 @@
             }
         }
 
-        public Dt_Task? GetDispatchExecutingTask(Dt_Task oldtask)
+        public Dt_Task? GetDispatchTask(List<Dt_Task> tasks,string RGVName)
         {
-            var stationManager = _stationManagerRepository.QueryData(x => x.stationType == 15);
-            if (stationManager.Count() > 0)
+            Dt_Task y = tasks.Where(x => x.Remark != null).FirstOrDefault();
+            if (y == null)
+            {
+                if (RGVName == "RGV01")
+                {
+                    if (tasks.FirstOrDefault(x => x.RGVName == RGVName) != null)
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName == RGVName);
+                    }
+                    else
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName != "RGV02");
+                    }
+                }
+                else
+                {
+                    if (tasks.FirstOrDefault(x => x.RGVName == RGVName) != null)
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName == RGVName);
+                    }
+                    else
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName != "RGV01");
+                    }
+                }
+            }
+            else
+            {
+                var stationManager = _stationManagerRepository.QueryData(x => x.stationType == 15);
+                if (stationManager.Count() > 0)
+                {
+                    string next = null;
+                    foreach (var item in stationManager)
+                    {
+                        var x = _taskRepository.QueryFirst(x => x.NextAddress == item.stationChildCode || x.CurrentAddress == item.stationChildCode);
+                        if (x == null)
+                        {
+                            next = item.stationChildCode;
+                            break;
+                        }
+                    }
+                    if (next != null)
+                    {
+                        y.Remark = next;
+                        _taskRepository.UpdateData(y);
+                        LogAndWarn("涓浆浠诲姟", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(y)}銆戙��");
+                        return y;
+                    }
+                }
+                if (RGVName == "RGV01")
+                {
+                    if (tasks.FirstOrDefault(x => x.RGVName == RGVName) != null)
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName == RGVName);
+                    }
+                    else
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName != "RGV02");
+                    }
+                }
+                else
+                {
+                    if (tasks.FirstOrDefault(x => x.RGVName == RGVName) != null)
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName == RGVName);
+                    }
+                    else
+                    {
+                        return tasks.FirstOrDefault(x => x.RGVName != "RGV01");
+                    }
+                }
+            }
+        }
+
+        public Dt_Task? GetDispatchExecutingTask(Dt_Task oldtask,Dt_Task task)
+        {
+            var stationManagers = _stationManagerRepository.QueryData(x => x.stationType == 15);
+            if (stationManagers.Count() > 0)
             {
                 string next = null;
-                foreach (var item in stationManager)
+                foreach (var item in stationManagers)
                 {
                     var x = _taskRepository.QueryFirst(x => x.NextAddress == item.stationChildCode || x.CurrentAddress == item.stationChildCode);
                     if (x == null)
                     {
                         next = item.stationChildCode;
+                        LogAndWarn("涓浆鑾峰彇绔欏彴", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(x)}銆戙�戙�恵next}銆�");
                         break;
                     }
                 }
                 if (next != null)
                 {
+                    var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == next);
+                    oldtask.Remark = next;
+                    //oldtask.CurrentAddress = next;
+                    _taskRepository.UpdateData(oldtask);
+                    if (task.RGVName == "RGV01")
+                    {
+                        if (task.TargetStation - stationManager.stationRemark > 1 && task.SourceStation - stationManager.stationRemark > 1 && task.SourceStation - oldtask.SourceStation > 1 && task.TargetStation - oldtask.SourceStation > 1)
+                        {
+                            LogAndWarn("涓浆浠诲姟GetDispatchExecutingTask", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(oldtask)}銆戙�戙�恵next}銆�");
+                            return oldtask;
+                        }
+                        else
+                        {
+                            return null;
+                        }
+                    }
+                    else
+                    {
+                        if (stationManager.stationRemark - task.TargetStation > 1 && stationManager.stationRemark - task.SourceStation > 1 && oldtask.SourceStation - task.SourceStation > 1 && oldtask.SourceStation - task.TargetStation > 1)
+                        {
+                            LogAndWarn("涓浆浠诲姟GetDispatchExecutingTask", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(oldtask)}銆戙��");
+                            return oldtask;
+                        }
+                        else
+                        {
+                            return null;
+                        }
+                    } 
+                }
+            }
+            return null;
+        }
+
+        public Dt_Task? GetDispatchExecutingTask(Dt_Task oldtask)
+        {
+            var stationManagers = _stationManagerRepository.QueryData(x => x.stationType == 15);
+            if (stationManagers.Count() > 0)
+            {
+                string next = null;
+                foreach (var item in stationManagers)
+                {
+                    var x = _taskRepository.QueryFirst(x => x.NextAddress == item.stationChildCode || x.CurrentAddress == item.stationChildCode);
+                    if (x == null)
+                    {
+                        next = item.stationChildCode;
+                        LogAndWarn("涓浆鑾峰彇绔欏彴", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(x)}銆戙�戙�恵next}銆�");
+                        break;
+                    }
+                }
+                if (next != null)
+                {
+                    var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == next);
                     oldtask.Remark = next;
                     _taskRepository.UpdateData(oldtask);
-                    LogAndWarn("涓浆浠诲姟GetDispatchExecutingTask", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(oldtask)}銆戙��");
                     return oldtask;
                 }
             }
-
             return null;
         }
 

--
Gitblit v1.9.3