1
huangxiaoqiang
3 天以前 2190be42c0d77be84fed82d387f2a34da7fe4acc
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob_FirstFloor/CommonRGV_FirstFloorJob.cs
@@ -32,6 +32,7 @@
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoRepository;
@@ -116,17 +117,44 @@
                                    bool sendFlag = SendCommand(FirstRgv, rgvTaskCommand);
                                    if (sendFlag)
                                    {
                                        IsExecutingTask.RGVName = FirstRgv.DeviceCode;
                                        _taskRepository.UpdateData(IsExecutingTask);
                                        _taskService.UpdateTaskStatusToNext(IsExecutingTask.TaskNum);
                                        Thread.Sleep(1000);
                                        if (IsExecutingTask.Remark != null)
                                        {
                                            IsExecutingTask.RGVName = "RGV02";
                                            IsExecutingTask.CurrentAddress = IsExecutingTask.Remark;
                                            IsExecutingTask.Remark = "";
                                            Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == IsExecutingTask.NextAddress);
                                            IsExecutingTask.SourceStation = IsExecutingTask.CurrentAddress=="1025"?10:7;
                                            if (IsExecutingTask.TaskType == (int)TaskInboundTypeEnum.Inbound)
                                            {
                                                IsExecutingTask.TargetStation = station.stationRemark;
                                            }
                                            else
                                            {
                                                IsExecutingTask.TargetStation = station.remark;
                                            }
                                                IsExecutingTask.TaskState = (int)TaskInStatusEnum.RGV_TransFer;
                                            _taskRepository.UpdateData(IsExecutingTask);
                                            Thread.Sleep(1000);
                                        }
                                        else
                                        {
                                            IsExecutingTask.RGVName = FirstRgv.DeviceCode;
                                            _taskRepository.UpdateData(IsExecutingTask);
                                            _taskService.UpdateTaskStatusToNext(IsExecutingTask.TaskNum);
                                            Thread.Sleep(1000);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            var taskNew = DispatchTask(FirstRgv);
                            Dt_Task taskNew = null;
                            taskNew = GetTransFerTask(FirstRgv);
                            if (taskNew == null)
                            {
                                taskNew = DispatchTask(FirstRgv);
                            }
                            if (taskNew != null)
                            {
                                RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(taskNew);
@@ -136,10 +164,44 @@
                                    bool sendFlag = SendCommand(FirstRgv, rgvTaskCommand);
                                    if (sendFlag)
                                    {
                                        taskNew.RGVName = FirstRgv.DeviceCode;
                                        _taskRepository.UpdateData(taskNew);
                                        _taskService.UpdateTaskStatusToNext(taskNew.TaskNum);
                                        Thread.Sleep(1000);
                                        if (taskNew.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)
                                        {
                                            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.RGVName = FirstRgv.DeviceCode;
                                            _taskRepository.UpdateData(taskNew);
                                            _taskService.UpdateTaskStatusToNext(taskNew.TaskNum);
                                            Thread.Sleep(1000);
                                        }
                                    }
                                }
                            }
@@ -216,17 +278,35 @@
                                    bool sendFlag = SendCommand(SecondRgv, rgvTaskCommand);
                                    if (sendFlag)
                                    {
                                        IsExecutingTask.RGVName = SecondRgv.DeviceCode;
                                        _taskRepository.UpdateData(IsExecutingTask);
                                        _taskService.UpdateTaskStatusToNext(IsExecutingTask.TaskNum);
                                        Thread.Sleep(1000);
                                        if (IsExecutingTask.Remark != null)
                                        {
                                            IsExecutingTask.RGVName = "RGV01";
                                            IsExecutingTask.CurrentAddress = IsExecutingTask.Remark;
                                            IsExecutingTask.Remark = "";
                                            IsExecutingTask.TaskState = (int)TaskInStatusEnum.RGV_TransFer;
                                            _taskRepository.UpdateData(IsExecutingTask);
                                            Thread.Sleep(1000);
                                        }
                                        else
                                        {
                                            IsExecutingTask.RGVName = SecondRgv.DeviceCode;
                                            _taskRepository.UpdateData(IsExecutingTask);
                                            _taskService.UpdateTaskStatusToNext(IsExecutingTask.TaskNum);
                                            Thread.Sleep(1000);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            var taskNew = DispatchTask(SecondRgv);
                            Dt_Task taskNew = null;
                            taskNew = GetTransFerTask(SecondRgv);
                            if (taskNew == null)
                            {
                                taskNew = DispatchTask(SecondRgv);
                            }
                            if (taskNew != null)
                            {
                                RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(taskNew);
@@ -236,10 +316,34 @@
                                    bool sendFlag = SendCommand(SecondRgv, rgvTaskCommand);
                                    if (sendFlag)
                                    {
                                        taskNew.RGVName = SecondRgv.DeviceCode;
                                        _taskRepository.UpdateData(taskNew);
                                        _taskService.UpdateTaskStatusToNext(taskNew.TaskNum);
                                        Thread.Sleep(1000);
                                        if (taskNew.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)
                                        {
                                            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 = "RGV01";
                                            taskNew.CurrentAddress = taskNew.Remark;
                                            taskNew.Remark = "";
                                            taskNew.TaskState = (int)TaskOutStatusEnum.RGV_TransFer;
                                            _taskRepository.UpdateData(taskNew);
                                            Thread.Sleep(1000);
                                        }
                                        else
                                        {
                                            taskNew.RGVName = SecondRgv.DeviceCode;
                                            _taskRepository.UpdateData(taskNew);
                                            _taskService.UpdateTaskStatusToNext(taskNew.TaskNum);
                                            Thread.Sleep(1000);
                                        }
                                    }
                                }
                            }
@@ -321,8 +425,14 @@
                                    {
                                        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)}】】");
                                            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)
                                            {
                                                return GetDispatchExecutingTask(taskSecond);
                                            }
                                            return task;
                                        }
                                    }
