using Microsoft.IdentityModel.Tokens; using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_DTO.Agv; using WIDESEAWCS_Common.APIEnum; 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 { public partial class AGV_CPJob { public void SendAGVTask() { try { var newTasks = _taskService.Db.Queryable().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()|| x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.DeviceCode=="AGV" && x.TaskType!=999).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); if (newTasks.Count>0) { foreach (var task in newTasks) { try { Guid guid = Guid.NewGuid(); AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO() { SysToken=guid.ToString().Replace("-",""), ReceiveTaskID=task.TaskNum.ToString(), MapCode="01", Variables=new List() }; Dt_StationManger stationMangerStart = _stationMangerRepository.QueryFirst(x=>x.StationCode==task.CurrentAddress); Dt_StationManger stationMangerEnd = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress); //添加任务路径及高度 if (stationMangerStart !=null && stationMangerEnd != null) { PointDetail pointDetail1 = new PointDetail() { Code= "GoodPoint", Value=stationMangerStart.AGVStationCode }; if (!string.IsNullOrEmpty(stationMangerStart.AGVFrontCode)) { PointDetail pointDetail2 = new PointDetail() { Code = "CostPoint", Value = stationMangerStart.AGVFrontCode }; agvTaskSend.Variables.Add(pointDetail2); } PointDetail pointDetail3 = new PointDetail() { Code = "PointB", Value = stationMangerEnd.AGVStationCode }; if (!string.IsNullOrEmpty(stationMangerStart.AGVFrontCode)) { PointDetail pointDetail4 = new PointDetail() { Code = "PointA", Value = stationMangerEnd.AGVFrontCode }; agvTaskSend.Variables.Add(pointDetail4); } PointDetail pointDetail5 = new PointDetail() { Code = "QUQTH", Value = stationMangerStart.AGVStationHeight.ToString() }; PointDetail pointDetail6 = new PointDetail() { Code = "FHMH", Value = stationMangerEnd.AGVStationHeight.ToString() }; agvTaskSend.Variables.Add(pointDetail1); agvTaskSend.Variables.Add(pointDetail3); agvTaskSend.Variables.Add(pointDetail5); agvTaskSend.Variables.Add(pointDetail6); } else { throw new Exception("未找到AGV站点"); } //发送AGV任务 WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask); if (!content.Status) throw new Exception(content.Message); task.Dispatchertime = DateTime.Now; _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); Thread.Sleep(500); } catch (Exception ex) { task.TaskState = TaskStatusEnum.Exception.ObjToInt(); task.ExceptionMessage = ex.Message; } } if (newTasks.Count > 0) { _taskService.UpdateData(newTasks); } } } catch (Exception ex) { WriteError(nameof(AGV_CPJob), ex.Message, ex); } } } }