From 7f42a3ef9bc83bdc199317d12c1905d8696dac4f Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期三, 20 八月 2025 17:23:05 +0800 Subject: [PATCH] 代码提交 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob_FirstFloor/CommonRGV_FirstFloorJob.cs | 1195 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 900 insertions(+), 295 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 8bf8834..728235d 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" @@ -19,8 +19,10 @@ using HslCommunication; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using Quartz; using SixLabors.ImageSharp.Drawing; +using SqlSugar; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Text; @@ -30,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; @@ -42,10 +45,10 @@ using WIDESEAWCS_QuartzJob.Models; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_SignalR; +using WIDESEAWCS_TaskInfoRepository; using WIDESEAWCS_Tasks.ConveyorLineJob; using WIDESEAWCS_Tasks.RGVJob; using WIDESEAWCS_Tasks.StackerCraneJob; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace WIDESEAWCS_Tasks { @@ -53,18 +56,19 @@ public class CommonRGV_FirstFloorJob : JobBase, IJob { private readonly ITaskService _taskService; + private readonly ITask_HtyRepository _task_HtyRepository; private readonly ITaskRepository _taskRepository; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly IRouterService _routerService; private readonly IDt_StationManagerService _stationManagerService; private readonly IDt_StationManagerRepository _stationManagerRepository; private readonly IMapper _mapper; - private readonly ICacheService _cacheService; + private readonly WIDESEAWCS_Core.Caches.ICacheService _cacheService; private readonly INoticeService _noticeService; private static List<string>? userTokenIds; private static List<int>? userIds; - public CommonRGV_FirstFloorJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IDt_StationManagerService stationManagerService, IMapper mapper, ICacheService cacheService, INoticeService noticeService, ITaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository) + public CommonRGV_FirstFloorJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IDt_StationManagerService stationManagerService, IMapper mapper, WIDESEAWCS_Core.Caches.ICacheService cacheService, INoticeService noticeService, ITaskRepository taskRepository, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository task_HtyRepository) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; @@ -75,11 +79,12 @@ _noticeService = noticeService; _taskRepository = taskRepository; _stationManagerRepository = stationManagerRepository; + _task_HtyRepository = task_HtyRepository; } public Task Execute(IJobExecutionContext context) { - Console.WriteLine(DateTime.Now.ToString() + "锛岀嚎绋婭D锛�" + Thread.CurrentThread.ManagedThreadId); + //Console.WriteLine(DateTime.Now.ToString() + "锛岀嚎绋婭D锛�" + Thread.CurrentThread.ManagedThreadId); try { //鐢ㄨ繖绉嶆柟寮忚兘纭繚绫诲瀷杞崲涓嶄細鏈夐棶棰� @@ -99,27 +104,62 @@ } if (FirstRgv.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !FirstRgv.GetValue<RGVDBName, bool>(RGVDBName.Fault) && !FirstRgv.GetValue<RGVDBName, bool>(RGVDBName.Running)) { - Dt_Task? task = GetTask(FirstRgv, FirstRgv.GetValue<RGVDBName, bool>(RGVDBName.InStock)); - if (task != null) + if (FirstRgv.GetValue<RGVDBName, bool>(RGVDBName.InStock)) { - var IsExecutingTask = DispatchExecutingTask(FirstRgv, task); - if (IsExecutingTask != null) + Dt_Task? task = GetTask(FirstRgv, FirstRgv.GetValue<RGVDBName, bool>(RGVDBName.InStock)); + if (task != null) { - RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(task); - if (rgvTaskCommand != null) + var IsExecutingTask = DispatchExecutingTask(FirstRgv, task); + if (IsExecutingTask != null) { - Thread.Sleep(1000); - bool sendFlag = SendCommand(FirstRgv, rgvTaskCommand); - if (sendFlag) + RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(IsExecutingTask); + if (rgvTaskCommand != null) { - _taskService.UpdateTaskStatusToNext(task.TaskNum); + Thread.Sleep(1000); + bool sendFlag = SendCommand(FirstRgv, rgvTaskCommand); + if (sendFlag) + { + 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; + IsExecutingTask.TaskState = (int)TaskInStatusEnum.RGV_TransFer; + } + else + { + IsExecutingTask.TargetStation = station.remark; + IsExecutingTask.TaskState = (int)TaskOutStatusEnum.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); @@ -129,7 +169,44 @@ bool sendFlag = SendCommand(FirstRgv, rgvTaskCommand); if (sendFlag) { - _taskService.UpdateTaskStatusToNext(taskNew.TaskNum); + 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); + } } } } @@ -164,6 +241,7 @@ Running = RGVWorkStatus(FirstRgv.GetValue<RGVDBName, bool>(RGVDBName.Running)), LevelPoint = FirstRgv.GetValue<RGVDBName, int>(RGVDBName.LevelPoint), CurrentTaskNum = FirstRgv.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum), + RGVAlarm = FirstRgv.GetValue<RGVDBName, uint>(RGVDBName.RGVAlarm), FirstRgv.DeviceCode, FirstRgv.DeviceName, }; @@ -175,10 +253,10 @@ } else { - if (commonRGVFirst == null) - Console.WriteLine($"RGV01鏈壘鍒拌澶囧璞$殑鍊�"); - else - Console.WriteLine($"RGV01璁惧瀵硅薄绫诲瀷閿欒"); + //if (commonRGVFirst == null) + // Console.WriteLine($"RGV01鏈壘鍒拌澶囧璞$殑鍊�"); + //else + // Console.WriteLine($"RGV01璁惧瀵硅薄绫诲瀷閿欒"); } #endregion @@ -192,24 +270,64 @@ } if (SecondRgv.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !SecondRgv.GetValue<RGVDBName, bool>(RGVDBName.Fault) && !SecondRgv.GetValue<RGVDBName, bool>(RGVDBName.Running)) { - Dt_Task? task = GetTask(SecondRgv, SecondRgv.GetValue<RGVDBName, bool>(RGVDBName.InStock)); - if (task != null) + if (SecondRgv.GetValue<RGVDBName, bool>(RGVDBName.InStock)) { - var IsExecutingTask = DispatchExecutingTask(SecondRgv, task); - RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(task); - if (rgvTaskCommand != null) + Dt_Task? task = GetTask(SecondRgv, SecondRgv.GetValue<RGVDBName, bool>(RGVDBName.InStock)); + if (task != null) { - Thread.Sleep(1000); - bool sendFlag = SendCommand(SecondRgv, rgvTaskCommand); - if (sendFlag) + var IsExecutingTask = DispatchExecutingTask(SecondRgv, task); + if (IsExecutingTask != null) { - _taskService.UpdateTaskStatusToNext(task.TaskNum); + RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(IsExecutingTask); + if (rgvTaskCommand != null) + { + Thread.Sleep(1000); + bool sendFlag = SendCommand(SecondRgv, rgvTaskCommand); + if (sendFlag) + { + if (IsExecutingTask.Remark != null) + { + IsExecutingTask.RGVName = "RGV01"; + 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.TaskState = (int)TaskInStatusEnum.RGV_TransFer; + IsExecutingTask.TargetStation = station.stationRemark; + } + else + { + IsExecutingTask.TaskState = (int)TaskOutStatusEnum.RGV_TransFer; + IsExecutingTask.TargetStation = station.remark; + } + + _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); @@ -219,7 +337,34 @@ bool sendFlag = SendCommand(SecondRgv, rgvTaskCommand); if (sendFlag) { - _taskService.UpdateTaskStatusToNext(taskNew.TaskNum); + 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); + } } } } @@ -254,6 +399,7 @@ Running = RGVWorkStatus(SecondRgv.GetValue<RGVDBName, bool>(RGVDBName.Running)), LevelPoint = SecondRgv.GetValue<RGVDBName, int>(RGVDBName.LevelPoint), CurrentTaskNum = SecondRgv.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum), + RGVAlarm = SecondRgv.GetValue<RGVDBName, uint>(RGVDBName.RGVAlarm), SecondRgv.DeviceCode, SecondRgv.DeviceName, }; @@ -265,10 +411,10 @@ } else { - if (commonRGVSecond == null) - Console.WriteLine($"RGV02鏈壘鍒拌澶囧璞$殑鍊�"); - else - Console.WriteLine($"RGV02璁惧瀵硅薄绫诲瀷閿欒"); + //if (commonRGVSecond == null) + // Console.WriteLine($"RGV02鏈壘鍒拌澶囧璞$殑鍊�"); + //else + // Console.WriteLine($"RGV02璁惧瀵硅薄绫诲瀷閿欒"); } #endregion //} @@ -289,33 +435,47 @@ 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) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.InStock)) + if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)) { - if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) - { - RGVTaskCommand command = new RGVTaskCommand() - { - PickupLocation = (byte)Convert.ToSByte(15), - TaskNum = Convert.ToInt16(1000), - TaskType = (byte)Convert.ToSByte(1) - }; - SendCommand(commonRGVSecond, command); - } - LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGVSecond.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.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(task)}銆戙��"); - return task; - } - else 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)); + 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.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) { if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish) { - if (task.TargetStation > taskSecond.SourceStation && task.TargetStation > taskSecond.TargetStation) + 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 || ((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; + } + } + } + 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; } } @@ -324,9 +484,16 @@ { if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish) { - if (task.TargetStation > taskSecond.TargetStation) + 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 || ((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; } } @@ -335,20 +502,45 @@ } else { - if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) + if (commonRGVSecond.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted)) { + RGVTaskFinish(commonRGVSecond, commonRGVSecond.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + } + 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), - TaskNum = Convert.ToInt16(1000), + TaskNum = Convert.ToInt16(1), TaskType = (byte)Convert.ToSByte(1) }; SendCommand(commonRGVSecond, command); + Thread.Sleep(3000); + if (!commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running)) + { + return null; + } } - 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)}銆戙��"); + 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; } @@ -357,34 +549,45 @@ 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) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.InStock)) + if (commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)) { - if (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) - { - RGVTaskCommand command = new RGVTaskCommand() - { - PickupLocation = (byte)Convert.ToSByte(26), - TaskNum = Convert.ToInt16(1000), - TaskType = (byte)Convert.ToSByte(1) - }; - SendCommand(commonRGVFirst, command); - } - LogAndWarn("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGVFirst.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.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(task)}銆戙��"); - return task; - } - else if (commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)) - { - var taskSecond = _taskRepository.QueryFirst(x => x.RGVName == "RGV01" && x.TaskNum == commonRGVFirst.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + var taskSecond = _taskRepository.QueryFirst(x => x.RGVName == "RGV01" && x.TaskNum == commonRGVFirst.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.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) { if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish) { - if (task.TargetStation < taskSecond.SourceStation && task.TargetStation < taskSecond.TargetStation) + 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 || ((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; + } + } + } + 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; } } @@ -393,9 +596,17 @@ { if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish) { - if (task.TargetStation < taskSecond.TargetStation) + 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 || ((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; } } @@ -404,20 +615,45 @@ } else { - if (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) + if (commonRGVFirst.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted)) { + RGVTaskFinish(commonRGVFirst, commonRGVFirst.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + } + 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), - TaskNum = Convert.ToInt16(1000), + TaskNum = Convert.ToInt16(1), TaskType = (byte)Convert.ToSByte(1) }; SendCommand(commonRGVFirst, command); + Thread.Sleep(3000); + if (!commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running)) + { + return null; + } } - 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)}銆戙��"); + 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; } @@ -434,7 +670,7 @@ try { var tasks = _taskService.QueryRGVTask(); - Dt_Task task; + Dt_Task task = new Dt_Task(); if (tasks.Count() == 0) { return null; @@ -444,104 +680,77 @@ 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) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.InStock)) + if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Fault)) { - if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) - { - 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}宸ヤ綔妯″紡锛氥�恵commonRGV.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"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName == "RGV01"); - } - else - { - LogAndWarn("璋冨害浠诲姟鎺у埗", $"銆恵commonRGVSecond.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGV.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 != "RGV02"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName != "RGV02"); - } - } - else 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)); + 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.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) - { - task = tasks.FirstOrDefault(x => x.SourceStation > taskSecond.TargetStation && x.TargetStation > taskSecond.SourceStation && x.SourceStation > taskSecond.SourceStation && x.TargetStation > taskSecond.TargetStation); + 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)}銆戙��"); - 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)}銆戙��"); - - - return task; - } - else if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InExecuting) - { - task = tasks.FirstOrDefault(x => x.SourceStation > taskSecond.TargetStation && x.TargetStation > taskSecond.TargetStation); - - 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)}銆戙��"); - - return task; - } + Thread.Sleep(1000); + return task; + } + } + var taskNews = tasks.Where(x => (x.TaskType == (int)TaskInboundTypeEnum.Inbound && (Convert.ToInt32(x.SourceAddress) < 1015|| Convert.ToInt32(x.SourceAddress)>1031)) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound && (x.Roadway == "SC01" || x.Roadway == "SC02" || x.Roadway == "SC03")) || x.RGVName == "RGV01").ToList(); + if (taskNews.Count == 0) + { + return null; + } + if (commonRGVSecond.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted)) + { + RGVTaskFinish(commonRGVSecond, commonRGVSecond.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + } + if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 35000) + { + if (commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running)) + { return null; } - else + RGVTaskCommand command = new RGVTaskCommand() { - if (commonRGVSecond.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) - { - 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"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName == "RGV01"); - } - 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(tasks.FirstOrDefault(x => x.RGVName != "RGV02"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName != "RGV02"); - } + PickupLocation = (byte)Convert.ToSByte(15), + TaskNum = Convert.ToInt16(1), + TaskType = (byte)Convert.ToSByte(1) + }; + SendCommand(commonRGVSecond, command); + Thread.Sleep(3000); + if (!commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running)) + { + return null; } } - else + task = GetDispatchTask(taskNews, "RGV01"); + if (task == null) { - 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"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName == "RGV01"); - } - 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(tasks.FirstOrDefault(x => x.RGVName != "RGV02"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName != "RGV02"); - } + return tasks.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("璋冨害浠诲姟鎺у埗", $"銆恵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"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName == "RGV01"); - } - 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(tasks.FirstOrDefault(x => x.RGVName != "RGV02"))}銆戙��"); - 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 @@ -549,77 +758,249 @@ 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) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.InStock)) + if (commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)) { - if (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) - { - 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"))}銆戙��"); - return tasks.FirstOrDefault(x => x.RGVName == "RGV02"); - } - 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(tasks.FirstOrDefault(x => x.RGVName != "RGV01"))}銆戙��"); - - return tasks.FirstOrDefault(x => x.RGVName != "RGV01"); - } - } - else 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)); + var taskFirst = _taskRepository.QueryFirst(x => x.RGVName == "RGV01" && x.TaskNum == commonRGVFirst.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 (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) + 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; + } + } + var taskNews = tasks.Where(x => (x.TaskType == (int)TaskInboundTypeEnum.Inbound && Convert.ToInt32(x.SourceAddress) > 1014 && Convert.ToInt32(x.SourceAddress)<1031) || (x.TaskType == (int)TaskOutboundTypeEnum.Outbound && (x.Roadway == "SC04" || x.Roadway == "SC05" || x.Roadway == "SC06")) || x.RGVName == "RGV02").ToList(); + if (taskNews.Count == 0) + { + return null; + } + if (commonRGVFirst.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted)) + { + RGVTaskFinish(commonRGVFirst, commonRGVFirst.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + } + 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), + TaskNum = Convert.ToInt16(1), + TaskType = (byte)Convert.ToSByte(1) + }; + SendCommand(commonRGVFirst, command); + Thread.Sleep(3000); + if (!commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running)) + { + return null; + } + } + task = GetDispatchTask(taskNews, "RGV02"); + if (task == null) + { + return tasks.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 + { + 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 != "RGV01"); + //} + } + } + } + catch (Exception ex) + { + WriteInfo("璋冨害浠诲姟寮傚父鏃ュ織", ex.Message+Environment.NewLine+ex.StackTrace); + return null; + } + } + + public Dt_Task GetTransFerTask(CommonRGV_FirstFloor commonRGV) + { + try + { + var tasks = _taskRepository.QueryData(x => x.Floor == "1F" && (x.TaskState == (int)TaskInStatusEnum.RGV_TransFerFInish || x.TaskState == (int)TaskOutStatusEnum.RGV_TransFerFInish)); + Dt_Task task = new Dt_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) && ((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.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish) { - task = tasks.FirstOrDefault(x => x.SourceStation < taskFirst.TargetStation && x.TargetStation < taskFirst.SourceStation && x.SourceStation < taskFirst.SourceStation && x.TargetStation < taskFirst.TargetStation); + 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("鎵ц璋冨害浠诲姟鎺у埗", $"銆恵commonRGVFirst.DeviceCode}宸ヤ綔妯″紡锛氥�恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Automatic)}銆戣澶囩姸鎬侊細銆恵commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Fault)}銆戙�恵commonRGVFirst.DeviceCode}銆戜换鍔°�恵JsonConvert.SerializeObject(taskFirst)}銆憑commonRGVFirst.DeviceCode}杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(task)}銆戙��"); + 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 (taskFirst.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskFirst.TaskState == (int)TaskInStatusEnum.RGV_InExecuting) + else if (taskSecond.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || taskSecond.TaskState == (int)TaskInStatusEnum.RGV_InExecuting) { - task = tasks.FirstOrDefault(x => x.SourceStation < taskFirst.TargetStation && x.TargetStation < taskFirst.TargetStation); + task = tasks.FirstOrDefault(x => x.SourceStation - taskSecond.TargetStation > 1 && x.TargetStation - taskSecond.TargetStation > 1 && x.RGVName == "RGV01"); - 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)}銆戙��"); - + 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 (commonRGVFirst.GetValue<RGVDBName, int>(RGVDBName.LevelPoint) > 1000) + if (commonRGVSecond.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted)) { + RGVTaskFinish(commonRGVSecond, commonRGVSecond.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + } + 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), - TaskNum = Convert.ToInt16(1000), + TaskNum = Convert.ToInt16(1), + TaskType = (byte)Convert.ToSByte(1) + }; + SendCommand(commonRGVSecond, command); + Thread.Sleep(3000); + if (!commonRGVSecond.GetValue<RGVDBName, bool>(RGVDBName.Running)) + { + return null; + } + } + + 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) && ((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 (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 => ((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)}銆戙��"); + 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<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted)) + { + RGVTaskFinish(commonRGVFirst, commonRGVFirst.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + } + 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), + TaskNum = Convert.ToInt16(1), TaskType = (byte)Convert.ToSByte(1) }; SendCommand(commonRGVFirst, command); + Thread.Sleep(3000); + if (!commonRGVFirst.GetValue<RGVDBName, bool>(RGVDBName.Running)) + { + return null; + } } + 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"))}銆戙��"); + 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 - { - 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 != "RGV01"))}銆戙��"); - - return tasks.FirstOrDefault(x => x.RGVName != "RGV01"); } } } @@ -627,15 +1008,9 @@ { 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"))}銆戙��"); - + 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 - { - 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 != "RGV01"))}銆戙��"); - - return tasks.FirstOrDefault(x => x.RGVName != "RGV01"); } } } @@ -643,22 +1018,18 @@ { 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"))}銆戙��"); + LogAndWarn("涓浆璋冨害浠诲姟鎺у埗", $"銆愭湭鎵惧埌RGV01璁惧淇℃伅銆� 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(tasks.FirstOrDefault(x => x.RGVName == "RGV02").TaskNum)}銆戙��"); + Thread.Sleep(1000); return tasks.FirstOrDefault(x => x.RGVName == "RGV02"); } - 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(tasks.FirstOrDefault(x => x.RGVName != "RGV01"))}銆戙��"); - - return tasks.FirstOrDefault(x => x.RGVName != "RGV01"); - } } + return null; } } catch (Exception ex) { - WriteInfo("璋冨害浠诲姟寮傚父鏃ュ織", ex.Message+Environment.NewLine+ex.StackTrace); + WriteInfo("璋冨害浠诲姟寮傚父鏃ュ織", ex.Message + Environment.NewLine + ex.StackTrace); return null; } } @@ -672,24 +1043,10 @@ { if (commonRGV != null) { + WriteInfo("RGV浠诲姟瀹屾垚", $"{commonRGV.DeviceName}瀹屾垚浠诲姟鍙穥TaskNum}"); var task = _taskRepository.QueryFirst(x => x.TaskNum == TaskNum); if (task != null) { - if (task.TaskState == (int)TaskInStatusEnum.InRetuen) - { - Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress); - if (stationManager != null) - { - IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); - if (device != null) - { - CommonConveyorLine conveyorLine = (CommonConveyorLine)device; - commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(4)); - - var content = _taskService.RGVTaskCompleted(TaskNum); - } - } - } if (task.TaskState == (int)TaskInStatusEnum.RGV_Indispatch) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress); @@ -701,16 +1058,30 @@ CommonConveyorLine conveyorLine = (CommonConveyorLine)device; Thread.Sleep(100); DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault(); - var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 5); + + var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 10); + string Barcode = Encoding.UTF8.GetString(x); - if (Barcode == null || Barcode == "") + short y = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, stationManager.stationChildCode); + var structs = BitConverter.GetBytes(y).ToArray().ToBoolArray(); + + if (Barcode == null || Barcode == "" || Barcode.Trim().Contains("\0")|| structs[5]) { - conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode); + WriteInfo("鍏ュ簱寮傚父淇℃伅", $"鎵樼洏鍙枫�恵Barcode}銆戞灏恒�恵structs[5]}銆戜换鍔″彿銆恵TaskNum}銆�"); commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, Convert.ToSByte(stationManager.stationRemark)); commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(task.TaskNum)); - task.TaskState = (int)TaskInStatusEnum.InRetuen; - _taskRepository.UpdateData(task); + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(4)); + + task.ModifyDate = DateTime.Now; + task.Modifier = "System"; + + 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); return; } var content = _taskService.RGVTaskCompleted(TaskNum, Barcode); @@ -729,10 +1100,9 @@ { 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); + conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTaskNum, Convert.ToInt16(1), stationManager.stationChildCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(2), stationManager.stationChildCode); } @@ -753,47 +1123,250 @@ { if (InStock) { - return _taskService.QueryRGVExecutingTask(commonRGV.DeviceCode, commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum)); + return _taskService.QueryRGVExecutingTask(commonRGV.DeviceCode); } return null; + } - #region - //if (commonRGV.LastTaskType == null) - //{ - // task = _taskService.QueryRGVTask(commonRGV.DeviceCode); - //} - //else - //{ - // if (commonRGV.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) - // { - // task = _taskService.QueryRGVInTask(commonRGV.DeviceCode); - // if (task == null) - // { - // task = _taskService.QueryRGVOutTask(commonRGV.DeviceCode); - // } - // } - // else - // { - // task = _taskService.QueryRGVOutTask(commonRGV.DeviceCode); - // } - //} + 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) + { + WriteInfo("鏌ヨ浠诲姟", $" 杩斿洖浠诲姟锛氥�恵JsonConvert.SerializeObject(oldtask)}銆戙��"); + if (oldtask.TaskState == (int)TaskOutStatusEnum.RGV_Outdispatch || oldtask.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish || oldtask.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish) + { + 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)) + { + 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)); - //if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) - //{ - // if (task == null) - // { - // task = _taskService.QueryRGVInTask(commonRGV.DeviceCode); - // } - // else - // { - // return task; - // } - //} - //else if (task == null) - //{ - // task = _taskService.QueryRGVInTask(commonRGV.DeviceCode); - //} - #endregion + } + + } + else if (oldtask.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting || oldtask.TaskState == (int)TaskInStatusEnum.RGV_InExecuting) + { + 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; + } + 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 (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.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); + } + return null; + } + } + + 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); + 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; + //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); + return oldtask; + } + } + return null; } /// <summary> @@ -809,23 +1382,37 @@ rgvTaskCommand.TaskNum = Convert.ToInt16(task.TaskNum); if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔� { - //rgvTaskCommand.TaskType = (byte)Convert.ToSByte(16); - //rgvTaskCommand.TaskType = (byte)Convert.ToSByte(64); 閫�鍥� if (task.TaskState == (int)TaskInStatusEnum.InNew) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress); 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 { - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鍙栬揣绔欏彴淇℃伅"); return null; } } @@ -834,9 +1421,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) { @@ -846,7 +1452,6 @@ } else { - _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鍙栬揣绔欏彴淇℃伅"); return null; } } -- Gitblit v1.9.3