huangxiaoqiang
2026-04-02 8cf9d378ad17a59b1b18067bd18280dd6b02719f
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using HslCommunication;
using Mapster;
using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Quartz;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.OtherDeviceJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonOtherDevicesJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ITask_HtyRepository _task_htyRepository;
        private readonly ISys_ConfigService _sys_ConfigService;
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
 
        public CommonOtherDevicesJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository task_htyRepository, ISys_ConfigService sys_ConfigService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _routerService = routerService;
            _cacheService = cacheService;
            _noticeService = noticeService;
            _stationManagerRepository = stationManagerRepository;
            _task_htyRepository = task_htyRepository;
            _sys_ConfigService = sys_ConfigService;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                OtherDevice otherDevice = (OtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
                if (otherDevice != null)
                {
                    #region 上料
 
                    var UpRequest = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.UpRequest);
                    ConsoleHelper.WriteInfoLine($"接收上料请求信号:【{UpRequest}】");
 
                    if (UpRequest == 1)
                    {
                        var UpPosition = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.UpPosition);
                        ConsoleHelper.WriteInfoLine($"上料位置信息:【{UpPosition}】");
                        var task = _taskRepository.QueryFirst(x => x.SourceAddress == UpPosition.ToString());
                        if (task == null)
                        {
                            Dt_Task taskNew = new Dt_Task()
                            {
                                TaskNum = _taskRepository.GetTaskNo().Result,
                                PalletCode = Random.Shared.Next(1, 100).ToString(),
                                Roadway = "R001",
                                TaskType = (int)TaskInboundTypeEnum.Inbound,
                                TaskState = (int)TaskInStatusEnum.AGV_InExecuting,
                                SourceAddress = UpPosition.ToString(),
                                TargetAddress = "TargetAddress",
                                CurrentAddress = UpPosition.ToString(),
                                NextAddress = "TargetAddress",
                                Grade = 1,
                                AGVSign = 1.ToString()
                            };
                            _taskRepository.AddData(taskNew);
                            Thread.Sleep(2000);
                            //回复收到信号
                            otherDevice.SetValue(OtherDeviceDBName.UpReplyRequest, 1);
                            Thread.Sleep(2000);
                            //请求放料
                            otherDevice.SetValue(OtherDeviceDBName.RequestPut, 1);
                        }
                        else
                        {
                            ConsoleHelper.WriteInfoLine($"已有任务不允许重复生成【{task.Serialize()}】");
                        }
                    }
 
                    var AllowPut = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.AllowPut);
                    ConsoleHelper.WriteInfoLine($"读取允许放料信号:【{AllowPut}】");
 
                    if (AllowPut == 1)
                    {
                        var task = _taskRepository.QueryFirst(x => x.AGVSign != null && x.TaskType == (int)TaskInboundTypeEnum.Inbound);
 
                        otherDevice.SetValue(OtherDeviceDBName.PutFinish, 1);
                        otherDevice.SetValue(OtherDeviceDBName.UpBarcode, task != null ? task.PalletCode : "1111");
                        _taskRepository.DeleteData(task);
                    }
 
                    #endregion
 
                    #region 下料
 
                    var DownRequest = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.DownRequest);
                    ConsoleHelper.WriteInfoLine($"接收下料请求信号:【{UpRequest}】");
 
                    if (DownRequest == 1)
                    {
                        var DownPosition = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.DownPosition);
                        ConsoleHelper.WriteInfoLine($"下料位置信息:【{DownPosition}】");
 
                        var task = _taskRepository.QueryFirst(x => x.TargetAddress == DownPosition.ToString());
                        if (task == null)
                        {
                            Dt_Task taskNew = new Dt_Task()
                            {
                                TaskNum = _taskRepository.GetTaskNo().Result,
                                PalletCode = Random.Shared.Next(1, 100).ToString(),
                                Roadway = "R001",
                                TaskType = (int)TaskOutboundTypeEnum.Outbound,
                                TaskState = (int)TaskOutStatusEnum.AGV_OutExecuting,
                                SourceAddress = "SourceAddress",
                                TargetAddress = DownPosition.ToString(),
                                CurrentAddress = "SourceAddress",
                                NextAddress = DownPosition.ToString(),
                                Grade = 1,
                                AGVSign = 1.ToString()
                            };
                            _taskRepository.AddData(taskNew);
                            Thread.Sleep(2000);
                            //回复收到信号
                            otherDevice.SetValue(OtherDeviceDBName.DownReplyRequest, 1);
                            Thread.Sleep(2000);
                            //请求取料
                            otherDevice.SetValue(OtherDeviceDBName.RequestPickUp, 1);
                        }
                        else
                        {
                            ConsoleHelper.WriteInfoLine($"已有任务不允许重复生成【{task.Serialize()}】");
                        }
                    }
 
                    var AllowPickUp = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.AllowPickUp);
                    ConsoleHelper.WriteInfoLine($"读取允许取料信号:【{AllowPickUp}】");
 
                    if (AllowPickUp == 1)
                    {
                        var task = _taskRepository.QueryFirst(x => x.AGVSign != null && x.TaskType == (int)TaskOutboundTypeEnum.Outbound);
                        otherDevice.SetValue(OtherDeviceDBName.PickUpFinish, 1);
                        otherDevice.SetValue(OtherDeviceDBName.DownBarcode, task != null ? task.PalletCode : "1111");
 
                        _taskRepository.DeleteData(task);
                    }
 
                    #endregion
                }
            }
            catch (Exception ex)
            {
                WriteError("CommonOtherDevicesJob", "test", ex);
                //ConsoleHelper.WriteErrorLine($"{ex.Message}");
            }
            return Task.CompletedTask;
        }
    }
}