1
huanghongfeng
2025-10-20 0e022ecccc0cccd486df4cd208658c332ddbdf3b
´úÂë¹ÜÀí/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs
@@ -12,6 +12,7 @@
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;
@@ -68,44 +69,51 @@
                {
                    GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
                    //读取设备完成信息
                    if (getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Completed && getStackerObject.CurrentRgvtaskid != 0)
                    if (getStackerObject.RGVInitializationValue == RGVInitialize.Initialized)
                    {
                        _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid,2);
                    }
                    if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
                        getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
                    {
                        //下发RGV任务之前,先读取一下安全门状态
                        //查找RGV进行下发任务
                        Dt_Task task = GetTask(speStackerCrane.DeviceCode,getStackerObject);
                        if (task != null)
                        //读取设备完成信息
                        if (getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.Completed || getStackerObject.StaclerkJobJobStatusValue == RGV_Rgvtaskstutas.AbnormalCompletion)
                        {
                            //调取写入RGV小车任务
                            RgvCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                            bool sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand);
                            if (sendFlag)
                            CommonStackerCrane_AGVTaskCompletedEventHandler(getStackerObject, speStackerCrane);
                        }
                        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)
                            {
                                //修改任务状态
                                _taskService.UpdateTaskStatusToNext(task);
                                //调取写入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);
                                }
                            }
                        }
                        else
                        {
                            if(speStackerCrane.DeviceCode=="RGV101" || speStackerCrane.DeviceCode == "RGV101")
                            {
                                //当没任务的时候,则进行移动
                                Returnposition(speStackerCrane.DeviceCode, getStackerObject.RGVCurrentlocation);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
@@ -115,6 +123,30 @@
            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)
            {
                //写入异常完成报警信息
                speStackerCrane.Communicator.Write<short>("DB101.36", 1);
            }
        }
        #endregion
        private Dt_Task? GetTask(string DeviceCode, GetStackerObject getStackerObject)
        {
            // æ ¹æ®è®¾å¤‡åç§°ï¼ŒèŽ·å–åˆ°è®¾å¤‡ç›¸å…³æ•°æ®
@@ -122,7 +154,7 @@
            return RGVTaskdevice.Station_tasktype switch
            {
                (int)RGVTasktype.Inbound => HandleInboundTask(RGVTaskdevice, getStackerObject),
                (int)RGVTasktype.Outbound => OutboundEquipmentTask(RGVTaskdevice, getStackerObject),
                (int)RGVTasktype.Outbound => OutboundEquipmentTask(RGVTaskdevice, getStackerObject),    //出库
                _ => null
            };
@@ -132,73 +164,195 @@
        #region å…¥åº“方法
        private Dt_Task? HandleInboundTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
        {
            if(RGVTaskdevice.Station_material== (int)RGVEquipment.InRGVForklift && getStackerObject.RgvCraneStatusValue== RgvEquipmentStatus.NoCargo)
            return (RGVTaskdevice.Station_material, getStackerObject.RgvCraneStatusValue) switch
            {
                return _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode, 1);
            }
            else if (RGVTaskdevice.Station_material == (int)RGVEquipment.InRGVForklift && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
            {
                return _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode, 2);
            }else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
            {
                return ZichePickUpAisle(RGVTaskdevice, getStackerObject);
            }else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
            {
                return GoodsPlacedCorridor(RGVTaskdevice, getStackerObject);
            }
            else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
            {
                return ZicheMobile(RGVTaskdevice, getStackerObject);
            }
            else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Mothertrailer && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
            {
                return MotherVehicleMovement(RGVTaskdevice);
            }
            else { return null; }
                ((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);
        #region è¿‡é“子车进行取货
            //判断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.GetInzicheTask(RGVTaskdevice.ChildPosiDeviceCode,1);
            if(dt_Task.CurrentAddress== getStackerObject.RGVCurrentlocation.ToString())
            Dt_Task dt_Task = _taskService.ViceChariotPickupTask(RGVTaskdevice.ChildPosiDeviceCode);
            if (dt_Task == null) return null;
            if (RGVTaskdevice.Station_Area == 6)    //外侧进取货,则需要判断子车当前位置
            {
                return dt_Task;
            }
            else
            {
                //如果不等于,则进行判断子车在哪个位置
                if (RGVTaskdevice.Station_Area == 1)
                if (getStackerObject.RGVCurrentlocation == RGVTaskdevice.WaitmomentOne)
                {
                    // æ ¹æ®å­è½¦ä½ç½®å¤„理不同情况
                    switch (getStackerObject.RGVCurrentlocation)
                    {
                        case int Waddress when Waddress == RGVTaskdevice.MotherCarDeviceCode:
                            return dt_Task;
                        case int Naddress when Naddress == RGVTaskdevice.MotherCardeputy:
                            return HandleMedialCase(dt_Task, RGVTaskdevice.MotherCarDeviceCode);
                        case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress:
                            return HandleMedialCase2(dt_Task, RGVTaskdevice);
                        default: return null;
                    }
                }
                else
                {
                    //取HCJ位的料判断
                    switch (getStackerObject.RGVCurrentlocation)
                    {
                        case int Waddress when Waddress == RGVTaskdevice.MotherCarDeviceCode:
                            return dt_Task;
                        case int Naddress when Naddress == RGVTaskdevice.MotherCardeputy:
                            return HandleMedialCase(dt_Task, RGVTaskdevice.MotherCarDeviceCode);
                        default: return null;
                    }
                }
                    //还需要判断入库口叉车是否收回叉车了
                    //在等待点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>
        /// åˆ¤æ–­å¤–侧母车是否在入口口
@@ -246,17 +400,18 @@
        #endregion
        #region è¿‡é“子车进行放货
        public Dt_Task? GoodsPlacedCorridor(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
        public Dt_Task? GoodsPlacedCorridor(AGVStation RGVTaskdevice)
        {
            Dt_Task task = _taskService.GetInzicheTask(RGVTaskdevice.ChildPosiDeviceCode, 2);
            int nexaddres = int.Parse(task.NextAddress);
            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:    //放货点在第一个过道点
                case int Whcjaddress when Whcjaddress == RGVTaskdevice.MotherCarDeviceCode:    //放货点在第一个过道点(已完成)
                    return MotherCarMoves(task, RGVTaskdevice);
                case int Waddress when Waddress == RGVTaskdevice.MotherCardeputy:              //放货点在第二个过道点
                case int Waddress when Waddress == RGVTaskdevice.MotherCardeputy:              //放货点在第二个过道点(已完成)
                    return MotherCarMovesinside(task, RGVTaskdevice);
                case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress:        //放货点在HCJ上
                case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress:        //放货点在HCJ上(已完成)
                    return HCJMotherCarMovesinside(task, RGVTaskdevice);
                default: return null;
            }
@@ -266,12 +421,23 @@
        //区域一判断母车是否到位,可立即放货
        private Dt_Task? MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.ZicheMotherinlaw);
            int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
            if (motherCarAddress == Muche.ZicheMotherinlaw) return _Task;
            if(motherCarAddress!=0) RGVMovetask(Muche.ZicheMotherinlaw, aGVStation.ChildPosiDeviceCode);
            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
                    {
                        RGVMovetask(Muche.ZicheMotherinlaw, Muche.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                    }
                }
            }
            return null;
        }
@@ -283,22 +449,40 @@
        /// <returns></returns>
        private Dt_Task? MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(Muche2.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw && motherCarAddress != 0)
            //判断外侧母车是否需要移动至堆垛机取货口
            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)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
                return _Task;
            }
            if (motherCarAddress2 != Muche2.ZicheMotherinlaw && motherCarAddress2 != 0)
            //母车1不在取货口
            if (muche1objet != Muche.Motherinlaw)     //判断母车是否在过道点,
            {
                RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);
                Dt_Task task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //获取到母车移动任务
                if (task == null)
                {
                    RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                }
            }
            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.ZicheMotherinlaw) return _Task;
            // æ¯è½¦å·²åœ¨æ­£ç¡®ä½ç½®
            //母车2不在过道站点
            if (muche2objet != Muche2.ZicheMotherinlaw)     //判断母车是否在过道点,
            {
                Dt_Task task = _taskService.MothermachinemovementTask2(Muche2.ChildPosiDeviceCode);   //获取到母车移动任务
                if (task == null)
                {
                    RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                }
            }
            return null;
        }
        /// <summary>