@@ -333,8 +443,12 @@
                                    {
                                        if (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)}】】");
                                            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)
                                            {
                                                return GetDispatchExecutingTask(taskSecond);
                                            }
                                            return task;
                                        }
                                    }
@@ -353,7 +467,7 @@
                                    };
                                    SendCommand(commonRGVSecond, command);
                                }
                                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)}】】");
                                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);
                                return task;
                            }
@@ -379,8 +493,13 @@
                                    {
                                        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)}】】");
                                            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)
                                            {
                                                return GetDispatchExecutingTask(taskSecond);
                                            }
                                            return task;
                                        }
                                    }
@@ -389,10 +508,15 @@
                                {
                                    if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                                    {
                                        if (taskSecond.TargetStation-task.TargetStation >1 )
                                        if (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)}】】");
                                            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)
                                            {
                                                return GetDispatchExecutingTask(taskSecond);
                                            }
                                            return task;
                                        }
                                    }
@@ -411,7 +535,7 @@
                                    };
                                    SendCommand(commonRGVFirst, command);
                                }
                                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)}】】");
                                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);
                                return task;
                            }
@@ -447,32 +571,44 @@
                            var taskSecond = _taskRepository.QueryFirst(x => x.RGVName == "RGV02" && x.TaskNum == commonRGVSecond.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum));
                            if (taskSecond != null)
                            {
                                if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_Indispatch || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InAwaitWMS || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                                {
                                #region
                                //if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                                //{
                                    task = tasks.FirstOrDefault(x =>(x.SourceStation- taskSecond.TargetStation > 1 && x.SourceStation - taskSecond.SourceStation > 1&&x.TaskType==(int)TaskInboundTypeEnum.Inbound) ||(x.SourceStation - taskSecond.TargetStation > 1 && x.TargetStation - taskSecond.SourceStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TargetStation - taskSecond.TargetStation > 1&&x.TaskType== (int)TaskOutboundTypeEnum.Outbound));
                                    if (task == null)
                                    {
                                        task = tasks.FirstOrDefault(x => (x.SourceStation - taskSecond.TargetStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - taskSecond.TargetStation > 1 && x.TargetStation - taskSecond.SourceStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TargetStation - taskSecond.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
                                    }
                                    LogAndWarn("执行调度任务控制", $"【{commonRGVSecond.DeviceCode}工作模式:【{commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}】设备状态:【{commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)}】【{commonRGVSecond.DeviceCode}】任务【{JsonConvert.SerializeObject(taskSecond)}】{commonRGVSecond.DeviceCode}返回任务:【{JsonConvert.SerializeObject(task.TaskNum)}】】");
                                //    //task = tasks.FirstOrDefault(x =>(x.SourceStation- taskSecond.TargetStation > 1 && x.SourceStation - taskSecond.SourceStation > 1&&x.TaskType==(int)TaskInboundTypeEnum.Inbound) ||(x.SourceStation - taskSecond.TargetStation > 1 && x.TargetStation - taskSecond.SourceStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TargetStation - taskSecond.TargetStation > 1&&x.TaskType== (int)TaskOutboundTypeEnum.Outbound));
                                //    //if (task == null)
                                //    //{
                                //    //    task = tasks.FirstOrDefault(x => (x.SourceStation - taskSecond.TargetStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - taskSecond.TargetStation > 1 && x.TargetStation - taskSecond.SourceStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TargetStation - taskSecond.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound));
                                //    //}
                                    Thread.Sleep(1000);
                                    return task;
                                }
                                else if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                                {
                                    task = tasks.FirstOrDefault(x => x.SourceStation - taskSecond.TargetStation> 1 &&x.TargetStation - taskSecond.TargetStation > 1);
                                //    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);
                                    return task;
                                }
                                return null;
                                //    LogAndWarn("执行调度任务控制", $"【{commonRGVSecond.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);
                                //    return task;
                                //}
                                //else if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                                //{
                                //    task = tasks.FirstOrDefault(x => x.SourceStation - taskSecond.TargetStation> 1 &&x.TargetStation - taskSecond.TargetStation > 1);
                                //    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);
                                //    return task;
                                //}
                                //return null;
                                #endregion
                                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);
                                return task;
                            }
                            else
                            {
                                var taskNews = tasks.Where(x => (x.TaskType == (int)TaskInboundTypeEnum.Inbound && Convert.ToInt32(x.SourceAddress) < 1015) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound && (x.Roadway == "SC01" || x.Roadway == "SC02" || x.Roadway == "SC03"))).ToList();
                                var taskNews = tasks.Where(x => (x.TaskType == (int)TaskInboundTypeEnum.Inbound && Convert.ToInt32(x.SourceAddress) < 1015) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound && (x.Roadway == "SC01" || x.Roadway == "SC02" || x.Roadway == "SC03"))||x.RGVName=="RGV01").ToList();
                                if (taskNews.Count== 0)
                                {
                                    return null;
@@ -544,29 +680,40 @@
                            var taskFirst = _taskRepository.QueryFirst(x => x.RGVName == "RGV01" && x.TaskNum == commonRGVFirst.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum));
                            if (taskFirst != null)
                            {
                                if (taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_Indispatch || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_InAwaitWMS || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                                {
                                #region
                                //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));
                                //    //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));
                                    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);
                                //    task = GetDispatchTask(tasks, taskFirst);
                                    return task;
                                }
                                else if (taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                                {
                                    task = tasks.FirstOrDefault(x => taskFirst.TargetStation - x.SourceStation > 1 && taskFirst.TargetStation - x.TargetStation > 1);
                                //    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);
                                    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;
                                }
                                return null;
                                //    return task;
                                //}
                                //else if (taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                                //{
                                //    task = tasks.FirstOrDefault(x => taskFirst.TargetStation - x.SourceStation > 1 && taskFirst.TargetStation - x.TargetStation > 1);
                                //    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;
                                //}
                                //return null;
                                #endregion
                                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)}】】");
                                Thread.Sleep(1000);
                                return task;
                            }
                            else
                            {
                                var taskNews = tasks.Where(x => (x.TaskType == (int)TaskInboundTypeEnum.Inbound && Convert.ToInt32(x.SourceAddress) > 1015) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound && (x.Roadway == "SC04" || x.Roadway == "SC05" || x.Roadway == "SC06"))).ToList();
                                var taskNews = tasks.Where(x => (x.TaskType == (int)TaskInboundTypeEnum.Inbound && Convert.ToInt32(x.SourceAddress) > 1015) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound && (x.Roadway == "SC04" || x.Roadway == "SC05" || x.Roadway == "SC06"))||x.RGVName=="RGV02").ToList();
                                if (taskNews.Count == 0)
                                {
                                    return null;
@@ -640,6 +787,171 @@
            }
        }
        public Dt_Task GetTransFerTask(CommonRGV_FirstFloor commonRGV)
        {
            try
            {
                var tasks = _taskRepository.QueryData(x=>x.TaskState==(int)TaskInStatusEnum.RGV_TransFerFInish|| x.TaskState == (int)TaskOutStatusEnum.RGV_TransFerFInish);
                Dt_Task task;
                if (tasks.Count() == 0)
                {
                    return null;
                }
                if (commonRGV.DeviceCode == "RGV01")
                {
                    CommonRGV_FirstFloor? commonRGVSecond = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "RGV02") as CommonRGV_FirstFloor;
                    if (commonRGVSecond != null)
                    {
                        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));
                            if (taskSecond != null)
                            {
                                if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                                {
                                    task = tasks.FirstOrDefault(x => ((x.SourceStation - taskSecond.TargetStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TaskType == (int)TaskInboundTypeEnum.Inbound) || (x.SourceStation - taskSecond.TargetStation > 1 && x.TargetStation - taskSecond.SourceStation > 1 && x.SourceStation - taskSecond.SourceStation > 1 && x.TargetStation - taskSecond.TargetStation > 1 && x.TaskType == (int)TaskOutboundTypeEnum.Outbound))&&x.RGVName=="RGV01");
                                    LogAndWarn("执行调度任务控制", $"【{commonRGVSecond.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);
                                    return task;
                                }
                                else if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                                {
                                    task = tasks.FirstOrDefault(x => x.SourceStation - taskSecond.TargetStation > 1 && x.TargetStation - taskSecond.TargetStation > 1 && x.RGVName == "RGV01");
                                    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);
                                    return task;
                                }
                                return null;
                            }
                            else
                            {
                                if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 35000)
                                {
                                    RGVTaskCommand command = new RGVTaskCommand()
                                    {
                                        PickupLocation = (byte)Convert.ToSByte(15),
                                        TaskNum = Convert.ToInt16(1000),
                                        TaskType = (byte)Convert.ToSByte(1)
                                    };
                                    SendCommand(commonRGVSecond, command);
                                }
                                if (tasks.FirstOrDefault(x => x.RGVName == "RGV01") != 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(tasks.FirstOrDefault(x => x.RGVName == "RGV01").TaskNum)}】】");
                                    Thread.Sleep(1000);
                                    return tasks.FirstOrDefault(x => x.RGVName == "RGV01");
                                }
                            }
                        }
                        else
                        {
                            if (tasks.FirstOrDefault(x => x.RGVName == "RGV01") != 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(tasks.FirstOrDefault(x => x.RGVName == "RGV01").TaskNum)}】】");
                                Thread.Sleep(1000);
                                return tasks.FirstOrDefault(x => x.RGVName == "RGV01");
                            }
                        }
                    }
                    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");
                        }
                    }
                    return null;
                }
                else
                {
                    CommonRGV_FirstFloor? commonRGVFirst = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "RGV01") as CommonRGV_FirstFloor;
                    if (commonRGVFirst != null)
                    {
                        if (commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault))
                        {
                            var taskFirst = _taskRepository.QueryFirst(x => x.RGVName == "RGV01" && x.TaskNum == commonRGVFirst.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum));
                            if (taskFirst != null)
                            {
                                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 = 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)}】】");
                                    Thread.Sleep(1000);
                                    return task;
                                }
                                else if (taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                                {
                                    task = tasks.FirstOrDefault(x => taskFirst.TargetStation - x.SourceStation > 1 && taskFirst.TargetStation - x.TargetStation > 1 && 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)}】】");
                                    Thread.Sleep(1000);
                                    return task;
                                }
                                return null;
                            }
                            else
                            {
                                if (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) < 420000)
                                {
                                    RGVTaskCommand command = new RGVTaskCommand()
                                    {
                                        PickupLocation = (byte)Convert.ToSByte(26),
                                        TaskNum = Convert.ToInt16(1000),
                                        TaskType = (byte)Convert.ToSByte(1)
                                    };
                                    SendCommand(commonRGVFirst, command);
                                }
                                if (tasks.FirstOrDefault(x => x.RGVName == "RGV02") != 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(tasks.FirstOrDefault(x => x.RGVName == "RGV02").TaskNum)}】】");
                                    Thread.Sleep(1000);
                                    return tasks.FirstOrDefault(x => x.RGVName == "RGV02");
                                }
                            }
                        }
                        else
                        {
                            if (tasks.FirstOrDefault(x => x.RGVName == "RGV02") != 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(tasks.FirstOrDefault(x => x.RGVName == "RGV02").TaskNum)}】】");
                                Thread.Sleep(1000);
                                return tasks.FirstOrDefault(x => x.RGVName == "RGV02");
                            }
                        }
                    }
                    else
                    {
                        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");
                        }
                    }
                    return null;
                }
            }
            catch (Exception ex)
            {
                WriteInfo("调度任务异常日志", ex.Message + Environment.NewLine + ex.StackTrace);
                return null;
            }
        }
        /// <summary>
        /// RGV任务完成
        /// </summary>
