| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.Log; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.APIEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.Agv; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_DTO.WMS; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ISystemServices; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly ITaskService _taskService; |
| | | private readonly ISys_ConfigService _sys_ConfigService; |
| | | public CommonAGVJob(ITaskRepository taskRepository,ITaskService taskService,ISys_ConfigService configService) |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | public CommonAGVJob(ITaskRepository taskRepository,ITaskService taskService,ISys_ConfigService configService,IDt_StationManagerRepository stationManagerRepository) |
| | | { |
| | | _taskRepository = taskRepository; |
| | | _taskService = taskService; |
| | | _sys_ConfigService = configService; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskAGVCarryStatusEnum.AGV_CarryNew.ObjToInt())).ToList().OrderBy(x => x.Grade).ThenBy(x => x.TaskNum).ToList(); |
| | | #region ä»»å¡ä¸å |
| | | if (newTasks.Count > 0) |
| | | { |
| | | WriteLog.Write_Log("AGVä»»å¡ä¸å", "ä»»å¡ä¸åæ¥å£", "æ·»å ä»»å¡", $"ä»»å¡ï¼{newTasks.ToJson()}"); |
| | | try |
| | | { |
| | | AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO() |
| | | { |
| | | MissionData = new List<MissionDataItem>() |
| | | }; |
| | | string taskGroupId = Guid.NewGuid().ToString().Replace("-", ""); |
| | | |
| | | foreach (var task in newTasks) |
| | | { |
| | | //è·åç®æ ç¹è´§ä½ |
| | | Dt_StationManager stationManagerStart = _stationManagerRepository.QueryFirst(x => x.stationLocation == task.CurrentAddress); |
| | | //è·åæ£éåºåºç«å° |
| | | Dt_StationManager stationManagerEnd = _stationManagerRepository.QueryFirst(x => x.stationLocation == task.NextAddress); |
| | | |
| | | if (stationManagerStart == null || stationManagerStart == null) throw new Exception($"æªæ¾å°ä»»å¡å·${task.TaskNum}èµ·å§ç¹{task.CurrentAddress}æç®æ ç¹{task.NextAddress}ä½ç½®ä¿¡æ¯"); |
| | | agvTaskSend.RequestId = taskGroupId; |
| | | agvTaskSend.MissionCode = task.TaskNum.ToString(); |
| | | agvTaskSend.ViewBoardType = "W01"; |
| | | //æç®±åæ¬è¿ä»»å¡ |
| | | MissionDataItem missionDataItem = new MissionDataItem() |
| | | { |
| | | Sequence = task.TaskNum, |
| | | BinCode = task.PalletCode, |
| | | StartPosition = stationManagerStart.stationLocation, |
| | | EndPosition = stationManagerEnd.stationLocation, |
| | | TakeActionConfirm = false, |
| | | TakeActionInform = false, |
| | | PutActionConfirm = true, |
| | | PutActionInform = true, |
| | | }; |
| | | agvTaskSend.MissionData.Add(missionDataItem); |
| | | } |
| | | if (newTasks.OrderByDescending(x => x.Grade).FirstOrDefault()?.Grade == 0) |
| | | { |
| | | agvTaskSend.Priority = 99; |
| | | } |
| | | else |
| | | { |
| | | agvTaskSend.Priority = 99 - newTasks.OrderByDescending(x => x.Grade).FirstOrDefault().Grade; |
| | | } |
| | | //åéAGVä»»å¡ |
| | | WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask); |
| | | if (!content.Status) |
| | | throw new Exception(content.Message); |
| | | newTasks.ForEach(x => |
| | | { |
| | | x.Dispatchertime = DateTime.Now; |
| | | x.TaskState = TaskAGVCarryStatusEnum.AGV_CarryExecuting.ObjToInt(); |
| | | }); |
| | | _taskService.UpdateData(newTasks); |
| | | Thread.Sleep(500); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | newTasks.ForEach(x => |
| | | { |
| | | x.TaskState = TaskAGVCarryStatusEnum.AGV_CarryException.ObjToInt(); |
| | | x.ExceptionMessage = ex.Message; |
| | | }); |
| | | _taskService.UpdateData(newTasks); |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | return Task.CompletedTask; |
| | | } |
| | | |