using Quartz; using SqlSugar; using WIDESEA_Common.TaskEnum; using WIDESEA_DTO.Basic; using WIDESEA_IBasicService; using WIDESEA_Model.Models; namespace WIDESEA_WMSServer { [DisallowConcurrentExecution] public class AgvTaskJob : IJob { private readonly ILogger _logger; private readonly ISqlSugarClient _db; private readonly IESSApiService _eSSApiService; // 通过构造函数直接注入依赖 public AgvTaskJob(ILogger logger, ISqlSugarClient db, IESSApiService eSSApiService) { _logger = logger; _db = db; _eSSApiService = eSSApiService; } public async Task Execute(IJobExecutionContext context) { try { var tasks = await _db.Queryable() .Where(x => x.TaskStatus == (int)TaskStatusEnum.New) .ToListAsync(); foreach (var item in tasks) { TaskModel esstask = new TaskModel() { taskType = item.TaskType.GetTaskTypeGroup()==TaskTypeGroup.InboundGroup? "putaway": "carry", taskGroupCode = "", groupPriority = 0, tasks = new List { new() { taskCode=item.TaskNum.ToString(), taskPriority=0, taskDescribe = new TaskDescribeType { containerCode = item.PalletCode, containerType = "CT_KUBOT_STANDARD", fromLocationCode = item.SourceAddress, toStationCode = "", toLocationCode = item.TargetAddress, deadline = 0, } } } }; var result = await _eSSApiService.CreateTaskAsync(esstask); if (result) { item.TaskStatus = (int)TaskStatusEnum.HasSent; await _db.Updateable(item).ExecuteCommandAsync(); } } } catch (Exception ex) { _logger.LogError(ex, "定时任务执行失败"); } } } }