|  |  |  | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Text; | 
|---|
|  |  |  | 
|---|
|  |  |  | using WIDESEAWCS_Common.TaskEnum; | 
|---|
|  |  |  | using WIDESEAWCS_Core; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Helper; | 
|---|
|  |  |  | using WIDESEAWCS_DTO.Agv; | 
|---|
|  |  |  | using WIDESEAWCS_Model.Models; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEAWCS_Tasks | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.New.ObjToInt() && nameof(AGV_FLJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); | 
|---|
|  |  |  | foreach (var task in newTasks) | 
|---|
|  |  |  | var AllTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (nameof(AGV_CPJob).Contains(x.DeviceCode))).ToList(); | 
|---|
|  |  |  | var stationMangers = _stationMangerRepository.QueryData(); | 
|---|
|  |  |  | #region å
¥åºä»»å¡æ¨é | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | var newTasksIn = AllTasks.Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()) && x.TaskType>=TaskTypeEnum.Inbound.ObjToInt() && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode) && x.TaskType!=999).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); | 
|---|
|  |  |  | if (newTasksIn.Count>0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.OutEmpty.ObjToInt() || task.TaskType == TaskTypeEnum.OutAllocate.ObjToInt()) | 
|---|
|  |  |  | task.CurrentAddress = GetAGVAddress(task.CurrentAddress); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | task.NextAddress = GetAGVAddress(task.NextAddress); | 
|---|
|  |  |  | AgvTaskDTO taskDTO = new AgvTaskDTO() | 
|---|
|  |  |  | foreach (var task in newTasksIn) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TaskCode = task.AgvTaskNum, | 
|---|
|  |  |  | ReqCode = DateTime.Now.ToString("yyyyMMddHHmmss") + task.AgvTaskNum, | 
|---|
|  |  |  | TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "FLC" : "FLR", | 
|---|
|  |  |  | ctnrCode = task.PalletCode, | 
|---|
|  |  |  | PositionCodePath = new List<CodePath>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type="05", | 
|---|
|  |  |  | positionCode=task.CurrentAddress | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type="05", | 
|---|
|  |  |  | positionCode=task.NextAddress | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | task.CurrentAddress = GetAGVAddress(task.CurrentAddress); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | task.NextAddress = GetAGVAddress(task.NextAddress); | 
|---|
|  |  |  | AgvTaskDTO taskDTO = new AgvTaskDTO() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TaskCode = task.AgvTaskNum, | 
|---|
|  |  |  | ReqCode = DateTime.Now.ToString("yyMMdd") + task.AgvTaskNum, | 
|---|
|  |  |  | TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "CPC" : "CPR", | 
|---|
|  |  |  | ctnrCode = task.PalletCode, | 
|---|
|  |  |  | PositionCodePath = new List<CodePath>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.CurrentAddress | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.NextAddress | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (taskDTO.TaskTyp== "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = task.Grade.ToString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.GroupId.IsNotEmptyOrNull()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.GroupId=task.GroupId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.TaskType==TaskTypeEnum.OutMesRworkProduct.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = "127"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //åéAGVä»»å¡ | 
|---|
|  |  |  | WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask); | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | throw new Exception(content.Message); | 
|---|
|  |  |  | if (taskDTO.TaskTyp == "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Takeing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Thread.Sleep(500); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_FLSendTask); | 
|---|
|  |  |  | if (!content.Status) throw new Exception(content.Message); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.Exception.ObjToInt(); | 
|---|
|  |  |  | task.ExceptionMessage = ex.Message; | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.Exception.ObjToInt(); | 
|---|
|  |  |  | task.ExceptionMessage = ex.Message; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (newTasksIn.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService.UpdateData(newTasksIn); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _taskService.UpdateData(newTasks); | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | #region åºåºæ¨éä»»å¡1线 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var newTasksOut1 = AllTasks.Where(x => (x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress=="5236").OrderBy(x => x.Grade).ThenBy(x => x.GroupId).Take(5).ToList(); | 
|---|
|  |  |  | var downTasksOut1 = AllTasks.Where(x => (x.TaskState > TaskStatusEnum.New.ObjToInt()) && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == "5236").ToList(); | 
|---|
|  |  |  | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.AGVStationCode == "5236"); | 
|---|
|  |  |  | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); | 
|---|
|  |  |  | if (device != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | OtherDevice otherDevice = (OtherDevice)device; | 
|---|
|  |  |  | short stationCurrentStatus = device.Communicator.Read<short>("DB29.112"); | 
|---|
|  |  |  | if (newTasksOut1.Count > 0 && downTasksOut1.Count <= 0 && stationCurrentStatus == 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | foreach (var task in newTasksOut1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | task.CurrentAddress = GetAGVAddress(task.CurrentAddress); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | task.NextAddress = GetAGVAddress(task.NextAddress); | 
|---|
|  |  |  | AgvTaskDTO taskDTO = new AgvTaskDTO() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TaskCode = task.AgvTaskNum, | 
|---|
|  |  |  | ReqCode = DateTime.Now.ToString("yyMMdd") + task.AgvTaskNum, | 
|---|
|  |  |  | TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "CPC" : "CPR", | 
|---|
|  |  |  | ctnrCode = task.PalletCode, | 
|---|
|  |  |  | PositionCodePath = new List<CodePath>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.CurrentAddress | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.NextAddress | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (taskDTO.TaskTyp == "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = task.Grade.ToString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.GroupId.IsNotEmptyOrNull()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.GroupId = task.GroupId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.OutMesRworkProduct.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = "127"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //åéAGVä»»å¡ | 
|---|
|  |  |  | WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask); | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | throw new Exception(content.Message); | 
|---|
|  |  |  | if (taskDTO.TaskTyp == "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Takeing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.Exception.ObjToInt(); | 
|---|
|  |  |  | task.ExceptionMessage = ex.Message; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (newTasksOut1.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService.UpdateData(newTasksOut1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | #region åºåºæ¨éä»»å¡2线 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var newTasksOut2 = AllTasks.Where(x => (x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == "5243").OrderBy(x => x.Grade).ThenBy(x => x.GroupId).Take(5).ToList(); | 
|---|
|  |  |  | var downTasksOut2 = AllTasks.Where(x => (x.TaskState > TaskStatusEnum.New.ObjToInt()) && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == "5243").ToList(); | 
|---|
|  |  |  | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.AGVStationCode == "5243"); | 
|---|
|  |  |  | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); | 
|---|
|  |  |  | if (device != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | OtherDevice otherDevice = (OtherDevice)device; | 
|---|
|  |  |  | short stationCurrentStatus = device.Communicator.Read<short>("DB29.126"); | 
|---|
|  |  |  | if (newTasksOut2.Count > 0 && downTasksOut2.Count <= 0 && stationCurrentStatus == 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | foreach (var task in newTasksOut2) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | task.CurrentAddress = GetAGVAddress(task.CurrentAddress); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | task.NextAddress = GetAGVAddress(task.NextAddress); | 
|---|
|  |  |  | AgvTaskDTO taskDTO = new AgvTaskDTO() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TaskCode = task.AgvTaskNum, | 
|---|
|  |  |  | ReqCode = DateTime.Now.ToString("yyMMdd") + task.AgvTaskNum, | 
|---|
|  |  |  | TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "CPC" : "CPR", | 
|---|
|  |  |  | ctnrCode = task.PalletCode, | 
|---|
|  |  |  | PositionCodePath = new List<CodePath>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.CurrentAddress | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.NextAddress | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (taskDTO.TaskTyp == "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = task.Grade.ToString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.GroupId.IsNotEmptyOrNull()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.GroupId = task.GroupId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.OutMesRworkProduct.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = "127"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //åéAGVä»»å¡ | 
|---|
|  |  |  | WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask); | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | throw new Exception(content.Message); | 
|---|
|  |  |  | if (taskDTO.TaskTyp == "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Takeing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.Exception.ObjToInt(); | 
|---|
|  |  |  | task.ExceptionMessage = ex.Message; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (newTasksOut2.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService.UpdateData(newTasksOut2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //else | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    WriteInfo(nameof(AGV_CPJob), $"2线æ ä»»å¡ï¼ç¶æ{stationCurrentStatus}"); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | #region åºåºæ¨éä»»å¡3线 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var newTasksOut3 = AllTasks.Where(x => (x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == "5250").OrderBy(x => x.Grade).ThenBy(x => x.GroupId).Take(5).ToList(); | 
|---|
|  |  |  | var downTasksOut3 = AllTasks.Where(x => (x.TaskState > TaskStatusEnum.New.ObjToInt()) && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == "5250").ToList(); | 
|---|
|  |  |  | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.AGVStationCode == "5250"); | 
|---|
|  |  |  | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); | 
|---|
|  |  |  | if (device != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | OtherDevice otherDevice = (OtherDevice)device; | 
|---|
|  |  |  | short stationCurrentStatus = device.Communicator.Read<short>("DB29.140"); | 
|---|
|  |  |  | if (newTasksOut3.Count > 0 && downTasksOut3.Count <= 0 && stationCurrentStatus == 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | foreach (var task in newTasksOut3) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | task.CurrentAddress = GetAGVAddress(task.CurrentAddress); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | task.NextAddress = GetAGVAddress(task.NextAddress); | 
|---|
|  |  |  | AgvTaskDTO taskDTO = new AgvTaskDTO() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TaskCode = task.AgvTaskNum, | 
|---|
|  |  |  | ReqCode = DateTime.Now.ToString("yyMMdd") + task.AgvTaskNum, | 
|---|
|  |  |  | TaskTyp = task.TaskType < TaskTypeEnum.Inbound.ObjToInt() ? "CPC" : "CPR", | 
|---|
|  |  |  | ctnrCode = task.PalletCode, | 
|---|
|  |  |  | PositionCodePath = new List<CodePath>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.CurrentAddress | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type = "05", | 
|---|
|  |  |  | positionCode = task.NextAddress | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (taskDTO.TaskTyp == "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = task.Grade.ToString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.GroupId.IsNotEmptyOrNull()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.GroupId = task.GroupId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.TaskType == TaskTypeEnum.OutMesRworkProduct.ObjToInt()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | taskDTO.Priority = "127"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //åéAGVä»»å¡ | 
|---|
|  |  |  | WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask); | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | throw new Exception(content.Message); | 
|---|
|  |  |  | if (taskDTO.TaskTyp == "CPC") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Takeing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.Exception.ObjToInt(); | 
|---|
|  |  |  | task.ExceptionMessage = ex.Message; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (newTasksOut3.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService.UpdateData(newTasksOut3); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //else | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    WriteInfo(nameof(AGV_CPJob), $"3线æ ä»»å¡ï¼ç¶æ{stationCurrentStatus}"); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | #region ç©ºæ¡æ¬è¿ | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var newTasksLocations = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.New.ObjToInt() && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode) && x.Remark == "æµè¯ç©ºæ¡").ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); | 
|---|
|  |  |  | if (newTasksLocations.Count>0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | foreach (var task in newTasksLocations) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string CurrentAddress = GetAGVAddress(task.CurrentAddress); | 
|---|
|  |  |  | string NextAddress = GetAGVAddress(task.NextAddress); | 
|---|
|  |  |  | AgvTaskDTO taskDTO = new AgvTaskDTO() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TaskCode = task.AgvTaskNum, | 
|---|
|  |  |  | ReqCode = DateTime.Now.ToString("yyMMdd") + task.AgvTaskNum, | 
|---|
|  |  |  | TaskTyp = "CP", | 
|---|
|  |  |  | ctnrCode = task.PalletCode, | 
|---|
|  |  |  | PositionCodePath = new List<CodePath>() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type="05", | 
|---|
|  |  |  | positionCode=CurrentAddress | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | new CodePath() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | type="05", | 
|---|
|  |  |  | positionCode=NextAddress | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | //åéAGVä»»å¡ | 
|---|
|  |  |  | WebResponseContent content = _taskService.AgvSendTask(taskDTO, APIEnum.Agv_CPSendTask); | 
|---|
|  |  |  | if (!content.Status) | 
|---|
|  |  |  | throw new Exception(content.Message); | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.AGV_Takeing.ObjToInt(); | 
|---|
|  |  |  | task.CurrentAddress = CurrentAddress; | 
|---|
|  |  |  | task.NextAddress = NextAddress; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.Exception.ObjToInt(); | 
|---|
|  |  |  | task.ExceptionMessage = ex.Message; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(nameof(AGV_FLJob), ex.Message, ex); | 
|---|
|  |  |  | WriteError(nameof(AGV_CPJob), ex.Message, ex); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// AGVåæ¾è´§åè° | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | public void ContinueAGVTask() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //è·åæ¯å¦æå®å
¨ç³è¯·ä¸çä»»å¡ | 
|---|
|  |  |  | var continueTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt()) && nameof(AGV_CPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); | 
|---|
|  |  |  | foreach (var continueTask in continueTasks) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //åè´§åè° | 
|---|
|  |  |  | if (continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == continueTask.CurrentAddress || x.StationCode == continueTask.CurrentAddress); | 
|---|
|  |  |  | if (stationManger == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); | 
|---|
|  |  |  | if (device == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OtherDevice otherDevice = (OtherDevice)device; | 
|---|
|  |  |  | short canTake = otherDevice.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanTake, stationManger.StationCode); | 
|---|
|  |  |  | if (canTake != 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else//æ¾è´§åè° | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == continueTask.NextAddress); | 
|---|
|  |  |  | if (stationManger == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); | 
|---|
|  |  |  | if (device == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OtherDevice otherDevice = (OtherDevice)device; | 
|---|
|  |  |  | short canPut = otherDevice.GetValue<GroundStationDBName, short>(GroundStationDBName.R_IsCanPut, stationManger.StationCode); | 
|---|
|  |  |  | if (canPut != 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è·åè°å
¥åæ° | 
|---|
|  |  |  | AGVBoxApplyPassDTO boxApplyPassDTO = new AGVBoxApplyPassDTO() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ReqCode = Guid.NewGuid().ToString().Replace("-", ""), | 
|---|
|  |  |  | ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), | 
|---|
|  |  |  | TaskCode = continueTask.AgvTaskNum | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | boxApplyPassDTO.Type = "1"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | boxApplyPassDTO.Type = "2"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è¯·æ±æç®±åè°æ¥å£ | 
|---|
|  |  |  | WebResponseContent content = _taskService.AgvBoxApplyPass(boxApplyPassDTO); | 
|---|
|  |  |  | if (content.Status && continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && boxApplyPassDTO.TaskCode == continueTask.AgvTaskNum) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService.UpdateTask(continueTask, TaskStatusEnum.AGV_Executing); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (content.Status && continueTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && boxApplyPassDTO.TaskCode== continueTask.AgvTaskNum) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService.UpdateTask(continueTask, TaskStatusEnum.AGV_Puting); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | continueTask.ExceptionMessage = content.Message; | 
|---|
|  |  |  | _taskService.UpdateTask(continueTask, TaskStatusEnum.Exception); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(nameof(AGV_CPJob), ex.Message, ex); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | var Layer = Convert.ToInt16(targetCodes[3]); | 
|---|
|  |  |  | var a = Row switch | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 1 => "A1", | 
|---|
|  |  |  | 2 => "B1", | 
|---|
|  |  |  | 3 => "C1", | 
|---|
|  |  |  | 4 => "D1", | 
|---|
|  |  |  | 5 => "E1", | 
|---|
|  |  |  | 1 => "A", | 
|---|
|  |  |  | 2 => "B", | 
|---|
|  |  |  | 3 => "C", | 
|---|
|  |  |  | 4 => "D", | 
|---|
|  |  |  | 5 => "E", | 
|---|
|  |  |  | _ => throw new Exception($"æªå®ä¹çæ,å°å:ã{Address}ã"), | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | var b = Layer > 9 ? "" + Layer : "0" + Layer; | 
|---|