@@ -669,7 +981,7 @@
                                string Barcode = Encoding.UTF8.GetString(x);
                                if (Barcode == null || Barcode == ""|| Barcode.Trim().Contains("\0"))
                                if (Barcode == null || Barcode == "" || Barcode.Trim().Contains("\0"))
                                {
                                    commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, Convert.ToSByte(stationManager.stationRemark));
                                    commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(task.TaskNum));
@@ -680,6 +992,7 @@
                                    Dt_Task_Hty task_Hty = _mapper.Map<Dt_Task_Hty>(task);
                                    task_Hty.TaskId = 0;
                                    task_Hty.OperateType = (int)OperateTypeEnum.异常退回;
                                    _taskRepository.DeleteData(task);
                                    _task_HtyRepository.AddData(task_Hty);
@@ -701,7 +1014,6 @@
                                {
                                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                                    Thread.Sleep(100);
                                    var Barcode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.ConveyorLineBarcode, stationManager.stationChildCode);
                                    conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, Convert.ToInt16(stationManager.stationNextChildCode), stationManager.stationChildCode);
                                    Thread.Sleep(100);
                                    conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTaskNum, Convert.ToInt16(1000), stationManager.stationChildCode);
@@ -730,6 +1042,94 @@
            return null;
        }
        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))).First();
            if (y == null)
            {
                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));
                }
                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);
                }
                return null;
            }
            else
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1001");
                if (device != null)
                {
                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                    var stationManager = _stationManagerRepository.QueryData(x => x.stationType == 15);
                    if (stationManager.Count() > 0)
                    {
                        string next = null;
                        foreach (var item in stationManager)
                        {
                            short x = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, item.stationChildCode);
                            var structs = BitConverter.GetBytes(x).ToArray().ToBoolArray();
                            if (structs[2])
                            {
                                next = item.stationChildCode;
                                break;
                            }
                        }
                        if (next != null)
                        {
                            oldtask.Remark = next;
                            _taskRepository.UpdateData(y);
                            return y;
                        }
                    }
                }
                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));
                }
                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);
                }
                return null;
            }
        }
        public Dt_Task? GetDispatchExecutingTask(Dt_Task oldtask)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1001");
            if (device != null)
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                var stationManager = _stationManagerRepository.QueryData(x => x.stationType == 15);
                if (stationManager.Count() > 0)
                {
                    string next = null;
                    foreach (var item in stationManager)
                    {
                        short x = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, item.stationChildCode);
                        var structs = BitConverter.GetBytes(x).ToArray().ToBoolArray();
                        if (structs[2])
                        {
                            next = item.stationChildCode;
                            break;
                        }
                    }
                    if (next != null)
                    {
                        oldtask.Remark = next;
                        _taskRepository.UpdateData(oldtask);
                        return oldtask;
                    }
                }
            }
            return null;
        }
        /// <summary>
        /// ä»»åŠ¡å®žä½“è½¬æ¢æˆå‘½ä»¤Model
        /// </summary>
