huangxiaoqiang
4 天以前 7f42a3ef9bc83bdc199317d12c1905d8696dac4f
ÏîÄ¿´úÂë/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);
                                            }
@@ -288,15 +290,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;
                                                }
@@ -446,11 +450,12 @@
                                            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"))))
                                            {
                                                task.Remark = "1025";
                                                _taskRepository.UpdateData(task);
                                                return GetDispatchExecutingTask(task, taskSecond);
                                            }
                                            return task;
                                        }
                                    }
@@ -465,11 +470,12 @@
                                            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"))))
                                            {
                                                task.Remark = "1025";
                                                _taskRepository.UpdateData(task);
                                                return GetDispatchExecutingTask(task, taskSecond);
                                            }
                                            return task;
                                        }
                                    }
@@ -482,8 +488,10 @@
                                        {
                                            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"))))
                                            {
                                                task.Remark = "1025";
                                                _taskRepository.UpdateData(task);
                                                return GetDispatchExecutingTask(task, taskSecond);
                                            }
                                            return task;
@@ -511,16 +519,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;
                }
@@ -543,8 +563,10 @@
                                            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"))))
                                            {
                                                task.Remark = "1026";
                                                _taskRepository.UpdateData(task);
                                                return GetDispatchExecutingTask(task, taskSecond);
                                            }
                                            return task;
@@ -560,8 +582,10 @@
                                            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"))))
                                            {
                                                task.Remark = "1026";
                                                _taskRepository.UpdateData(task);
                                                return GetDispatchExecutingTask(task, taskSecond);
                                            }
                                            return task;
@@ -577,8 +601,10 @@
                                            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"))))
                                            {
                                                task.Remark = "1026";
                                                _taskRepository.UpdateData(task);
                                                return GetDispatchExecutingTask(task, taskSecond);
                                            }
                                            return task;
@@ -606,16 +632,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;
                }
@@ -645,13 +683,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;
                            }
                        }
@@ -677,40 +715,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
@@ -754,43 +794,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");
                        //}
                    }
                }
            }
@@ -818,7 +859,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)
                            {
@@ -861,7 +901,7 @@
                                        TaskType = (byte)Convert.ToSByte(1)
                                    };
                                    SendCommand(commonRGVSecond, command);
                                    Thread.Sleep(1000);
                                    Thread.Sleep(3000);
                                    if (!commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running))
                                    {
                                        return null;
@@ -948,7 +988,7 @@
                                        TaskType = (byte)Convert.ToSByte(1)
                                    };
                                    SendCommand(commonRGVFirst, command);
                                    Thread.Sleep(1000);
                                    Thread.Sleep(3000);
                                    if (!commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running))
                                    {
                                        return null;
@@ -1088,7 +1128,7 @@
            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)
@@ -1175,6 +1215,82 @@
            }
        }
        public Dt_Task? GetDispatchTask(List<Dt_Task> tasks,string RGVName)
        {
            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);
@@ -1187,6 +1303,7 @@
                    if (x == null)
                    {
                        next = item.stationChildCode;
                        LogAndWarn("中转获取站台", $" è¿”回任务:【{JsonConvert.SerializeObject(x)}】】【{next}】");
                        break;
                    }
                }
@@ -1194,12 +1311,13 @@
                {
                    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)
                        {
                            _taskRepository.UpdateData(oldtask);
                            LogAndWarn("中转任务GetDispatchExecutingTask", $" è¿”回任务:【{JsonConvert.SerializeObject(oldtask)}】】");
                            LogAndWarn("中转任务GetDispatchExecutingTask", $" è¿”回任务:【{JsonConvert.SerializeObject(oldtask)}】】【{next}】");
                            return oldtask;
                        }
                        else
@@ -1211,7 +1329,6 @@
                    {
                        if (stationManager.stationRemark - task.TargetStation > 1 && stationManager.stationRemark - task.SourceStation > 1 && oldtask.SourceStation - task.SourceStation > 1 && oldtask.SourceStation - task.TargetStation > 1)
                        {
                            _taskRepository.UpdateData(oldtask);
                            LogAndWarn("中转任务GetDispatchExecutingTask", $" è¿”回任务:【{JsonConvert.SerializeObject(oldtask)}】】");
                            return oldtask;
                        }
@@ -1225,6 +1342,33 @@
            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);
                    return oldtask;
                }
            }
            return null;
        }
        /// <summary>
        /// ä»»åŠ¡å®žä½“è½¬æ¢æˆå‘½ä»¤Model
        /// </summary>