agv
dengjunjie
2024-12-26 7d2fd750dc14c4f5fb31a166727b259d3f2d3b33
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using AutoMapper;
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_DTO.Agv;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class AGVJob : JobBase, IJob
    {
        public readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IMapper _mapper;
 
        public AGVJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _mapper = mapper;
        }
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                List<Dt_Task> UpTasks = new List<Dt_Task>();
                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt() || x.TaskState == TaskStatusEnum.New.ObjToInt()).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                foreach (var agvTask in newTasks)
                {
                    AgvTaskDTO taskDTO = new AgvTaskDTO()
                    {
                        ReqCode = agvTask.TaskNum.ToString(),
                        TaskTyp = AgvTaskType(agvTask.TaskType, agvTask.DeviceCode),
                        PositionCodePath = new List<CodePath>()
                        {
                            new CodePath()
                            {
                                type="",
                                positionCode=""
                            },
                            new CodePath()
                            {
                                type="",
                                positionCode=""
                            }
                        },
                        PodTyp = agvTask.PalletType == 1 ? "XX" : "DD",
                    };
                    WebResponseContent content = _taskService.AgvSendTask(taskDTO);
                    if (content.Status)
                    {
                        agvTask.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
                        UpTasks.Add(agvTask);
                    }
                }
                _taskService.UpdateData(UpTasks);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(nameof(AGVJob) + ":" + ex.Message);
            }
            return Task.CompletedTask;
        }
 
        public string AgvTaskType(int TaskType, string DeviceCode)
        {
            switch (DeviceCode)
            {
                case "SC01-CSJ":
                    {
                        return TaskType == TaskTypeEnum.ProductionReturn.ObjToInt() ? "23" : "24";
                    }
                case "SC01-ZH":
                    {
                        if (TaskType == TaskTypeEnum.InboundXB.ObjToInt())
                            return "20";
                        else if (TaskType == TaskTypeEnum.InboundJT.ObjToInt())
                            return "21";
                        else return "22";
                    }
                default:
                    throw new NotImplementedException();
            }
        }
    }
}