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_Model.Models; using WIDESEAWCS_Tasks.StackerCraneJob; namespace WIDESEAWCS_Tasks { public partial class AGV_PPJob { public void SendAGVTask() { try { var newTasks = _taskService.Db.Queryable().Where(x => (x.TaskState == TaskStatusEnum.New.ObjToInt()||x.TaskState==TaskStatusEnum.AGV_Execute.ObjToInt()) && nameof(AGV_PPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); foreach (var agvTask in newTasks) { try { string taskTyp; if (agvTask.TaskType == TaskTypeEnum.MesPPMove.ObjToInt()) { taskTyp = "110"; } else if (agvTask.PalletType < 2) { taskTyp = "008"; } else { taskTyp = "004"; } AgvTaskDTO taskDTO = new AgvTaskDTO() { ReqCode = Guid.NewGuid().ToString().Replace("-", ""), TaskTyp = taskTyp, PositionCodePath = new List() { new CodePath() { type = "00", positionCode = agvTask.CurrentAddress }, new CodePath() { type = (agvTask.TaskType == TaskTypeEnum.PPPKInbound.ObjToInt()||agvTask.TaskType == TaskTypeEnum.MesPPCutOutbound.ObjToInt()) ? "00" : "04", positionCode = agvTask.NextAddress } }, TaskCode = agvTask.AgvTaskNum, }; WebResponseContent content = _taskService.AgvSendTask(taskDTO); if (content.Status) { agvTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt(); //agvTask.Remark = content.Data.ObjToString(); _taskService.UpdateTask(agvTask, TaskStatusEnum.AGV_Executing); } else { agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt(); //agvTask.Remark = content.Data.ObjToString(); agvTask.ExceptionMessage = content.Message; } } catch (Exception ex) { agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt(); //agvTask.Remark = content.Data.ObjToString(); agvTask.ExceptionMessage = ex.Message; WriteError(nameof(AGV_PPJob), ex.Message, ex); } } _taskService.UpdateData(newTasks); } catch (Exception ex) { WriteError(nameof(AGV_PPJob), ex.Message, ex); } } } }