wanshenmean
2025-04-16 29f20b28392d212c04c0c40a512894f8622cfa53
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
using HslCommunication;
using Mapster;
using Newtonsoft.Json;
using System.Diagnostics.CodeAnalysis;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.Models;
 
namespace WIDESEAWCS_TaskInfoService
{
    public partial class TaskService
    {
        /// <summary>
        /// 根据托盘号、起始地址向WMS请求任务
        /// </summary>
        /// <param name="palletCode">托盘号</param>
        /// <param name="sourceAddress">起始地址</param>
        /// <returns></returns>
        public async Task<WebResponseContent> RequestTask(string palletCode, string EquiCodeMOM, string Roadways, string area, string CurrentChildCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var hasTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode);
                if (hasTask != null)
                {
                    return content.Error("当前托盘存在任务");
                }
 
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestInTask)?.ConfigValue;
                if (wmsBase == null || requestTask == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddrss = wmsBase + requestTask;
 
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = EquiCodeMOM, Roadways = Roadways, area = area, Position = CurrentChildCode }.ToJsonString());
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
 
                if (!content.Status)
                {
                    // wms失败返回去NG口任务
 
                    return content;
                }
 
                var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                return ReceiveByWMSTask(task);
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        #region 根据托盘号、站台向WMS请求任务
 
        /// <summary>
        /// 根据托盘号、站台向WMS请求任务
        /// </summary>
        /// <param name="palletCode">托盘号</param>
        /// <param name="stationManager">站台</param>
        /// <returns></returns>
        public async Task<WebResponseContent> RequestTask1(string palletCode, Dt_StationManager stationManager)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                StaticVariable.isLineRun = false;
                var hasTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode);
                if (hasTask != null)
                {
                    return content.Error("当前托盘存在任务");
                }
 
                var Station = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 6 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea);
                var tasks = await BaseDal.QueryFirstAsync(x => x.TaskType == (int)TaskOutboundTypeEnum.InToOut && x.TargetAddress == stationManager.stationLocation && x.CurrentAddress == Station.stationChildCode);
                if (tasks != null)
                {
                    ConsoleHelper.WriteErrorLine($"【{stationManager.stationChildCode}】已存在直接出库任务任务");
                    return content.Error($"【{stationManager.stationChildCode}】已存在直接出库任务任务");
                }
 
                if (StaticVariable.isStackerRun)
                {
                    if (stationManager.stationType == 7)
                    {
                        var runTask = await BaseDal.QueryFirstAsync(x => x.CurrentAddress == Station.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray);
                        if (runTask != null)
                        {
                            runTask.TargetAddress = stationManager.stationLocation;
                            runTask.NextAddress = stationManager.stationChildCode;
                            runTask.Grade = 3;
                            runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut;
                            runTask.TaskState = (int)TaskOutStatusEnum.OutNew;
 
                            var config1 = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                            var wmsBase1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                            var requestTask1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.SetEmptyOutbyInToOutAsync)?.ConfigValue;
                            if (wmsBase1 == null || requestTask1 == null)
                            {
                                throw new InvalidOperationException("WMS IP 未配置");
                            }
                            var wmsIpAddrss1 = wmsBase1 + requestTask1;
 
                            var result1 = await HttpHelper.PostAsync(wmsIpAddrss1, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = Station.stationChildCode }.ToJsonString());
                            content = JsonConvert.DeserializeObject<WebResponseContent>(result1);
                            if (content.Status)
                            {
                                await BaseDal.UpdateDataAsync(runTask);
                                ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】");
                                return content.OK("成功");
                            }
                            else
                                ConsoleHelper.WriteErrorLine(content.Message);
                        }
                        else
                            ConsoleHelper.WriteErrorLine($"【{Station.stationChildCode}】未找到空托盘入库任务");
                    }
                    else if (stationManager.stationType == 6)
                    {
                        var emptyStation = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 7 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea);
                        var runTask = await BaseDal.QueryFirstAsync(x => x.NextAddress == emptyStation.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray);
                        if (runTask != null)
                        {
                            runTask.SourceAddress = stationManager.stationLocation;
                            runTask.CurrentAddress = stationManager.stationChildCode;
                            runTask.Grade = 3;
                            runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut;
                            runTask.TaskState = (int)TaskOutStatusEnum.OutNew;
                            runTask.PalletCode = palletCode;
 
                            var config1 = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                            var wmsBase1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                            var requestTask1 = config1.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.SetEmptyOutbyInToOutOneAsync)?.ConfigValue;
                            if (wmsBase1 == null || requestTask1 == null)
                            {
                                throw new InvalidOperationException("WMS IP 未配置");
                            }
                            var wmsIpAddrss1 = wmsBase1 + requestTask1;
 
                            var result1 = await HttpHelper.PostAsync(wmsIpAddrss1, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = emptyStation.stationChildCode }.ToJsonString());
                            content = JsonConvert.DeserializeObject<WebResponseContent>(result1);
                            if (content.Status)
                            {
                                await BaseDal.UpdateDataAsync(runTask);
                                ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】");
                                return content.OK("成功");
                            }
                            else
                                ConsoleHelper.WriteErrorLine(content.Message);
                        }
                    }
                }
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestInTask)?.ConfigValue;
                if (wmsBase == null || requestTask == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddrss = wmsBase + requestTask;
 
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode }.ToJsonString());
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                ConsoleHelper.WriteErrorLine($"{stationManager.stationChildCode}站台请求响应信息:{content.ToJsonString()}");
                if (!content.Status)
                {
                    // wms失败返回去NG口任务
                    //if (stationManager.stationChildCode != stationManager.stationNGChildCode)
                    //{
                    //    WMSTaskDTO taskDTO = new WMSTaskDTO()
                    //    {
                    //        Grade = 8,
                    //        PalletCode = palletCode,
                    //        SourceAddress = stationManager.stationLocation,
                    //        TargetAddress = stationManager.stationNGLocation,
                    //        RoadWay = stationManager.Roadway,
                    //        TaskNum = 1000,
                    //        TaskState = (int)TaskOutStatusEnum.OutNew,
                    //        TaskType = (int)TaskOutboundTypeEnum.InToOut
                    //    };
                    //}
                    return content;
                }
 
                var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                ConsoleHelper.WriteSuccessLine(content.Data.ToString());
                return ReceiveByWMSTask(task);
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
                StaticVariable.isLineRun = true;
            }
        }
 
        /// <summary>
        /// 根据托盘号、站台向WMS请求任务
        /// </summary>
        /// <param name="palletCode">托盘号</param>
        /// <param name="stationManager">站台</param>
        /// <returns></returns>
        public async Task<WebResponseContent> RequestTask(string palletCode, Dt_StationManager stationManager)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
 
                // 检查当前托盘是否存在任务
                if (await HasTask(palletCode))
                {
                    return content.Error("当前托盘存在任务");
                }
 
                //// 检查是否已存在直接出库任务
                //if (await HasDirectOutboundTask(stationManager))
                //{
                //    return content.Error($"【{stationManager.stationChildCode}】已存在直接出库任务任务");
                //}
 
                //if (stationManager.stationType == 7)
                //{
                //    var result = await HandleStationType7(palletCode, stationManager);
                //    if (result != null)
                //    {
                //        return result;
                //    }
                //}
                //else if (stationManager.stationType == 6)
                //{
                //    var result = await HandleStationType6(palletCode, stationManager);
                //    if (result != null)
                //    {
                //        return result;
                //    }
                //}
 
                // 发起请求获取入库任务
                content = await RequestInTask(palletCode, stationManager);
                ConsoleHelper.WriteErrorLine($"{stationManager.stationChildCode}站台请求响应信息:{content.ToJsonString()}");
 
                if (!content.Status)
                {
                    return content;
                }
 
                var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                ConsoleHelper.WriteSuccessLine(content.Data.ToString());
                return ReceiveByWMSTask(task);
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        // 检查当前托盘是否存在任务
        private async Task<bool> HasTask(string palletCode)
        {
            var hasTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode);
            return hasTask != null;
        }
 
        // 检查是否已存在直接出库任务
        private async Task<bool> HasDirectOutboundTask(Dt_StationManager stationManager)
        {
            var station = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 6 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea);
            var tasks = await BaseDal.QueryFirstAsync(x => x.TaskType == (int)TaskOutboundTypeEnum.InToOut && x.TargetAddress == stationManager.stationLocation && x.CurrentAddress == station.stationChildCode);
            return tasks != null;
        }
 
        // 处理 stationType 为 7 的情况
        private async Task<WebResponseContent> HandleStationType7(Dt_StationManager stationManager)
        {
            var station = await _taskNeedBarcodeRepository.QueryFirstAsync(x => x.toArea == stationManager.stationChildCode && x.productLine == stationManager.productLine);
 
            return null;
        }
 
        // 处理 stationType 为 6 的情况
        private async Task<WebResponseContent> HandleStationType6(string palletCode, Dt_StationManager stationManager)
        {
            var emptyStation = await _stationManagerRepository.QueryFirstAsync(x => x.stationType == 7 && x.productLine == stationManager.productLine && x.stationArea == stationManager.stationArea);
            var runTask = await BaseDal.QueryFirstAsync(x => x.NextAddress == emptyStation.stationChildCode && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.TaskType == (int)TaskInboundTypeEnum.InTray);
 
            if (runTask != null)
            {
                runTask.SourceAddress = stationManager.stationLocation;
                runTask.CurrentAddress = stationManager.stationChildCode;
                runTask.Grade = 3;
                runTask.TaskType = (int)TaskOutboundTypeEnum.InToOut;
                runTask.TaskState = (int)TaskOutStatusEnum.OutNew;
                runTask.PalletCode = palletCode;
 
                var wmsIpAddrss = GetWmsIpAddress(SysConfigKeyConst.SetEmptyOutbyInToOutAsync);
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = runTask.PalletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = emptyStation.stationChildCode }.ToJsonString());
                var content = JsonConvert.DeserializeObject<WebResponseContent>(result);
 
                if (content.Status)
                {
                    await BaseDal.UpdateDataAsync(runTask);
                    ConsoleHelper.WriteSuccessLine($"【{runTask.PalletCode}直接出库至二封】");
                    return content.OK("成功");
                }
                else
                {
                    ConsoleHelper.WriteErrorLine(content.Message);
                }
            }
 
            return null;
        }
 
        // 获取 WMS 请求地址
        private string GetWmsIpAddress(string configKey)
        {
            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
            var requestTask = config.FirstOrDefault(x => x.ConfigKey == configKey)?.ConfigValue;
 
            if (wmsBase == null || requestTask == null)
            {
                throw new InvalidOperationException("WMS IP 未配置");
            }
 
            return wmsBase + requestTask;
        }
 
        // 发起请求获取入库任务
        private async Task<WebResponseContent> RequestInTask(string palletCode, Dt_StationManager stationManager)
        {
            var wmsIpAddrss = GetWmsIpAddress(SysConfigKeyConst.RequestInTask);
            var result = await HttpHelper.PostAsync(wmsIpAddrss, new { palletCode = palletCode, EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode, ProductionLine = stationManager.productLine}.ToJsonString());
            return JsonConvert.DeserializeObject<WebResponseContent>(result);
        }
 
        #endregion 根据托盘号、站台向WMS请求任务
 
        public async Task<WebResponseContent> RequestOutTaskToBZAsync(Dt_StationManager stationManager)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestOutTaskToBZ)?.ConfigValue;
                if (wmsBase == null || requestTask == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddrss = wmsBase + requestTask;
 
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { Position = stationManager.stationChildCode }.ToJsonString());
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                if (!content.Status)
                {
                    //无满足条件可出库至包装的库存
                    return content;
                }
 
                var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                ConsoleHelper.WriteSuccessLine(content.Data.ToString());
 
                content = ReceiveWMSTask(new List<WMSTaskDTO> { task });
 
                return content;
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 接收WMS任务信息
        /// </summary>
        /// <param name="taskDTOs">WMS任务对象集合</param>
        /// <returns>返回处理结果</returns>
        public WebResponseContent ReceiveByWMSTask([NotNull] WMSTaskDTO taskDTO)
        {
            WebResponseContent content = new WebResponseContent();
            ConsoleHelper.WriteSuccessLine($"接收到任务,任务数据:{JsonConvert.SerializeObject(taskDTO, Formatting.Indented)}");
            try
            {
                if (BaseDal.QueryFirst(x => x.TaskNum == taskDTO.TaskNum || x.PalletCode == taskDTO.PalletCode) != null)
                {
                    return content.OK();
                }
                Dt_Task task = _mapper.Map<Dt_Task>(taskDTO);
                task.Creater = "WMS";
 
                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                {
                    if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray)
                    {
                        // 查询下一个路由
                        List<Dt_Router> routers = _routerService.QueryNextRoutes(taskDTO.RoadWay, taskDTO.TargetAddress);
                        if (routers.Count > 0)
                        {
                            // 设置任务状态为出库新建
                            task.TaskState = (int)TaskOutStatusEnum.OutNew;
                            // 设置当前地址为源地址
                            task.CurrentAddress = taskDTO.SourceAddress;
                            // 设置下一个地址为第一个子位置
                            task.NextAddress = routers.FirstOrDefault().ChildPosi;
                        }
                        else
                        {
                            // 查询从源地址到目标地址的路由
                            routers = _routerService.QueryNextRoutes(taskDTO.SourceAddress, taskDTO.TargetAddress);
                            if (routers.Count > 0)
                            {
                                // 设置任务状态为出库完成
                                task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
                                // 设置当前地址为源地址
                                task.CurrentAddress = taskDTO.SourceAddress;
                                // 设置下一个地址为第一个子位置
                                task.NextAddress = routers.FirstOrDefault().ChildPosi;
                            }
                        }
                    }
                    else
                    {
                        var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.TargetAddress && x.Roadway == taskDTO.RoadWay);
                        task.TaskState = (int)TaskOutStatusEnum.OutNew;
                        task.CurrentAddress = taskDTO.RoadWay;
                        task.NextAddress = stationinfo.stationChildCode;
                        task.SourceAddress = taskDTO.SourceAddress;
                        task.TargetAddress = taskDTO.TargetAddress;
                        //if (taskDTO.TaskType == (int)TaskOutboundTypeEnum.InToOut)
                        //{
                        //    task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
                        //}
                    }
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                {
                    var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.SourceAddress && x.Roadway == taskDTO.RoadWay);
                    task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
                    task.SourceAddress = taskDTO.SourceAddress;
                    task.CurrentAddress = stationinfo.stationChildCode;
                    task.NextAddress = stationinfo.stationChildCode;
                    task.TargetAddress = taskDTO.TargetAddress;
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
                {
                    task.TaskState = (int)TaskStatus.Created;
                    task.SourceAddress = taskDTO.SourceAddress;
                    task.CurrentAddress = taskDTO.SourceAddress;
                    task.NextAddress = taskDTO.TargetAddress;
                    task.TargetAddress = taskDTO.TargetAddress;
                }
 
                BaseDal.AddData(task);
 
                _taskExecuteDetailService.AddTaskExecuteDetail(task.WMSId, "接收WMS任务");
 
                content = WebResponseContent.Instance.OK("成功");
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}");
            }
            return content;
        }
 
        /// <summary>
        /// 接收WMS任务信息
        /// </summary>
        /// <param name="taskDTOs">WMS任务对象集合</param>
        /// <returns>返回处理结果</returns>
        public WebResponseContent ReceiveByBZOtuTask([NotNull] WMSTaskDTO taskDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (BaseDal.QueryFirst(x => x.TaskNum == taskDTO.TaskNum || x.PalletCode == taskDTO.PalletCode) != null)
                {
                    return content.OK();
                }
                Dt_Task task = _mapper.Map<Dt_Task>(taskDTO);
                task.Creater = "WMS";
 
                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                {
                    var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationLocation == taskDTO.TargetAddress && x.Roadway == taskDTO.RoadWay);
                    task.TaskState = (int)TaskOutStatusEnum.OutNew;
                    task.CurrentAddress = stationinfo.stationChildCode;
                    task.NextAddress = stationinfo.stationChildCode;
                    task.SourceAddress = taskDTO.SourceAddress;
                    task.TargetAddress = taskDTO.TargetAddress;
                }
                BaseDal.AddData(task);
 
                _taskExecuteDetailService.AddTaskExecuteDetail(task.WMSId, "接收WMS任务");
 
                content = WebResponseContent.Instance.OK("成功");
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}");
            }
            return content;
        }
 
        /// <summary>
        /// 高温出库
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <returns></returns>
        public WebResponseContent ReceiveByWMSGWTask([NotNull] WMSTaskDTO taskDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (BaseDal.QueryFirst(x => x.TaskNum == taskDTO.TaskNum || x.PalletCode == taskDTO.PalletCode) != null)
                {
                    return content.OK();
                }
                Dt_Task task = _mapper.Map<Dt_Task>(taskDTO);
                task.Creater = "WMS";
 
                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                {
                    task.TaskState = (int)TaskOutStatusEnum.OutNew;
                    task.CurrentAddress = taskDTO.RoadWay;
                    task.NextAddress = "002-000-002";
                    task.SourceAddress = taskDTO.SourceAddress;
                    task.TargetAddress = taskDTO.TargetAddress;
                }
                BaseDal.AddData(task);
 
                _taskExecuteDetailService.AddTaskExecuteDetail(task.WMSId, "接收WMS任务");
 
                content = WebResponseContent.Instance.OK("成功");
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}");
            }
            return content;
        }
 
        /// <summary>
        /// 接收WMS任务信息
        /// </summary>
        /// <param name="taskDTOs">WMS任务对象集合</param>
        /// <returns>返回处理结果</returns>
        public async Task<WebResponseContent> RequestFlow(Dt_StationManager stationManager)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestFlow)?.ConfigValue;
                if (wmsBase == null || requestTask == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddrss = wmsBase + requestTask;
 
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { EquiCodeMOM = stationManager.stationEquipMOM, Roadways = stationManager.Roadway, area = stationManager.stationArea, Position = stationManager.stationChildCode }.ToJsonString());
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
 
                if (!content.Status)
                {
                    return content;
                }
                Dt_StationManager dt_Station = content.Data as Dt_StationManager;
                //dt_Station.
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}");
            }
            return content;
        }
 
        /// <summary>
        /// 根据托盘号和设备号查询任务
        /// </summary>
        /// <param name="taskNum">任务号</param>
        /// <param name="currentAddress">当前地址</param>
        /// <returns></returns>
        public Dt_Task QueryTaskByPalletCode(string palletCode, string Roadway)
        {
            return BaseDal.QueryFirst(x => x.PalletCode == palletCode && x.Roadway == Roadway, TaskOrderBy);
        }
 
        ///// <summary>
        ///// 根据设备编号、当前地址查询输送线未执行的任务
        ///// </summary>
        ///// <param name="deviceNo">设备编号</param>
        ///// <param name="currentAddress">当前地址</param>
        ///// <returns></returns>
        //public Dt_Task QueryConveyorLineTask(string deviceNo, string currentAddress)
        //{
        //    return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy);
        //}
 
        /// 任务完成
        /// </summary>
        /// <param name="taskNum">任务编号</param>
        /// <returns>返回处理结果</returns>
        public WebResponseContent StackCraneTaskCompletedByStation(int taskNum)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
 
                #region WMS同步任务完成
 
                var keys = new Dictionary<string, object>()
                {
                    {"taskNum", taskNum}
                };
                // 获取WMSip地址
                var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
                var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.CompleteTask)?.ConfigValue;
                if (wmsBase == null || completeTask == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddress = wmsBase + completeTask;
 
                var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result;
                content = JsonConvert.DeserializeObject<WebResponseContent>(result);
 
                #endregion WMS同步任务完成
 
                if (content.Status)
                {
                    task.TaskState = 1;  //任务完成
                    var taskHty = task.Adapt<Dt_Task_Hty>();
                    _taskHtyRepository.AddData(taskHty);
                    BaseDal.DeleteData(task);
                }
 
                content.OK(data: task);
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"任务完成异常,任务号:【{taskNum}】");
            }
            return content;
        }
        //public override WebResponseContent DeleteData(Dt_Task entity)
        //{
        //    return base.DeleteData(entity);
        //}
    }
}