1
wankeda
2025-02-12 8326222e65f0bb258c99d93f1954d7696c4ef00d
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Quartz;
using SqlSugar;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEAWCS_Core;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineJob : IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IPlatformStationService _PlatformStationService;
 
        private readonly IMapper _mapper;
 
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, IPlatformStationService platformStation)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _mapper = mapper;
            _PlatformStationService = platformStation;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
 
                if (conveyorLine != null)
                {
                    //读取输送线入库申请
                    RequestInbound(conveyorLine);
                    //读取堆垛机入库站台信号
                    RequestInSCLine(conveyorLine);
 
                    //堆垛机站台进行下发输送线任务
                    RequestOutSCLine(conveyorLine);
                    //读取Rgv出库口任务
                    RequestOutbound(conveyorLine);
                    //读取出库站台,获取出库口更新出库任务
                    RequestOutAdd(conveyorLine);
                    
                }
            }
            catch (Exception ex)
            {
                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
            }
            return Task.CompletedTask;
        }
 
        /// <summary>
        /// 输送线请求入库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        public void RequestInbound(CommonConveyorLine conveyorLine)
        {
            
            List<PlatformStation> platformsList = _PlatformStationService.GetPlatformList(conveyorLine.DeviceCode);
            foreach (var RGVStationitem in platformsList)
            {
                ConveyorLineCommand command = lineCommand(conveyorLine,RGVStationitem.Station_code);
                if (command != null)
                {
                    if (command.Online)
                    {
                        if (command.STB)
                        {
                            WebResponseContent content = _taskService.RequestWMSTask(command.BarCode, RGVStationitem.Station_code.ToString(), command.GoodsType);
                            if (content.Status)
                            {
                                DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem.Station_code.ToString() && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
                                if (deviceProDTO6 != null)
                                {
                                    conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)true);
                                    wcsWriteLog(RGVStationitem.Station_code.ToString(), "正常日志", $"{RGVStationitem.Station_code}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:true");
                                }
                                else
                                {
                                    wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"未找到对于的读取模块{RGVStationitem.Station_code}");
                                }
                            }
                            else
                            {
                                wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"入库站台:{RGVStationitem.Station_code},错误信息:{content.Message}");
                            }
                        }
                        else
                        {
                            DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem.Station_code.ToString() && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
                            if (deviceProDTO6 != null)
                            {
 
                                conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)false);
                                wcsWriteLog(RGVStationitem.Station_code.ToString(), "正常日志", $"{RGVStationitem.Station_code}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:false");
                            }
                            else
                            {
                                wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"未找到对于的读取模块{RGVStationitem.Station_code}");
                            }
                        }
                    }
                    else
                    {
                        wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"该站台{RGVStationitem.Station_code}不处于联机状态");
                    }
                   
                }
            }
        }
 
        /// <summary>
        /// 读取堆垛机入库站台信息,进行任务完成
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        public void RequestInSCLine(CommonConveyorLine conveyorLine)
        {
            List<string> platformsList = _PlatformStationService.GetPlatIn(conveyorLine.DeviceCode);    //读取站台信息
            foreach (var RGVStationitem in platformsList)
            {
                ConveyorLineCommand command = lineCommand(conveyorLine, RGVStationitem);
                if (command != null)
                {
                    if (command.Online && command.STB && command.TaskNo != 0)
                    {
                        //写入反馈
                        DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
 
                        if (conveyorLine.Communicator.Write(deviceProDTO.DeviceProAddress, (bool)true))
                        {
                            DeviceProDTO? deviceProDTO2 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "STB" && x.DeviceProParamType == "ReadDeviceCommand");
                            if (conveyorLine.Communicator.Read<bool>(deviceProDTO2.DeviceProAddress))
                            {
                                conveyorLine.Communicator.Write(deviceProDTO.DeviceProAddress, (bool)false);
                                _taskService.UpdateTaskStatusToNext2(command.TaskNo);
 
                                wcsWriteLog5(RGVStationitem, "正常信息", $"清除站台:{RGVStationitem}的交互信号写入:false,地址:{deviceProDTO.DeviceProAddress}");
                            }
                            else
                            {
                                wcsWriteLog5(RGVStationitem, "错误信息", $"未读取到站台:{RGVStationitem}的交互信号:true,地址:{deviceProDTO.DeviceProAddress}");
                            }
                        }
                        else
                        {
                            conveyorLine.Communicator.Write(deviceProDTO.DeviceProAddress, (bool)false);
                            wcsWriteLog5(RGVStationitem, "错误信息", $"{RGVStationitem}的交互信号写入:true ==》 false,地址:{deviceProDTO.DeviceProAddress}");
                        }
                    }
                    else
                    {
                        wcsWriteLog5(RGVStationitem, "错误信息", $"未读取到站台:{RGVStationitem}的申请信号,目前信号状态为。Online:{command.Online},STB:{command.STB},TaskNo:{command.TaskNo},");
                    }
                }
            }
        }
 
        /// <summary>
        /// RGV输送线请求出站
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        public void RequestOutbound(CommonConveyorLine conveyorLine)
        {
 
            List<string> platformsList = _PlatformStationService.GetPlatform2(conveyorLine.DeviceCode);
            foreach (var RGVStationitem in platformsList)
            {
                ConveyorLineCommand command = lineCommand(conveyorLine, RGVStationitem);
                if (command != null)
                {
                    if(command.Online)
                    {
                        if (command.STB)
                        {
                            if (_taskService.UpdateTaskStatusToNext(command.TaskNo).Status)
                            {
                                DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
                                if (deviceProDTO6 != null)
                                {
                                    conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)true);
                                    wcsWriteLog2(RGVStationitem, "正常日志", $"{RGVStationitem}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:true");
                                }
                                else
                                {
                                    wcsWriteLog2(RGVStationitem, "错误日志", $"未找到对于的读取模块{RGVStationitem}");
                                }
                            }
                            else
                            {
                                wcsWriteLog2(RGVStationitem, "错误日志", $"任务信息更改失败");
                            }
                        }
                        else
                        {
                            DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
                            if (deviceProDTO6 != null)
                            {
 
                                conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)false);
                                wcsWriteLog2(RGVStationitem, "正常日志", $"{RGVStationitem}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:false");
                            }
                            else
                            {
                                wcsWriteLog2(RGVStationitem, "错误日志", $"未找到对于的读取模块{RGVStationitem}");
                            }
                        }
                    }
                    else
                    {
                        wcsWriteLog2(RGVStationitem, "错误日志", $"该站台{RGVStationitem}不处于联机状态");
                    }
 
                }
            }
        }
 
        /// <summary>
        /// 获取出库站台,更新出库任务
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        public void RequestOutAdd(CommonConveyorLine conveyorLine)
        {
            List<PlatformStation> platformsList = _PlatformStationService.GetPlatformOutList(conveyorLine.DeviceCode);
            foreach (var RGVStationitem in platformsList)
            {
                ConveyorLineCommand command = lineCommand(conveyorLine, RGVStationitem.Station_code);
                if (command != null)
                {
                    if(command.Online)
                    {
                        if (command.Free)
                        {
                            if (_taskService.OutConveyorLineTask(RGVStationitem))    //查找是否被占用
                            {
                                wcsWriteLog3(RGVStationitem.Station_code.ToString(), "更新成功", $"任务信息更新成功");
                            }
                            else
                            {
                                wcsWriteLog3(RGVStationitem.Station_code.ToString(), "错误信息", $"已有该站台的出库任务或任务更新失败");
                            }
                        }
                        else
                        {
                            wcsWriteLog3(RGVStationitem.Station_code.ToString(), "错误信息", $"该出库站台不可放货");
                        }
                    }
                    else
                    {
                        wcsWriteLog3(RGVStationitem.Station_code.ToString(), "是否联机", $"该站台{RGVStationitem.Station_code}不处于联机状态");
                    }
                }
            }
        }
 
 
        /// <summary>
        /// 堆垛机出库站台,根据任务进行下发至输送线
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        public void RequestOutSCLine(CommonConveyorLine conveyorLine)
        {
            List<Dt_Task> StationData = _taskService.StackerCraneOutTask();
            
            foreach (var LinSCStationitem in StationData)
            {
                string platformsList = _PlatformStationService.GetOutSCName(LinSCStationitem.Roadway, LinSCStationitem.Station_storey);
                DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList && x.DeviceProParamName == "STB" && x.DeviceProParamType == "DeviceCommand");
                DeviceProDTO? deviceProDTO7 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList && x.DeviceProParamName == "TaskNo" && x.DeviceProParamType == "DeviceCommand");
                if (deviceProDTO6 != null && deviceProDTO7 != null)
                {
                    conveyorLine.Communicator.Write(deviceProDTO7.DeviceProAddress, (int)LinSCStationitem.TaskNum);
                    if (conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)true))
                    {
                        DeviceProDTO? deviceProDTO8 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "ReadDeviceCommand");
                        if (deviceProDTO8 != null)
                        {
                            if (conveyorLine.Communicator.Read<bool>(deviceProDTO8.DeviceProAddress))
                            {
                                _taskService.UpdateTaskStatusToNext(LinSCStationitem.TaskNum);
                                conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)false);
                                conveyorLine.Communicator.Write(deviceProDTO8.DeviceProAddress, (int)0);
                                //写入输送线回应信号与
                            }
                            else
                            {
                                wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台错误信息", $"未读取到输送线回应信号:ACK,{LinSCStationitem}");
                            }
                        }
                        else
                        {
                            wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台错误信息", $"未找到对于的读取模块{LinSCStationitem}");
                        }
                    }
                    else
                    {
                        wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台失败", $"写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:失败");
                    }
                }
                else
                {
                    wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台错误信息", $"未找到对于的写入模块{LinSCStationitem}");
                }
            }
        }
 
        
 
        /// <summary>
        /// 读取信息记录
        /// </summary>
        /// <param name="SCLLinStack"></param>
        /// <param name="Logtype"></param>
        /// <param name="Magessadd"></param>
        public void wcsWriteLog(string SCLLinStack, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log("入库口", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
        }
 
        public void wcsWriteLog2(string SCLLinStack, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log("RGV站台", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
        }
 
        public void wcsWriteLog3(string SCLLinStack, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log("出库口", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
        }
 
        public void wcsWriteLog4(string SCLLinStack, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log("堆垛机站台", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
        }
 
        public void wcsWriteLog5(string SCLLinStack, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log("堆垛机入库站台", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
        }
 
 
 
 
        public ConveyorLineCommand lineCommand(CommonConveyorLine conveyorLine,string Station_code)
        {
            ConveyorLineCommand conveyorLineCommand = new ConveyorLineCommand();
            List<DeviceProDTO> deviceProDTO6 = conveyorLine.DeviceProDTOs
                .Where(x => x.DeviceChildCode == Station_code
                            && DBLine.ListDBdata.Contains(x.DeviceProParamName)
                            && x.DeviceProParamType == "ReadDeviceCommand")
                .ToList();
            foreach (var item in deviceProDTO6)
            {
                var paramName = item.DeviceProParamName;
                var propertyInfo = typeof(ConveyorLineCommand).GetProperty(paramName);
 
                if (propertyInfo != null)
                {
                    if (item.DeviceDataType == "bool")
                    {
                       var value = conveyorLine.Communicator.Read<bool>(item.DeviceProAddress);
                       propertyInfo.SetValue(conveyorLineCommand, value);
                    }else if(item.DeviceDataType == "int")
                    {
                        var value = conveyorLine.Communicator.Read<int>(item.DeviceProAddress);
                        propertyInfo.SetValue(conveyorLineCommand, value);
                    }else if(item.DeviceDataType == "string")
                    {
                        var value = conveyorLine.Communicator.Read<string>(item.DeviceProAddress);
                        propertyInfo.SetValue(conveyorLineCommand, value);
                    }
                }
            }
            return conveyorLineCommand;
        }
    }
}