huangxiaoqiang
6 小时以前 16749e23b489ee24f993fe9e87346680b7bcf63a
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using AutoMapper;
using HslCommunication;
using NetTaste;
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.ElevatorJob;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public partial class CommonConveyorLineJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        private readonly ITask_HtyRepository _task_HtyRepository;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly ISys_ConfigService _sys_ConfigService;
        private readonly IMapper _mapper;
        private readonly IDt_StationManagerService _stationManagerService;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private readonly IDeviceInfoRepository _deviceInfoRepository;
 
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
 
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository,ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService, IDeviceInfoRepository deviceInfoRepository, ITask_HtyRepository task_HtyRepository)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _mapper = mapper;
            _taskRepository = taskRepository;
            _sys_ConfigService = sys_ConfigService;
            _stationManagerService = stationManagerService;
            _stationManagerRepository = stationManagerRepository;
            _cacheService = cacheService;
            _noticeService = noticeService;
            _deviceInfoRepository = deviceInfoRepository;
            _task_HtyRepository = task_HtyRepository;
        }
 
        public async Task Execute(IJobExecutionContext context)
        {
            string jobName = context.JobDetail.Key.Name;
            try
            {
                // 从JobDataMap中获取传递的参数
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    ConveyorLineTaskCommand conmmand = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>("LK001");
                    if (conmmand != null)
                    {
                        var structs = BitConverter.GetBytes(conmmand.InteractiveSignal).Reverse().ToArray().ToBoolArray();
                        if (structs[2])
                        {
                            //var task = _taskRepository.QueryFirst(x => x.TaskNum == conmmand.TargetAddress);
                            var task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.Line_InExecuting && x.TaskNum == conmmand.ConveyorLineTargetAddress);
                            if (task != null)
                            {
                                task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
                                task.CurrentAddress = task.NextAddress;
                                //获取WMS货位信息
                                task.NextAddress = task.TargetAddress;
                                _taskRepository.UpdateData(task);
                            }
                        }
 
                        if (structs[0])
                        {
                            var task = _taskService.QueryRequestConveyorLineSignalTask();
 
                            if (task != null && task.AGVSign == "RequestPickUp")
                            {
                                if (conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.AllowPickUp, "LK001") == 1)
                                {
                                    await _taskService.ContinueAgvTask(task.AGVTaskNum);
                                    task.AGVSign = "";
                                    task.TaskState = (int)TaskOutStatusEnum.Line_OutFinish;
                                    _taskRepository.UpdateData(task);
                                }
                            }
                            if (task != null && task.AGVSign == "RequestPut")
                            {
                                if (conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.AllowPut, "LK001") == 1)
                                {
                                    await _taskService.ContinueAgvTask(task.AGVTaskNum);
                                    task.AGVSign = "";
                                    _taskRepository.UpdateData(task);
                                }
                            }
 
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // 输出异常信息
                Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
            }
            return;
        }
 
    }
}