1
huanghongfeng
10 天以前 0b4792ff8245f9eac16e6d02452eb9a091f6f72b
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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
using Autofac.Core;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Hosting;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Net;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class SpeStackerCraneJob : IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        private readonly IAgvStationService _agvStationService;
 
 
        public SpeStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IAgvStationService agvStationService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _routerService = routerService;
            _agvStationService = agvStationService;
        }
 
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                SpeStackerCrane speStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (speStackerCrane != null)
                {
                    GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
 
                    if (getStackerObject.RGVInitializationValue == RGVInitialize.Initialized)
                    {
                        //读取设备完成信息
                        if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Completed || getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.AbnormalCompletion)
                        {
                            CommonStackerCrane_AGVTaskCompletedEventHandler(getStackerObject, speStackerCrane);
                        }
 
                        //判断当前设备是入库还是出库
                        /*if (GetDeviceAddress.OutbounMotherChildCartbool(speStackerCrane.DeviceCode))
                        {
                            //判断当前安全门是否为绿色灯
                            if (GetDeviceAddress.ReadAqmDecicStice(1))
                            {
                                return null;
                            }
                        }
                        else
                        {
                            //判断入库端安全门是否正常
                            if (GetDeviceAddress.ReadAqmDecicStice(2))
                            {
                                return null;
                            }
                        }*/
 
                        
                        
 
 
                        if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
                        getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
                        {
                            //查找RGV进行下发任务
                            Dt_Task task = GetTask(speStackerCrane.DeviceCode, getStackerObject);
                            if (task != null)
                            {
                                //调取写入RGV小车任务
                                RgvCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                                if (stackerCraneTaskCommand != null)
                                {
                                    bool sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand);
                                    if (sendFlag)
                                    {
                                        //修改任务状态
                                        _taskService.UpdateTaskStatusToNext(task);
                                    }
                                }
 
                            }
                            else
                            {
                                if (GetDeviceAddress.OutbounMotherChildCartbool(speStackerCrane.DeviceCode))
                                {
                                    //当没任务的时候,则进行移动
                                    Returnposition(speStackerCrane.DeviceCode, getStackerObject.RGVCurrentlocation, (int)getStackerObject.RgvCraneStatusValue);
 
                                }
                                else if (GetDeviceAddress.OutbounMotherChildCartbool2(speStackerCrane.DeviceCode))
                                {
                                    InReturnposition(speStackerCrane.DeviceCode, getStackerObject.RGVCurrentlocation, (int)getStackerObject.RgvCraneStatusValue);
                                }
 
                            }
                        }
                    }
 
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
            }
            return Task.CompletedTask;
        }
 
        #region 任务完成
        private void CommonStackerCrane_AGVTaskCompletedEventHandler(GetStackerObject getStackerObject, SpeStackerCrane speStackerCrane)
        {
            if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Completed && getStackerObject.CurrentRgvtaskid == 30001)
            {
                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 1);
                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 0);
            }
            else if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Completed && getStackerObject.CurrentRgvtaskid != 0 && getStackerObject.CurrentRgvtaskid != 30001)
            {
                _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid);   //正常任务完成
                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 1);
                speStackerCrane.SetValue(RGV_taskcoDBName.RGV_taskcomplete, 0);
            }
            else if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.AbnormalCompletion && getStackerObject.CurrentRgvtaskid != 0 && getStackerObject.CurrentRgvtaskid != 30001)
            {
 
                //修改任务状态为异常完成                                              
                _taskService.HandleInAbnormal(getStackerObject.CurrentRgvtaskid);   
 
                //写入异常完成报警信息
                speStackerCrane.Communicator.Write<short>("DB101.36", 1);   //写入报警
            }
        }
        #endregion
 
 
 
        private Dt_Task? GetTask(string DeviceCode, GetStackerObject getStackerObject)
        {
            // 根据设备名称,获取到设备相关数据
            AGVStation RGVTaskdevice = _agvStationService.Corridorequipment(DeviceCode);   //根据设备获取到内容
            return RGVTaskdevice.Station_tasktype switch
            {
                (int)RGVTasktype.Inbound => HandleInboundTask(RGVTaskdevice, getStackerObject),
                (int)RGVTasktype.Outbound => OutboundEquipmentTask(RGVTaskdevice, getStackerObject),    //出库
                _ => null
            };
 
 
        }
 
        #region 入库方法
        private Dt_Task? HandleInboundTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
        {
            return (RGVTaskdevice.Station_material, getStackerObject.RgvCraneStatusValue) switch
            {
                ((int)RGVEquipment.InRGVForklift, RgvEquipmentStatus.NoCargo)   //叉车式RGV无货,下发取货任务
                    => _taskService.PickupWarehouse(RGVTaskdevice.ChildPosiDeviceCode),
 
                ((int)RGVEquipment.InRGVForklift, RgvEquipmentStatus.HasCargo)
                    => ForkliftUnloading(RGVTaskdevice),    //叉车式进行放货(已完成)
 
                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.NoCargo)
                    => ZichePickUpAisle(RGVTaskdevice, getStackerObject),   //过道子车进行取货(已完成)
 
                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.HasCargo)
                    => GoodsPlacedCorridor(RGVTaskdevice),    //子车放货任务(已完成)
 
                ((int)RGVEquipment.Mothertrailer, RgvEquipmentStatus.HasCargo)
                    => MotherVehicleMovement(RGVTaskdevice),        //母车移动(已完成)
 
                _ => null
            };
 
        }
 
        #region 叉车式进行放货(已完成)
        public Dt_Task? ForkliftUnloading(AGVStation RGVTaskdevice)
        {
            Dt_Task dt_Task = _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode);
 
            //判断HCJ是否有货
            if (GetDeviceAddress.HCJIsstock(dt_Task.NextAddress))
            {
                //判断子车是否在接驳台下
                var zichestation = _agvStationService.OutGetZicheDeepHCJ(1061);
                int ziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                if ((ziche == zichestation.WaitmomentOne || ziche == zichestation.WaitmomentTwo || ziche == zichestation.MotherCarDeviceCode || ziche == zichestation.MotherCardeputy || ziche == zichestation.HCJStorageaddress) && ziche != 1021)
                {
                    //获取这个接驳台是否有取货任务
                    Dt_Task zitask = _taskService.ViceChariotPickupTask2(RGVTaskdevice.ChildPosiDeviceCode);
                    if (zitask == null)
                    {
 
                        return dt_Task;
                    }
                }
            }
            return null;
        }
        #endregion
 
        #region 过道子车进行取货(已完成)
        public Dt_Task? ZichePickUpAisle(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
        {
            //获取子车取货任务
            Dt_Task dt_Task = _taskService.ViceChariotPickupTask(RGVTaskdevice.ChildPosiDeviceCode);
            if (dt_Task == null) return null;
            if (RGVTaskdevice.Station_Area == 6)    //外侧进取货,则需要判断子车当前位置
            {
                if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentOne)
                {
                    //还需要判断入库口叉车是否收回叉车了
 
                    //在等待点1,则需要判断1号母车在堆垛机取货口
                    var mu1rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
                    int mu1 = GetDeviceAddress.GetEquipmentlocation(mu1rgv.ChildPosiDeviceCode); //此时的RGV应该无货
                    bool ywh = GetDeviceAddress.Mucheywhaddres(mu1rgv.ChildPosiDeviceCode);
                    if (mu1 == mu1rgv.Motherinlaw || (ywh && mu1 == mu1rgv.ZicheMotherinlaw))   //在堆垛机取货口
                    {
                        //=============================新增当去取货时进行判断巷道,看能不能提前拉出母车
                        if (int.Parse(dt_Task.TargetAddress) == (int)StorageAisleEnum.LaneTwo)
                        {
                            int taraddress = int.Parse(dt_Task.TargetAddress);
                            var InMotherVehicle = _agvStationService.ObtainCcordingTunnel(taraddress);    //获取到需要入库的母车(2巷道)
                            int mu2 = GetDeviceAddress.GetEquipmentlocation(InMotherVehicle.ChildPosiDeviceCode); //此时的RGV应该无货
                            if (GetDeviceAddress.Mucheywhaddres(InMotherVehicle.ChildPosiDeviceCode))   //判断无货
                            {
                                if (mu2 == InMotherVehicle.ZicheMotherinlaw)
                                {
                                    return dt_Task;
                                }
                                else if (mu2 == InMotherVehicle.Motherinlaw)
                                {
                                    RGVMovetask(InMotherVehicle.ZicheMotherinlaw, InMotherVehicle.ChildPosiDeviceCode);
                                }
                            }
                        }
                        //=============================新增当去取货时进行判断巷道,看能不能提前拉出母车
                        return dt_Task;
                    }
                    //去掉原因:在该出子车去取货,可直接穿过无货母车,拖车
                    /*else 
                    {
                        Dt_Task task = _taskService.MothermachinemovementTask2(RGVTaskdevice.ChildPosiDeviceCode);
                        if (task == null)
                        {
                            RGVMovetask(mu1rgv.Motherinlaw, mu1rgv.ChildPosiDeviceCode);
                        }
                    }*/
 
                }
                else if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentTwo)    //则需要判断两个母车的位子
                {
                    //判断两个子车是否在堆垛机取货口
 
                    //母车1
                    var mu1rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
                    int mu1 = GetDeviceAddress.GetEquipmentlocation(mu1rgv.ChildPosiDeviceCode); //此时的RGV应该无货
                    bool m1Isitstock1 = GetDeviceAddress.Mucheywhaddres(mu1rgv.ChildPosiDeviceCode);
 
                    var mu2rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCardeputy);
                    int mu2 = GetDeviceAddress.GetEquipmentlocation(mu2rgv.ChildPosiDeviceCode); //此时的RGV应该无货
                    bool m1Isitstock2 = GetDeviceAddress.Mucheywhaddres(mu2rgv.ChildPosiDeviceCode);
 
                    // 提取可读性变量
                    bool mu1AtHome = mu1 == mu1rgv.Motherinlaw;
                    bool mu2AtHome = mu2 == mu2rgv.Motherinlaw;
                    bool mu1Ready = mu1 == mu1rgv.ZicheMotherinlaw && m1Isitstock1;
                    bool mu2Ready = mu2 == mu2rgv.ZicheMotherinlaw && m1Isitstock2;
 
                    // 合并所有满足条件的情况
                    if ((mu1AtHome && mu2AtHome) ||        // 都在初始位置
                        (mu1Ready && mu2Ready) ||          // 都在就绪位置且无货
                        (mu1AtHome && mu2Ready) ||         // 1在初始位置,2就绪
                        (mu1Ready && mu2AtHome))           // 1就绪,2在初始位置
                    {
                        return dt_Task;
                    }
 
                    /*else
                    {
                        //无需把母车移动至取货台,无货状态的子车无需踩托盘过去去取货
                        if (mu1 != mu1rgv.Motherinlaw)
                        {
                            Dt_Task task = _taskService.MothermachinemovementTask2(mu1rgv.ChildPosiDeviceCode);
                            if (task == null)
                            {
                                RGVMovetask(mu1rgv.Motherinlaw, mu1rgv.ChildPosiDeviceCode);
                            }
                        }
                        if (mu2 != mu2rgv.Motherinlaw)
                        {
                            Dt_Task task2 = _taskService.MothermachinemovementTask2(mu2rgv.ChildPosiDeviceCode);
                            if (task2 == null)
                            {
                                RGVMovetask(mu2rgv.Motherinlaw, mu2rgv.ChildPosiDeviceCode);
                            }
                        }
                    }*/
                }
            }
            else if (RGVTaskdevice.Station_Area == 5)
            {
                if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentOne)
                {
                    //需要判断外侧小车是否在HCJ上
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
 
                    if ((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress)
                    {
                        return dt_Task;
                    }
 
                }
                else if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentTwo)    //需要判断3巷道母车是否在取货站台
                {
                    //判断子车是否在HCJ站台
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
 
                    if ((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress)
                    {
                        //母车1
                        var mu1rgv = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
                        int mu1 = GetDeviceAddress.GetEquipmentInformation(mu1rgv.ChildPosiDeviceCode); //此时的RGV应该无货
                        if (mu1 == mu1rgv.Motherinlaw)
                        {
                            return dt_Task;
                        }
                        else
                        {
                            Dt_Task task = _taskService.MothermachinemovementTask2(mu1rgv.ChildPosiDeviceCode);
                            if (task == null)
                            {
                                RGVMovetask(mu1rgv.Motherinlaw, mu1rgv.ChildPosiDeviceCode);
                            }
                        }
                    }
                }
            }
            return null;
        }
        /// <summary>
        /// 判断外侧母车是否在入口口
        /// </summary>
        /// <param name="task"></param>
        /// <param name="currentStation"></param>
        /// <returns></returns>
        private Dt_Task? HandleMedialCase(Dt_Task task, int currentStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(currentStation);
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            if (motherCarAddress == Muche.Motherinlaw) return task;
            RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            return null;
        }
        /// <summary>
        /// 判断内外侧母车是否在入库口
        /// </summary>
        /// <param name="task"></param>
        /// <param name="currentStation"></param>
        /// <returns></returns>
        private Dt_Task? HandleMedialCase2(Dt_Task task, AGVStation currentStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(currentStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(currentStation.MotherCardeputy);    //内侧母车
 
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            if (motherCarAddress == 0 || motherCarAddress2 == 0) return null;
            // 如果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.Motherinlaw)
            {
                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
            }
            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw) return task;
            // 母车已在正确位置
            return null;
        }
 
 
        #endregion
 
        #region 过道子车进行放货
        public Dt_Task? GoodsPlacedCorridor(AGVStation RGVTaskdevice)
        {
            Dt_Task task = _taskService.ViceChariotPlacingTask(RGVTaskdevice.ChildPosiDeviceCode);  //获取到放货任务
            if (task == null) return null;
            int nexaddres = int.Parse(task.NextAddress);    //判断是放货在哪的任务
            switch (nexaddres)
            {
                case int Whcjaddress when Whcjaddress == RGVTaskdevice.MotherCarDeviceCode:    //放货点在第一个过道点(已完成)
                    return MotherCarMoves(task, RGVTaskdevice);
                case int Waddress when Waddress == RGVTaskdevice.MotherCardeputy:              //放货点在第二个过道点(已完成)
                    return MotherCarMovesinside(task, RGVTaskdevice);
                case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress:        //放货点在HCJ上(已完成)
                    return HCJMotherCarMovesinside(task, RGVTaskdevice);
                default: return null;
            }
        }
 
 
        //区域一判断母车是否到位,可立即放货
        private Dt_Task? MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);
            Dt_Task task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //获取到母车移动任务
            if (task == null)
            {
                GetStackerObject getStackerObject = GetDeviceAddress.GetChildDeviceCode(Muche.ChildPosiDeviceCode);
                if (getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)   //判断母车是否有货
                {
                    if (getStackerObject.RGVCurrentlocation == Muche.ZicheMotherinlaw)     //判断母车是否在过道点,
                    {
                        return _Task;
                    }
                    else
                    {
                        //判断母车是否有任务
                        Dt_Task _Task1 = _taskService.MothermacTask(Muche.ChildPosiDeviceCode);
                        if (task == null)
                        {
                            RGVMovetask(Muche.ZicheMotherinlaw, Muche.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                        }
                            
                    }
                }
            }
            return null;
        }
 
        /// <summary>
        /// 判断放第二个母车位置
        /// </summary>
        /// <param name="_Task"></param>
        /// <param name="aGVStation"></param>
        /// <returns></returns>
        private Dt_Task? MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
        {
 
            //判断外侧母车是否需要移动至堆垛机取货口
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);
            int muche1objet = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
 
            //判断内侧母车是否在放货点
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            int muche2objet = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            bool NoCargobool = GetDeviceAddress.Mucheywhaddres(Muche2.ChildPosiDeviceCode);
 
            //正常情况下,把信息反馈出去
            if (muche1objet == Muche.Motherinlaw && muche2objet == Muche2.ZicheMotherinlaw && NoCargobool)
            {
                return _Task;
            }
            //母车1不在取货口
            if (muche1objet != Muche.Motherinlaw)     //判断母车是否在过道点,
            {
                Dt_Task task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //获取到母车移动任务
                if (task == null)
                {
                    RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                }
            }
 
            //母车2不在过道站点
            if (muche2objet != Muche2.ZicheMotherinlaw)     //判断母车是否在过道点,
            {
                Dt_Task task = _taskService.MothermachinemovementTask2(Muche2.ChildPosiDeviceCode);   //获取到母车移动任务
                if (task == null)
                {
                    Dt_Task _Task1 = _taskService.MothermacTask(Muche.ChildPosiDeviceCode);
                    if (task == null)
                    {
                        RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                    }
                        
                }
            }
            return null;
        }
        /// <summary>
        /// 判断放在HCJ上面
        /// </summary>
        /// <param name="_Task"></param>
        /// <param name="aGVStation"></param>
        /// <returns></returns>
        private Dt_Task? HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
        {
            //先判断HCJ站台点是否有货,有任务
            if (GetDeviceAddress.HCJIsstock(_Task.NextAddress))
            {
                //判断内车子车是否在等待点
                AGVStation neiziche = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //内侧子车
                int neizichecurraddres = GetDeviceAddress.GetEquipmentlocation(neiziche.ChildPosiDeviceCode);
 
 
                Dt_Task task = _taskService.ViceChariotPickupTask2(neiziche.ChildPosiDeviceCode);   //获取到内侧子车取货任务
                if ((neizichecurraddres != neiziche.WaitmomentOne && neizichecurraddres != neiziche.WaitmomentTwo) || task != null)     //内侧子车不在两个缓存点
                {
                    return null;
                }
                AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
                int mucheaddre1 = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
                AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
                int mucheaddre2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
 
                if ((neizichecurraddres == neiziche.WaitmomentOne || neizichecurraddres == neiziche.WaitmomentTwo) && task == null && neizichecurraddres != neiziche.HCJStorageaddress && mucheaddre1 == Muche.Motherinlaw && mucheaddre2 == Muche2.Motherinlaw)
                {
                    return _Task;
                }
                //判断两个母车位置
                if (mucheaddre1 != Muche.Motherinlaw)     //判断母车是否在过道点,
                {
                    Dt_Task muche1task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //获取到母车移动任务
                    if (muche1task == null)
                    {
                        RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                    }
                }
                if (mucheaddre2 != Muche2.Motherinlaw)     //判断母车是否在过道点,
                {
                    Dt_Task muche2task = _taskService.MothermachinemovementTask2(Muche2.ChildPosiDeviceCode);   //获取到母车移动任务
                    if (muche2task == null)
                    {
                        RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                    }
                }
            }
            return null;
        }
        #endregion
 
        #region 母车移动任务
        public Dt_Task? MotherVehicleMovement(AGVStation RGVTaskdevice)
        {
            Dt_Task task = _taskService.MothermachinemovementTask(RGVTaskdevice.ChildPosiDeviceCode);
            if (task == null) return null;
 
            AGVStation GdZiche = _agvStationService.GetMotheaisle(RGVTaskdevice.ZicheMotherinlaw);
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(GdZiche.ChildPosiDeviceCode);
            if (GdZiche.WaitmomentOne == motherCarAddress || GdZiche.WaitmomentTwo == motherCarAddress)
            {
                return task;
            }
            return null;
        }
        #endregion
 
        #endregion
 
        #region 出库方法(可进行测试)
        public Dt_Task? OutboundEquipmentTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
        {
            return (RGVTaskdevice.Station_material, getStackerObject.RgvCraneStatusValue) switch
            {
                ((int)RGVEquipment.Mothertrailer, RgvEquipmentStatus.HasCargo)      //下发母车出来到过道上
                    => Mothertaskdistribution(RGVTaskdevice),//已完成   
 
                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.NoCargo)         //查找子车出来取货
                    => ChildPickupAddres(RGVTaskdevice, getStackerObject.RGVCurrentlocation),   //已完成
 
                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.HasCargo)
                    => Findshippingtask(RGVTaskdevice, getStackerObject.RGVCurrentlocation),    //子车取货后,进行放货(已完成)
 
                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.NoCargo)
                    => OutboundGateVehicle(RGVTaskdevice),              //出库口RGV取货(已完成)
 
                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.HasCargo)
                    => _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
                       RGVTaskdevice.HCJStorageaddress.ToString()),
 
                _ => null
            };
        }
 
        #region 下发母车任务,需要判断当前行小车在哪个位子(已完成)
 
        private Dt_Task? Mothertaskdistribution(AGVStation GdZiche)
        {
            // 提前检查无效的Area值
            if (GdZiche.Station_Area < 1 || GdZiche.Station_Area > 4)
                return null;
 
            //根据母车地址,获取当前行道的子车
            AGVStation ZicheinnerSide = _agvStationService.GetMotheaisle(GdZiche.ZicheMotherinlaw);
            int zichecurraddre = GetDeviceAddress.GetEquipmentlocation(ZicheinnerSide.ChildPosiDeviceCode);   //获取到子车实例
 
            if (zichecurraddre != ZicheinnerSide.WaitmomentOne && zichecurraddre != ZicheinnerSide.WaitmomentTwo) return null;
 
            //判断是哪个巷道的母车
            return GdZiche.Station_Area switch
            {
                4 => OutboundSideAisle4(zichecurraddre, ZicheinnerSide),    //在4巷道进行出库的任务(已完成)
                3 => OutboundSideAisle3(zichecurraddre, ZicheinnerSide),    //在3巷道进行出库的任务(已完成)
                2 => OutboundSideAisle2(ZicheinnerSide),                                   //在二巷道进行出库的任务(已完成)
                1 => _taskService.ObtainMuChetask(GdZiche.ZicheMotherinlaw.ToString()),   //根据母车子地址,查找是否有需要移动的任务(已完成)
                _ => null
            };
 
        }
 
        public Dt_Task? OutboundSideAisle1(AGVStation ZicheinnerSide)
        {
            //获取1巷道母车是否有任务
            Dt_Task Muche1Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCarDeviceCode.ToString());
            if (Muche1Task == null) return null;
 
            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
            if (zicheTASK != null) return null;
 
            return Muche1Task;
        }
 
        public Dt_Task? OutboundSideAisle2(AGVStation ZicheinnerSide)
        {
            //获取2巷道母车是否有任务
            Dt_Task Muche2Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCardeputy.ToString());
            if (Muche2Task == null) return null;
 
            //获取子车是否有任务
            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
            if (zicheTASK != null) return null;
 
            //获取2巷道子车是否有任务
            var muche1 = _agvStationService.GetMothervehicle(ZicheinnerSide.MotherCarDeviceCode);
            Dt_Task Muche1 = _taskService.GetChariotTaskBool(muche1.ChildPosiDeviceCode.ToString());
            if(Muche1!=null) return null;
 
            return Muche2Task;
        }
        public Dt_Task? OutboundSideAisle3(int curraddZiChe, AGVStation ZicheinnerSide)
        {
            //获取3巷道母车是否有任务
            Dt_Task Muche3Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCarDeviceCode.ToString());
            if (Muche3Task == null) return null;
 
            //判断子车是否有要取HCJ任务
            Dt_Task zicheTASK = _taskService.GetHCJTaskBool(ZicheinnerSide.ChildPosiDeviceCode, ZicheinnerSide.HCJStorageaddress);
            if (zicheTASK != null) return null;
 
            return Muche3Task;
        }
        public Dt_Task? OutboundSideAisle4(int curraddZiChe, AGVStation ZicheinnerSide)
        {
            //获取当前母车是否有任务
            Dt_Task Muche4Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCardeputy.ToString());
            if (Muche4Task == null) return null;
 
            //判断是否有需要取HCJ的任务
            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
            if (zicheTASK != null) return null;
 
            //判断3巷道是否有出库的任务
            var muche3 = _agvStationService.GetMothervehicle(ZicheinnerSide.MotherCarDeviceCode);
            Dt_Task muchetask = _taskService.OutMothermaTask(muche3.ChildPosiDeviceCode);
            if (muchetask != null) return null;
 
            return Muche4Task;
        }
 
        #endregion
 
        #region 判断已移动出来的母车,再判断小车位置(已完成)
        public Dt_Task? ChildPickupAddres(AGVStation GdZiche, int curraderr)
        {
            if (curraderr == GdZiche.WaitmomentOne || curraderr == GdZiche.WaitmomentTwo)
            {
                Dt_Task dtTasks = _taskService.ChildVehicleMission(GdZiche);
                if (dtTasks == null) return null;
                if (GdZiche.Station_Area == 5)
                {
                    if (dtTasks.CurrentAddress == GdZiche.MotherCardeputy.ToString())   //取货的点在2巷道,则子车无论在哪个等待点,都可以取货
                    {
                        return dtTasks;
                    }
                    else if (dtTasks.CurrentAddress == GdZiche.MotherCarDeviceCode.ToString())     //取1巷道的货
                    {
                        if (curraderr == GdZiche.WaitmomentOne)     //子车刚好在旁边,可立马取货
                        {
                            return dtTasks;
                        }
                        else if (curraderr == GdZiche.WaitmomentTwo)
                        {
                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
                            int muche2addres = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);  //获取2巷道母车实例
                            if (muche2addres == muchestation.Motherinlaw)
                            {
                                return dtTasks;
                            }
                        }
                    }
                }
                else if (GdZiche.Station_Area == 6)
                {
                    //HCJ站台没任务
                    if (dtTasks.CurrentAddress == GdZiche.MotherCardeputy.ToString())       //优先判断是否是最外面的任务
                    {
                        if (curraderr == GdZiche.WaitmomentTwo)
                        {
                            return dtTasks;
                        }
                        else
                        {
                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
                            int muche3x = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
                            if (muche3x == muchestation.Motherinlaw)
                            {
                                return dtTasks;
                            }
                        }
                    }
                    else if (dtTasks.CurrentAddress == GdZiche.MotherCarDeviceCode.ToString())    //该任务为取3巷道
                    {
                        if (curraderr == GdZiche.WaitmomentOne)
                        {
                            return dtTasks;
                        }
                        else if(curraderr == GdZiche.WaitmomentTwo)
                        {
                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
                            int muche4x = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
                            if (muche4x == muchestation.Motherinlaw)
                            {
                                return dtTasks;
                            }
                        }
 
                    }
                    else if (dtTasks.CurrentAddress == GdZiche.HCJStorageaddress.ToString())
                    {
                        //判断内侧子车的位置
                        AGVStation neiziche = _agvStationService.GetOutZicheDeep(GdZiche.HCJStorageaddress);    //内侧子车
                        int neizichecurraddres = GetDeviceAddress.GetEquipmentlocation(neiziche.ChildPosiDeviceCode);
                        if ((neiziche.WaitmomentOne == neizichecurraddres || neiziche.WaitmomentTwo == neizichecurraddres || neiziche.MotherCarDeviceCode == neizichecurraddres || neiziche.MotherCardeputy == neizichecurraddres) && neiziche.HCJStorageaddress != neizichecurraddres)
                        {
                            if (curraderr == GdZiche.WaitmomentTwo)
                            {
                                var mu1rgv = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
                                int mu1 = GetDeviceAddress.GetEquipmentlocation(mu1rgv.ChildPosiDeviceCode);
 
                                var mu2rgv = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
                                int mu2 = GetDeviceAddress.GetEquipmentlocation(mu2rgv.ChildPosiDeviceCode);
 
                                if (mu1 == mu1rgv.Motherinlaw && mu2 == mu2rgv.Motherinlaw)
                                {
                                    return dtTasks;
                                }
                            }
                            else if (curraderr == GdZiche.WaitmomentOne)
                            {
                                return dtTasks;
                            }
                        }
                    }
 
 
                }
 
            }
            return null;
        }
        #endregion
 
        #region 查找子车放货任务(已完成)
        public Dt_Task? Findshippingtask(AGVStation GdZiche, int curraderr)
        {
            Dt_Task task = _taskService.GetFinhuoTask(GdZiche.ChildPosiDeviceCode);
            if (task == null) return null;
            if (GetDeviceAddress.HCJIsstock(task.NextAddress))
            {
                if (GdZiche.Station_Area == 5)
                {
                    //需要判断外侧小车是否在HCJ上
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(GdZiche.HCJStorageaddress);
                    int waiziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    if ((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode) && waiziche != zichestation.HCJStorageaddress)
                    {
                        //判断当前位置
                        if (task.CurrentAddress == GdZiche.MotherCarDeviceCode.ToString())
                        {
                            var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
                            int muche2 = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
                            if (muche2 == muchestation.Motherinlaw)
                            {
                                return task;
                            }
                        }
                        else if (task.CurrentAddress == GdZiche.MotherCardeputy.ToString())
                        {
                            return task;
                        }
                    }
                }
                else if (GdZiche.Station_Area == 6)
                {
                    if (GdZiche.HCJStorageaddress == curraderr)
                    {
                        //判断3巷道母车
                        var muchestation = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
                        int mucboject3 = GetDeviceAddress.GetEquipmentlocation(muchestation.ChildPosiDeviceCode);
                        if (mucboject3 == muchestation.Motherinlaw)
                        {
                            //判断4巷道母车
                            var muchestation2 = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
                            int mucboject4 = GetDeviceAddress.GetEquipmentlocation(muchestation2.ChildPosiDeviceCode);
                            if (mucboject4 == muchestation2.Motherinlaw)
                            {
                                return task;
                            }
 
                        }
                    }
                    else if (GdZiche.MotherCarDeviceCode == curraderr)
                    {
                        //判断4巷道母车
                        var muchestation2 = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
                        int mucboject4 = GetDeviceAddress.GetEquipmentlocation(muchestation2.ChildPosiDeviceCode);
                        if (mucboject4 == muchestation2.Motherinlaw)
                        {
                            return task;
                        }
                    }
                    else if (GdZiche.MotherCardeputy == curraderr) return task;
                }
            }
            return null;
        }
        #endregion
 
        #region 出库口子车取货(已完成)
        public Dt_Task OutboundGateVehicle(AGVStation GdZiche)
        {
            //需要判断子车是否在HCJ上
            var zichestation = _agvStationService.OutGetZicheDeepHCJ(1131);
            int ziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
 
            if (ziche != GdZiche.HCJStorageaddress && (ziche == zichestation.HCJStorageaddress || ziche == zichestation.WaitmomentOne || ziche == zichestation.WaitmomentTwo || ziche == zichestation.MotherCardeputy || ziche == zichestation.MotherCarDeviceCode))
            {
                return _taskService.GetOutchachekouFinhuoTask(GdZiche.ChildPosiDeviceCode, GdZiche.HCJStorageaddress.ToString());
            }
            return null;
        }
        #endregion
 
        #endregion
 
        #region 出库小车移动任务下发(已完成)
        public void Returnposition(string DeviceCode, int RGVCurrentlocation, int RgvCraneStatusValue)
        {
            AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);
            if (GdZiche.Station_material == (int)RGVEquipment.Mothertrailer)
            {
                if (GdZiche.Motherinlaw == RGVCurrentlocation) return;
                if (RgvCraneStatusValue == (int)RgvEquipmentStatus.HasCargo) return;
 
                //母亲回堆垛机口任务,判断子车的位置是否在母车上
                var zichestation = _agvStationService.GetMotheaisle(GdZiche.ZicheMotherinlaw);
 
                //获取子车是否有任务来该位置取货
                Dt_Task Muche2Task = _taskService.OutPickupZiche(zichestation.ChildPosiDeviceCode.ToString());
                if (Muche2Task != null) return;
                GetStackerObject getStackerObject = GetDeviceAddress.GetChildDeviceCode(zichestation.ChildPosiDeviceCode);
 
                if (getStackerObject.StaclerkJobJobStatusValue != RGV_Rgvtaskstutas.Executing && getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic
                     && (getStackerObject.RGVCurrentlocation == zichestation.WaitmomentOne || getStackerObject.RGVCurrentlocation == zichestation.WaitmomentTwo || getStackerObject.RGVCurrentlocation==1171) && getStackerObject.RGVCurrentlocation != zichestation.ZicheMotherinlaw)
                {
                    RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
                }
            }
            else if (GdZiche.Station_material == (int)RGVEquipment.Corridorcar)
            {
                if (RgvCraneStatusValue == (int)RgvEquipmentStatus.HasCargo) return;
                if (GdZiche.Station_Area == 5)
                {
                    if (GdZiche.MotherCardeputy == RGVCurrentlocation || GdZiche.HCJStorageaddress == RGVCurrentlocation)
                    {
                        RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
                    }
                    else if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation)
                    {
                        RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
                    }
                }
                else
                {
                    if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation || GdZiche.HCJStorageaddress == RGVCurrentlocation)
                    {
                        RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
                    }
                    else if (GdZiche.MotherCardeputy == RGVCurrentlocation || RGVCurrentlocation == 1171)
                    {
                        RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
                    }
                }
            }
        }
        #endregion
 
        #region 入库小车移动任务下发(已完成)
        public void InReturnposition(string DeviceCode, int RGVCurrentlocation, int RgvCraneStatusValue)
        {
            AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);//获取到要移动的子车
            if (GdZiche.Station_material == (int)RGVEquipment.Corridorcar)
            {
                if (GdZiche.Station_Area == 5)
                {
                    Dt_Task task = _taskService.GetChariotTaskBool(GdZiche.ChildPosiDeviceCode);
                    if (task == null && RgvCraneStatusValue == (int)RgvEquipmentStatus.NoCargo)
                    {
                        if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation || GdZiche.HCJStorageaddress == RGVCurrentlocation)
                        {
                            RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
                        }
                        else if (GdZiche.MotherCardeputy == RGVCurrentlocation)
                        {
                            RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
                        }
                    }
                        
                }
                else
                {
                    Dt_Task task = _taskService.GetChariotTaskBool(GdZiche.ChildPosiDeviceCode);
                    if (task == null && RgvCraneStatusValue == (int)RgvEquipmentStatus.NoCargo)
                    {
                        if (GdZiche.HCJStorageaddress == RGVCurrentlocation)
                        {
                            //如果在2巷道的母车,则可以放子车来1号等待点,如果在HCJ则可以让子车去2号
                            RGVMovetask(GdZiche.WaitmomentTwo, GdZiche.ChildPosiDeviceCode);
                        }
                        else if (GdZiche.MotherCarDeviceCode == RGVCurrentlocation || GdZiche.MotherCardeputy == RGVCurrentlocation)
                        {
                            RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
                        }
                        else if (RGVCurrentlocation == 1021)
                        {
                            //加入判断,如果在1021站台,则需要判断1号巷道母车是否在堆垛机取货口
                            var zichestation = _agvStationService.GetMothervehicle(GdZiche.MotherCarDeviceCode);
                            int ziche = GetDeviceAddress.GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                            if (GetDeviceAddress.Mucheywhaddres(zichestation.ChildPosiDeviceCode) && (ziche == zichestation.ZicheMotherinlaw || ziche == zichestation.Motherinlaw))
                            {
                                RGVMovetask(GdZiche.WaitmomentOne, GdZiche.ChildPosiDeviceCode);
                            }
 
                        }
                    }
                }
            }
        }
        #endregion
 
        /// <summary>
        /// 子母车移动任务
        /// </summary>
        /// <param name="RGVAdders">目标地址</param>
        /// <param name="ChildPosiDeviceCode">设备编号</param>
        /// <returns></returns>
        private bool RGVMovetask(int RGVAdders, string ChildPosiDeviceCode)
        {
            RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(RGVAdders);
            bool sendFlag = SendCommand2(standardCommands, ChildPosiDeviceCode);
            return sendFlag;
        }
        /// <summary>
        /// 任务实体转换成命令Model
        /// </summary>
        /// <param name="task">任务实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public RgvCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
        {
            RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
 
            short locaticurr = task.TaskType switch
            {
                _ when task.TaskType == (int)TaskInboundTypeEnum.Inbound
                    => InRgvLocaaddres(task),
                _ when task.TaskType == (int)TaskOutboundTypeEnum.Outbound
                    => RgvLocaaddres(task),
                _ => (short)0
            };
            if (locaticurr == 0) return null;
 
            stackerCraneTaskCommand.RGV_RGVTasklocation = locaticurr;
            stackerCraneTaskCommand.RGV_RGVtasktype = (short)task.RGVTaskType;
            stackerCraneTaskCommand.RGV_Rgvtaskid = (short)task.TaskNum;
            stackerCraneTaskCommand.RGV_Lanjiantaskid = (short)task.TaskNum;
            return stackerCraneTaskCommand;
        }
 
        public short InRgvLocaaddres(Dt_Task dt_Task)
        {
            if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp) return short.Parse(dt_Task.CurrentAddress);
            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.Placing) return short.Parse(dt_Task.NextAddress);
            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && dt_Task.TaskState == (int)TaskInStatusEnum.RGV_InZicheReleaseFinish) return short.Parse(dt_Task.NextAddress);
            return 0;
        }
        public short RgvLocaaddres(Dt_Task dt_Task)
        {
            if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp) return short.Parse(dt_Task.CurrentAddress);
            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.Placing) return short.Parse(dt_Task.NextAddress);
            else if (dt_Task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && dt_Task.TaskState == (int)TaskOutStatusEnum.OutNew) return short.Parse(dt_Task.NextAddress);
            return 0;
        }
 
 
        /// <summary>
        /// 下发移动任务
        /// </summary>
        /// <param name="task">任务实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand(int RGVAddress)
        {
            RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
            stackerCraneTaskCommand.RGV_RGVTasklocation = (short)RGVAddress;
            stackerCraneTaskCommand.RGV_RGVtasktype = 3;
            stackerCraneTaskCommand.RGV_Rgvtaskid = 30001;          //rgv任务号
            stackerCraneTaskCommand.RGV_Lanjiantaskid = 30001;      //兰剑任务id
            return stackerCraneTaskCommand;
        }
        public bool SendCommand2(RgvCraneTaskCommand command, string DeviceCode)
        {
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetRGVDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
                int MCGStatus = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
 
 
                if (MCGStatus == 0)
                {
                    if (MCGStatus == (int)RGV_Rgvtaskstutas.Ready)
                    {
                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVTasklocationt, command.RGV_RGVTasklocation);
                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVtasktypet, command.RGV_RGVtasktype);
                        Commonstacker.SetValue(RgvCraneDBName.RGV_Rgvtaskidt, command.RGV_Rgvtaskid);
                        Commonstacker.SetValue(RgvCraneDBName.RGV_Lanjiantaskidt, command.RGV_Lanjiantaskid);
                        return true;
                    }
                }
                return false;
 
            }
            catch (Exception ex)
            {
                return false;
            }
        }
 
 
    }
}