@@ -749,11 +1149,28 @@
                    rgvTaskCommand.TaskType = (byte)Convert.ToSByte(3);
                    rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
                }
                else if (task.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish)
                {
                    Dt_StationManager stationManagerStart = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                    Dt_StationManager stationManagerEnd = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress);
                    rgvTaskCommand.TaskType = (byte)Convert.ToSByte(5);
                    rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManagerStart.stationRemark);
                    rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManagerEnd.stationRemark);
                }
                else if (task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
                {
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress);
                    rgvTaskCommand.TaskType = (byte)Convert.ToSByte(4);
                    rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
                    if (task.Remark != null && (task.Roadway == "SC01" || task.Roadway == "SC06"))
                    {
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.Remark);
                        rgvTaskCommand.TaskType = (byte)Convert.ToSByte(4);
                        rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
                    }
                    else
                    {
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress);
                        rgvTaskCommand.TaskType = (byte)Convert.ToSByte(4);
                        rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
                    }
                }
                else
                {
@@ -765,9 +1182,28 @@
                if (task.TaskState == (int)TaskOutStatusEnum.Line_OutFinish)
                {
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                    rgvTaskCommand.TaskType = (byte)Convert.ToSByte(3);
                    rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
                    if (task.Remark != null && (task.Roadway == "SC01" || task.Roadway == "SC06"))
                    {
                        Dt_StationManager stationManagerStart = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                        Dt_StationManager stationManagerEnd = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.Remark);
                        rgvTaskCommand.TaskType = (byte)Convert.ToSByte(5);
                        rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManagerStart.stationRemark);
                        rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManagerEnd.stationRemark);
                    }
                    else
                    {
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                        rgvTaskCommand.TaskType = (byte)Convert.ToSByte(3);
                        rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
                    }
                }
                else if (task.TaskState == (int)TaskOutStatusEnum.RGV_TransFerFInish)
                {
                    Dt_StationManager stationManagerStart = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
                    Dt_StationManager stationManagerEnd = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress);
                    rgvTaskCommand.TaskType = (byte)Convert.ToSByte(5);
                    rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManagerStart.stationRemark);
                    rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManagerEnd.stationRemark);
                }
                else if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish)
                {