1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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<AgvTaskJob> _logger;
        private readonly ISqlSugarClient _db;
        private readonly IESSApiService _eSSApiService;
        // 通过构造函数直接注入依赖
        public AgvTaskJob(ILogger<AgvTaskJob> logger, ISqlSugarClient db, IESSApiService eSSApiService)
        {
            _logger = logger;
            _db = db;
            _eSSApiService = eSSApiService;
        }
 
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                var tasks = await _db.Queryable<Dt_Task>()
                    .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<TasksType>
                        {
                                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, "定时任务执行失败");
            }
        }
 
    }
}