| | |
| | | using Newtonsoft.Json.Linq; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; |
| | | using Quartz; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | 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 == (int)TaskAGVCarryStatusEnum.AGV_CarryNew)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.TaskNum).ToList(); |
| | | return Task.CompletedTask; |
| | | #region ä»»å¡ä¸å |
| | | if (newTasks.Count > 0) |
| | | { |
| | | WriteLog.Write_Log("AGVä»»å¡ä¸å", "ä»»å¡ä¸åæ¥å£", "æ·»å ä»»å¡", $"ä»»å¡ï¼{newTasks.ToJson()}"); |
| | | foreach (var task in newTasks) |
| | | { |
| | | try |
| | | { |
| | | AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO() |
| | | { |
| | | MissionData = new List<MissionDataItem>() |
| | | }; |
| | | string taskGroupId = Guid.NewGuid().ToString().Replace("-", ""); |
| | | |
| | | // è·åèµ·å§ç«å° |
| | | Dt_StationManager stationManagerEnd = _stationManagerRepository.QueryFirst(x => x.StationLocation == task.SourceAddress); |
| | | // è·åç®çç«å° |
| | | Dt_StationManager finalmission = _stationManagerRepository.QueryFirst(x => x.StationLocation == task.TargetAddress); |
| | | |
| | | if (stationManagerEnd == null) throw new Exception($"æªæ¾å°ä»»å¡å·${task.TaskId}èµ·å§ç¹{task.SourceAddress}ä½ç½®ä¿¡æ¯"); |
| | | if (finalmission == null) throw new Exception($"æªæ¾å°ä»»å¡å·${task.TaskId}ç®æ ç¹{task.TargetAddress}ä½ç½®ä¿¡æ¯"); |
| | | |
| | | agvTaskSend.RequestId = taskGroupId; |
| | | agvTaskSend.MissionCode = task.TaskId.ToString(); |
| | | agvTaskSend.ViewBoardType = "W01"; |
| | | agvTaskSend.ContainerCode = task.PalletCode; |
| | | //è´§æ¶åæ¬è¿ä»»å¡ |
| | | MissionDataItem Startingmission = new MissionDataItem() // èµ·ç¹ |
| | | { |
| | | Sequence = 1, |
| | | Position = stationManagerEnd.StationLocation, |
| | | }; |
| | | |
| | | MissionDataItem Finalmission = new MissionDataItem() // ç»ç¹ |
| | | { |
| | | Sequence = 2, |
| | | Position = finalmission.StationLocation, |
| | | PutDown = true, |
| | | }; |
| | | agvTaskSend.MissionData.Add(Startingmission); |
| | | agvTaskSend.MissionData.Add(Finalmission); |
| | | if (task.Grade == 0) |
| | | { |
| | | agvTaskSend.Priority = 99; |
| | | } |
| | | else |
| | | { |
| | | agvTaskSend.Priority = 99 - task.Grade; |
| | | } |
| | | //åéAGVä»»å¡ |
| | | WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask); |
| | | if (!content.Status) |
| | | throw new Exception(content.Message); |
| | | task.Dispatchertime = DateTime.Now; |
| | | task.TaskState = (int)TaskAGVCarryStatusEnum.AGV_CarryExecuting; |
| | | _taskService.UpdateData(task); |
| | | Thread.Sleep(500); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | task.TaskState = (int)TaskAGVCarryStatusEnum.AGV_CarryException; |
| | | task.ExceptionMessage = ex.Message; |
| | | _taskService.UpdateData(newTasks); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | return Task.CompletedTask; |
| | | } |
| | | |