@@ -309,121 +493,94 @@
        /// <returns></returns>
        private Dt_Task? HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            AGVStation Ziche3 = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //内侧子车
            //先判断HCJ站台点是否有货,有任务
            if (GetDeviceAddress.HCJIsstock(_Task.NextAddress))
            {
                //判断内车子车是否在等待点
                AGVStation neiziche = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //内侧子车
                int neizichecurraddres = GetDeviceAddress.GetEquipmentlocation(neiziche.ChildPosiDeviceCode);
            int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(Muche2.ChildPosiDeviceCode);
            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentInMuche(Ziche3.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw && motherCarAddress != 0)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.Motherinlaw && motherCarAddress2 != 0)
            {
                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
            }
            if (ZiCarAddress3 == Ziche3.HCJStorageaddress && ZiCarAddress3!=0)
            {
                //判断目标站台是入库到几号堆垛机
                if (_Task.TargetAddress == "3")     //入库至3号堆垛机
                Dt_Task task = _taskService.ViceChariotPickupTask2(neiziche.ChildPosiDeviceCode);   //获取到内侧子车取货任务
                if ((neizichecurraddres != neiziche.WaitmomentOne && neizichecurraddres != neiziche.WaitmomentTwo) || task != null)     //内侧子车不在两个缓存点
                {
                    //判断外侧母车位置(2区域)
                    AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode);  //外侧母车
                    int motNCarAddress = GetDeviceAddress.GetEquipmentInMuche(MucheN.ChildPosiDeviceCode); //获取到母车当前位置
                    if (motNCarAddress!=0)
                    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 && mucheaddre1 == Muche.Motherinlaw && mucheaddre2 == Muche2.Motherinlaw)
                {
                    return _Task;
                }
                //判断两个母车位置
                if (mucheaddre1 != Muche.Motherinlaw)     //判断母车是否在过道点,
                {
                    Dt_Task muche1task = _taskService.MothermachinemovementTask2(Muche.ChildPosiDeviceCode);   //获取到母车移动任务
                    if (muche1task == null)
                    {
                        if (MucheN.ZicheMotherinlaw == motNCarAddress)
                        {
                            RGVMovetask(Ziche3.MotherCarDeviceCode, Ziche3.ChildPosiDeviceCode);
                        }
                        else
                        {
                            RGVMovetask(MucheN.ZicheMotherinlaw, MucheN.ChildPosiDeviceCode);
                        }
                        RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                    }
                }
                else if (_Task.TargetAddress == "4")    //入库至4号堆垛机
                if (mucheaddre2 != Muche2.Motherinlaw)     //判断母车是否在过道点,
                {
                    //判断外侧母车位置(2区域)
                    AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode);  //外侧母车
                    int motNCarAddress = GetDeviceAddress.GetEquipmentInMuche(MucheN.ChildPosiDeviceCode); //获取到母车当前位置
                    if (MucheN.Motherinlaw != motNCarAddress && motNCarAddress!=0)
                    Dt_Task muche2task = _taskService.MothermachinemovementTask2(Muche2.ChildPosiDeviceCode);   //获取到母车移动任务
                    if (muche2task == null)
                    {
                        RGVMovetask(MucheN.Motherinlaw, MucheN.ChildPosiDeviceCode);
                    }
                    AGVStation MucheN2 = _agvStationService.GetMothervehicle(Ziche3.MotherCardeputy);  //外侧母车
                    int motNCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(MucheN2.ChildPosiDeviceCode); //获取到母车当前位置
                    if (MucheN2.ZicheMotherinlaw != motNCarAddress2 && motNCarAddress2!=0)
                    {
                        RGVMovetask(MucheN2.ZicheMotherinlaw, MucheN2.ChildPosiDeviceCode);
                    }
                    if (MucheN.Motherinlaw == motNCarAddress && MucheN2.ZicheMotherinlaw == motNCarAddress2)
                    {
                        RGVMovetask(Ziche3.MotherCardeputy, Ziche3.ChildPosiDeviceCode);
                        RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);  //如果没有任务,则可以进行移动出来
                    }
                }
            }
            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw && ZiCarAddress3 != Ziche3.HCJStorageaddress) return _Task;
            // æ¯è½¦å·²åœ¨æ­£ç¡®ä½ç½®
            return null;
        }
        #endregion
        #region å­è½¦ç§»åŠ¨ä»»åŠ¡(后续可能需要优化一下)
        public Dt_Task? ZicheMobile(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
        {
            Dt_Task task = _taskService.GetInzicheTaskMobile(RGVTaskdevice.ChildPosiDeviceCode, 1);
            return task;
        }
        #endregion
        #region æ¯è½¦ç§»åŠ¨ä»»åŠ¡
        public Dt_Task? MotherVehicleMovement(AGVStation RGVTaskdevice)
        {
            Dt_Task task = _taskService.GetInzicheTaskMobile(RGVTaskdevice.ChildPosiDeviceCode, 2);
            int curradder = int.Parse(task.CurrentAddress);
            AGVStation GdZiche = _agvStationService.GetMotheaisle(curradder);
            int motherCarAddress = GetDeviceAddress.GetEquipmentInformation(GdZiche.ChildPosiDeviceCode);
            if (motherCarAddress != curradder && motherCarAddress!=0) return task;
            RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
            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 å‡ºåº“方法
        #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.Mothertrailer, RgvEquipmentStatus.HasCargo)      //下发母车出来到过道上
                    => Mothertaskdistribution(RGVTaskdevice),//已完成
                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.NoCargo)
                    => ChildPickupAddres(RGVTaskdevice),
                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.NoCargo)         //查找子车出来取货
                    => ChildPickupAddres(RGVTaskdevice, getStackerObject.RGVCurrentlocation),   //已完成
                ((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.HasCargo)
                    => Findshippingtask(RGVTaskdevice),
                    => Findshippingtask(RGVTaskdevice, getStackerObject.RGVCurrentlocation),    //子车取货后,进行放货(已完成)
                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.NoCargo)
                    => _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
                       RGVTaskdevice.HCJStorageaddress.ToString(), 1),
                    => OutboundGateVehicle(RGVTaskdevice),              //出库口RGV取货(已完成)
                ((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.HasCargo)
                    => _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
                       RGVTaskdevice.HCJStorageaddress.ToString(), 2),
                       RGVTaskdevice.HCJStorageaddress.ToString()),
                _ => null
            };
        }
        #region ä¸‹å‘母车任务,需要判断当前行小车在哪个位子
        #region ä¸‹å‘母车任务,需要判断当前行小车在哪个位子(已完成)
        private Dt_Task? Mothertaskdistribution(AGVStation GdZiche)
        {
@@ -431,171 +588,375 @@
            if (GdZiche.Station_Area < 1 || GdZiche.Station_Area > 4)
                return null;
            //根据母车地址,获取当前行道的子车
            AGVStation ZicheinnerSide = _agvStationService.GetMotheaisle(GdZiche.ZicheMotherinlaw);
            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentInformation(ZicheinnerSide.ChildPosiDeviceCode);
            int zichecurraddre = GetDeviceAddress.GetEquipmentlocation(ZicheinnerSide.ChildPosiDeviceCode);   //获取到子车实例
            // ä½¿ç”¨switch语句提高可读性
            if (zichecurraddre != ZicheinnerSide.WaitmomentOne && zichecurraddre != ZicheinnerSide.WaitmomentTwo) return null;
            //判断是哪个巷道的母车
            return GdZiche.Station_Area switch
            {
                4 when ZiCarAddress3 != GdZiche.ZicheMotherinlaw
                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
                3 when ZiCarAddress3 == ZicheinnerSide.HCJStorageaddress
                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
                2 when ZiCarAddress3 != GdZiche.MotherCardeputy && ZiCarAddress3 != GdZiche.HCJStorageaddress
                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
                1 when ZiCarAddress3 == ZicheinnerSide.HCJStorageaddress
                    => _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
                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;
            return Muche2Task;
        }
        public Dt_Task? OutboundSideAisle3(int curraddZiChe, AGVStation ZicheinnerSide)
        {
            //获取3巷道母车是否有任务
            Dt_Task Muche3Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCarDeviceCode.ToString());
            if (Muche3Task == null) return null;
            //判断子车是否有有需要取货的任务
            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
            if (zicheTASK != null) return null;
            if (curraddZiChe == ZicheinnerSide.WaitmomentTwo || curraddZiChe == ZicheinnerSide.WaitmomentOne)
            {
                return Muche3Task;
            }
            return null;
        }
        public Dt_Task? OutboundSideAisle4(int curraddZiChe, AGVStation ZicheinnerSide)
        {
            //获取当前母车是否有任务
            Dt_Task Muche4Task = _taskService.ObtainMuChetask(ZicheinnerSide.MotherCardeputy.ToString());
            if (Muche4Task == null) return null;
            Dt_Task zicheTASK = _taskService.GetChariotTaskBool(ZicheinnerSide.ChildPosiDeviceCode);
            if (zicheTASK != null) return null;
            if (curraddZiChe == ZicheinnerSide.WaitmomentOne)
            {
            }
            if ( || curraddZiChe == ZicheinnerSide.WaitmomentTwo)
            {
                return Muche4Task;
            }
            return null;
        }
        #endregion
        #region åˆ¤æ–­å·²ç§»åŠ¨å‡ºæ¥çš„æ¯è½¦ï¼Œå†åˆ¤æ–­å°è½¦ä½ç½®
        public Dt_Task? ChildPickupAddres(AGVStation GdZiche)
        #region åˆ¤æ–­å·²ç§»åŠ¨å‡ºæ¥çš„æ¯è½¦ï¼Œå†åˆ¤æ–­å°è½¦ä½ç½®(已完成)
        public Dt_Task? ChildPickupAddres(AGVStation GdZiche, int curraderr)
        {
            if (GdZiche.Station_Area == 5)
                return _taskService.ChildVehicleMission(GdZiche);
            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;
                            }
                        }
            var task = _taskService.ChildVehicleMission(GdZiche);
                    }
                    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);
            // å¿«é€Ÿè¿”回条件检查
            if (task.CurrentAddress != GdZiche.HCJStorageaddress.ToString())
                return task;
                                var mu2rgv = _agvStationService.GetMothervehicle(GdZiche.MotherCardeputy);
                                int mu2 = GetDeviceAddress.GetEquipmentlocation(mu2rgv.ChildPosiDeviceCode);
            var innerStation = _agvStationService.GetZicheDeep(GdZiche.HCJStorageaddress);
            if (GetDeviceAddress.GetEquipmentInformation(innerStation.ChildPosiDeviceCode) != innerStation.HCJStorageaddress)
                return task;
                                if (mu1 == mu1rgv.Motherinlaw && mu2 == mu2rgv.Motherinlaw)
                                {
                                    return dtTasks;
                                }
                            }
                            else if (curraderr == GdZiche.WaitmomentOne)
                            {
                                return dtTasks;
                            }
                        }
                    }
            var motherStation = _agvStationService.GetMothervehicle(innerStation.MotherCarDeviceCode);
            if (GetDeviceAddress.ReturnCurrentStatus(motherStation.ChildPosiDeviceCode))
                RGVMovetask(innerStation.MotherCarDeviceCode, innerStation.ChildPosiDeviceCode);
                }
            }
            return null;
        }
        #endregion
        #region æŸ¥æ‰¾å­è½¦æ”¾è´§ä»»åŠ¡
        public Dt_Task? Findshippingtask(AGVStation GdZiche)
        #region æŸ¥æ‰¾å­è½¦æ”¾è´§ä»»åŠ¡(已完成)
        public Dt_Task? Findshippingtask(AGVStation GdZiche, int curraderr)
        {
            Dt_Task task = _taskService.GetFinhuoTask(GdZiche.ChildPosiDeviceCode);
            if (GetDeviceAddress.HCJIsstock(task.NextAddress)) return task;
            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)
        #region å‡ºåº“小车移动任务下发(已完成)
        public void Returnposition(string DeviceCode, int RGVCurrentlocation, int RgvCraneStatusValue)
        {
            int HCJGoodsplatform = 1170;    //定义的放货站台
                                            //判断母车是否需要进行移动
            AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);
            if (GdZiche.Station_Area == 1)
            if (GdZiche.Station_material == (int)RGVEquipment.Mothertrailer)
            {
                switch (RGVCurrentlocation)
                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 != zichestation.ZicheMotherinlaw)
                {
                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //在第一个母车上
                        RGVMovetask(HCJGoodsplatform, GdZiche.ChildPosiDeviceCode);
                        break;
                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //在第二个母车上
                        OutNMotherCar(GdZiche.MotherCarDeviceCode);
                        break;
                    case int HCJaddress when HCJaddress == GdZiche.HCJStorageaddress:        //在HCJ站台上
                        OutHCJMotherCar(GdZiche);
                        break;
                    default: break;
                    RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
                }
            }
            else
            else if (GdZiche.Station_material == (int)RGVEquipment.Corridorcar)
            {
                switch (RGVCurrentlocation)
                if (RgvCraneStatusValue == (int)RgvEquipmentStatus.HasCargo) return;
                if (GdZiche.Station_Area == 5)
                {
                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //在第一个母车上,需要判断外侧子车是否在HCJ上
                        OutinnerSideNMotherCar(GdZiche);
                        break;
                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //在第二个母车上,需要判断子车与外侧母车是否在过道上
                        OutinnerSideMotherCar(GdZiche);
                        break;
                    default: break;
                    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 å¤–侧小车回归到起始点位
        /// <summary>
        /// åˆ¤æ–­æ”¾ç¬¬äºŒä¸ªæ¯è½¦ä½ç½®
        /// </summary>
        /// <param name="_Task"></param>
        /// <param name="aGVStation"></param>
        /// <returns></returns>
        private void OutNMotherCar(int MotherCarDeviceCode)
        #region å…¥åº“小车移动任务下发(已完成)
        public void InReturnposition(string DeviceCode, int RGVCurrentlocation, int RgvCraneStatusValue)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(MotherCarDeviceCode);  //外侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            if (motherCarAddress != Muche.Motherinlaw)
            AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);//获取到要移动的子车
            if (GdZiche.Station_material == (int)RGVEquipment.Corridorcar)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
        }
        private void OutHCJMotherCar(AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.Motherinlaw)
            {
                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
                if (GdZiche.Station_Area == 5)
                {
                    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
        #region å¤–侧小车回归到起始点位
        /// <summary>
        /// åœ¨ç¬¬ä¸€ä¸ªä½ç½®ï¼Œåˆ™åˆ¤æ–­å¤–侧子车是否在HCJ站台下面
        /// </summary>
        /// <param name="_Task"></param>
        /// <param name="aGVStation"></param>
        /// <returns></returns>
        private void OutinnerSideNMotherCar(AGVStation aGVStation)
        {
            AGVStation Ziche3 = _agvStationService.GetZicheOuterSide(aGVStation.HCJStorageaddress);    //外侧子车
            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentlocation(Ziche3.ChildPosiDeviceCode);
            if (ZiCarAddress3 == Ziche3.HCJStorageaddress)
            {
                OutHCJMotherCar(Ziche3);
            }
            else
            {
                RGVMovetask(aGVStation.HCJStorageaddress, aGVStation.ChildPosiDeviceCode);
            }
        }
        private void OutinnerSideMotherCar(AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            OutinnerSideNMotherCar(aGVStation);
        }
        #endregion
        #endregion
        /// <summary>
        /// å­æ¯è½¦ç§»åŠ¨ä»»åŠ¡
@@ -618,20 +979,37 @@
        public RgvCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
        {
            RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
            short locaticurr = task.RGVTaskType switch
            short locaticurr = task.TaskType switch
            {
                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp ||
                       (task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType != (int)TaskInStatusEnum.RGV_InZichemoveFinish)
                    => short.Parse(task.CurrentAddress),
                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.Placing || (task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType== (int)TaskInStatusEnum.RGV_InZichemoveFinish)
                    => short.Parse(task.NextAddress),
                _ 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;
        }
@@ -646,8 +1024,8 @@
            RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
            stackerCraneTaskCommand.RGV_RGVTasklocation = (short)RGVAddress;
            stackerCraneTaskCommand.RGV_RGVtasktype = 3;
            stackerCraneTaskCommand.RGV_Rgvtaskid = 999;          //rgv任务号
            stackerCraneTaskCommand.RGV_Lanjiantaskid = 999;      //兰剑任务id
            stackerCraneTaskCommand.RGV_Rgvtaskid = 30001;          //rgv任务号
            stackerCraneTaskCommand.RGV_Lanjiantaskid = 30001;      //兰剑任务id
            return stackerCraneTaskCommand;
        }
        public bool SendCommand2(RgvCraneTaskCommand command, string DeviceCode)
@@ -661,14 +1039,14 @@
                int MCGStatus = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (Commonstacker.IsConnected)
                if (MCGStatus == 0)
                {
                    if (MCGStatus == (int)RgvJobCraneStatus.Ready)
                    if (MCGStatus == (int)RGV_Rgvtaskstutas.Ready)
                    {
                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVTasklocation, command.RGV_RGVTasklocation);
                        Commonstacker.SetValue(RgvCraneDBName.RGV_RGVtasktype, command.RGV_RGVtasktype);
                        Commonstacker.SetValue(RgvCraneDBName.RGV_Rgvtaskid, command.RGV_Rgvtaskid);
                        Commonstacker.SetValue(RgvCraneDBName.RGV_Lanjiantaskid, command.RGV_Lanjiantaskid);
                        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;
                    }
                }
@@ -680,5 +1058,7 @@
                return false;
            }
        }
    }
}