1
HuBingJie
7 天以前 5da3a276b7847187a7c155ee069d3cd4c9e58074
´úÂë¹ÜÀí/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs
@@ -1,4 +1,4 @@
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
/*----------------------------------------------------------------
 * å‘½åç©ºé—´ï¼šWIDESEAWCS_TaskInfoService
 * åˆ›å»ºè€…:胡童庆
@@ -25,6 +25,7 @@
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz.Util;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -40,7 +41,9 @@
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEA_Common.Log;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.Enum;
@@ -58,9 +61,10 @@
{
    public class RgvoperainformService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvoperainformService
    {
        private readonly IAgvStationService _gvStationService;
        private readonly IAgvStationService _agvStationService;
        private readonly IServiceProvider _serviceProvider;
        private static bool _isMonitoring = false;
        private readonly IRepository<DeviceAlarmLog> _deviceAlarmLog;
        //private static CancellationTokenSource _cancellationTokenSource;
        // åœ¨ç±»çº§åˆ«æ·»åŠ ç‹¬ç«‹çš„ç›‘æŽ§çŠ¶æ€
@@ -74,10 +78,11 @@
        private CancellationTokenSource _outboundCancellationTokenSource;
        private CancellationTokenSource _inboundCancellationTokenSource;
        private CancellationTokenSource _safetyDoorCancellationTokenSource;
        public RgvoperainformService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, IServiceProvider serviceProvider) : base(BaseDal)
        public RgvoperainformService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, IServiceProvider serviceProvider, IRepository<DeviceAlarmLog> deviceAlarmLog) : base(BaseDal)
        {
            _gvStationService = agvStationService;
            _agvStationService = agvStationService;
            _serviceProvider = serviceProvider;
            _deviceAlarmLog = deviceAlarmLog;
        }
@@ -659,7 +664,7 @@
            int zhi = 1002011;
            try
            {
            switch (operationType)
            {
                case "cs":          //初始化
@@ -693,14 +698,39 @@
                    DeviceProParamName = "RGV_Risingsignalplace";
                    DeviceProParamType = "DeviceCommand";
                    zhi = parameter;
                    break;
                case "xj":          //下降
                    DeviceProDTO? RGV_Resetoperationss1 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //上升
                    RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationss1.DeviceProAddress, (short)zhi);
                    //DeviceProDTO? RGV_Resetoperationss2 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Risingsignalplace", "ReadDeviceCommand");        //上升到位信号
                    //    int resss = 0;
                    //    while (resss == 0)
                    //    {
                    //        Thread.Sleep(2000);
                    //        resss = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperationss2.DeviceProAddress);
                    //    }
                    //    DeviceProDTO? RGV_Resetoperationss3 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //上升
                    //    RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationss3.DeviceProAddress, 0);
                        return webResponse.OK();
                    case "xj":          //下降
                    DeviceProParamName = "RGV_Descentsignal";
                    DeviceProParamType = "DeviceCommand";
                    zhi = parameter;
                    break;
                        DeviceProDTO? RGV_Resetoperationxj1 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //下降
                        RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationxj1.DeviceProAddress, (short)zhi);
                        //DeviceProDTO? RGV_Resetoperationxj2 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Descentsignal", "ReadDeviceCommand");        //下降到位信号
                        //int resxj = 0;
                        //while (resxj == 0)
                        //{
                        //    Thread.Sleep(2000);
                        //    resxj = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperationxj2.DeviceProAddress);
                        //}
                        //DeviceProDTO? RGV_Resetoperationxj3 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //上升
                        //RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationxj3.DeviceProAddress, 0);
                        return webResponse.OK();
                case "dz":          //地址
                    DeviceProParamName = "RGV_RGVTasklocationt";
                        if (!YiDongPD(Commonstacker, parameter)) { return webResponse.Error("目标地址被占用或条件不满足,禁止移动"); }
                        DeviceProParamName = "RGV_RGVTasklocationt";
                    DeviceProParamType = "DeviceCommand";
                    zhi = parameter;
                        //获取实例
@@ -753,6 +783,657 @@
                return webResponse.Error("设备操作失败");
            }
        }
    /// <summary>
    /// 1、判断子车区域
    /// 2、判断子车当前位置
    /// 3、判断子车要去的位置
    /// 4、根据子车要去的为获取母车位置
    ///
    /// </summary>
    /// <param name="device">要移动的设备</param>
    /// <param name="parameter">要去的目标地址</param>
    /// <returns></returns>
        private bool YiDongPD(SpeStackerCrane Commonstacker, int parameter)
        {
            //入库设备
            List<string> InDevices = new List<string> {  "RGV104", "RGV107" };
            //出库设备
            List<string>  OutDevices = new List<string> {"RGV116", "RGV111"};
            Dictionary<int, string> HCJ = new Dictionary<int, string>
        {
            { 1061, "HCJ106" },
            { 1021, "HCJ102" },
            { 1131, "HCJ113" },
            { 1171, "HCJ117" },
        };
            AGVStation RGVTaskdevice = _agvStationService.Corridorequipment(Commonstacker.DeviceCode);   //根据设备获取到内容
            //根据子车获取到母车设备
            // æ ¹æ®å­è½¦èŽ·å–åˆ°æ¯è½¦è®¾å¤‡
            AGVStation Mu1 = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
            AGVStation Mu2 = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCardeputy);
            // èŽ·å–å­è½¦ä½ç½®
            int zhicheWZ = GetzicheWZ(Commonstacker, Commonstacker.DeviceCode);
            // ç»Ÿä¸€ç›®æ ‡å ç”¨æ£€æŸ¥ï¼ˆæ‰«æå…¶å®ƒ RGV æ˜¯å¦åœ¨åŒä¸€ç›®æ ‡åœ°å€ï¼‰
            bool IsAddressOccupied(int addr)
            {
                var allCodes = InDevices.Concat(OutDevices).Where(code => code != Commonstacker.DeviceCode).ToList();
                foreach (var code in allCodes)
                {
                    var dev = Storage.Devices.FirstOrDefault(x => x.DeviceCode == code) as SpeStackerCrane;
                    if (dev == null) continue;
                    try
                    {
                        DeviceProDTO? locDto = RgvOperationService.GetRGVDeviceProDTO(dev, code, "RGVCurrentlocation", "RGVCurrentlocation");
                        if (locDto == null) continue;
                        int loc = RgvOperationService.GetLine(dev, locDto.DeviceProAddress);
                        if (loc == addr) return true; // ç›®æ ‡è¢«å ç”¨
                    }
                    catch
                    {
                        // è¯»å–异常不当作占用,避免误拒
                    }
                }
                return false;
            }
            // ç›®æ ‡è¢«å…¶ä»– RGV å ç”¨åˆ™ç¦æ­¢
            if (IsAddressOccupied(parameter)) return false;
            if (RGVTaskdevice.Station_Area == 6) // å¤–ä¾§
            {
                if (zhicheWZ == RGVTaskdevice.WaitmomentOne) // ç­‰å¾…点1
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw) //母1
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw) // æ¯2
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && mu2 != Mu2.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu2.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }else if(parameter == 1021 || parameter == 1171)
                    {
                        if (RGVTaskdevice.ChildPosiDeviceCode == "RGV116" && Mucheywhaddres("HCJ102"))
                        {
                            return true;
                        }
                        string hcj = HCJ[parameter];
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else if (zhicheWZ == RGVTaskdevice.WaitmomentTwo) // ç­‰å¾…点2
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu2.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == 1021 || parameter == 1171)
                    {
                        string hcj = HCJ[parameter];
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            else if (RGVTaskdevice.Station_Area == 5) // å†…ä¾§
            {
                if (zhicheWZ == RGVTaskdevice.WaitmomentOne) // ç­‰å¾…点1
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw) //母1
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw) // æ¯2
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        if (Mucheywhaddres(hcj))
                        {
                            return true;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else if (zhicheWZ == RGVTaskdevice.WaitmomentTwo) // ç­‰å¾…点2
                {
                    // åˆ¤æ–­å¤–侧小车是否在 HCJ ä¸Š
                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
                    //判断传进来设备是否是入库
                    if (InDevices.Contains(Commonstacker.DeviceCode))
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
                        {
                            return false;
                        }
                    }
                    if (parameter == Mu1.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == Mu2.ZicheMotherinlaw)
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
                    {
                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode)&&Mucheywhaddres(hcj))//判断是否有货
                        {
                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        int taraddress = parameter;
                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//判断是否有货
                        {
                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            // é»˜è®¤ï¼šæœªè¢«æ‹¦æˆªä¸”目标未占用 -> æ”¾è¡Œ
            return true;
        }
        /// <summary>
        /// ä¼ å…¥è®¾å¤‡ï¼Œè¿”回当前设备信息
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static int GetEquipmentInformation(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null)
            {
                Console.WriteLine($"读取到设备为空,设备编号:{ChildPosiDeviceCode},003");
                return 0;
            }
            DeviceProDTO? deviceProDTOGZMS = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RgvCraneAutoStatus" && x.DeviceProParamType == "RgvCraneAutoStatus");
            int GZMS = RGVGetLine(speStackerCrane, deviceProDTOGZMS.DeviceProAddress);
            DeviceProDTO? deviceProDTORWZT = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGV_Rgvtaskstutas" && x.DeviceProParamType == "RGV_Rgvtaskstutas");
            int RWZT = RGVGetLine(speStackerCrane, deviceProDTORWZT.DeviceProAddress);
            DeviceProDTO? deviceProDTOBJGC = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVStepprocess" && x.DeviceProParamType == "RGVStepprocess");
            int BJGC = RGVGetLine(speStackerCrane, deviceProDTOBJGC.DeviceProAddress);
            DeviceProDTO? deviceProDTOWZ = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
            int WZ = RGVGetLine(speStackerCrane, deviceProDTOWZ.DeviceProAddress);
            if (GZMS == 1 && RWZT == 0 && BJGC == 0)
            {
                return WZ;
            }
            else
            {
                return 0;
            }
        }
        public static bool Mucheywhaddres(string DeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceCode && x.DeviceProParamName == "RgvEquipmentStatus" && x.DeviceProParamType == "RgvEquipmentStatus");
            int MCGStatus = RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
            if (MCGStatus == (int)RgvEquipmentStatus.NoCargo)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// RGV设备状态
        /// </summary>
        public enum RgvEquipmentStatus
        {
            /// <summary>
            /// æ— è´§
            /// </summary>
            [Description("无货")]
            NoCargo,
            /// <summary>
            /// æœ‰è´§
            /// </summary>
            [Description("有货")]
            HasCargo,
            /// <summary>
            /// æœªçŸ¥
            /// </summary>
            [Description("未知")]
            Unkonw = 6
        }
        /// <summary>
        /// ä¼ å…¥è®¾å¤‡ï¼ŒèŽ·å–å½“å‰ä½ç½®ä½ç½®
        /// </summary>
        /// <param name="ChildPosiDeviceCode">设备</param>
        /// <returns></returns>
        public static int GetEquipmentlocation(string ChildPosiDeviceCode)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
            if (speStackerCrane == null) return 0;
            DeviceProDTO? deviceProDTO = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
            int MCGStatus = RGVGetLine(speStackerCrane, deviceProDTO.DeviceProAddress);
            return MCGStatus;
        }
        public static int RGVGetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
        {
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
        /// <summary>
        /// èŽ·å–åˆ°å­è½¦ä½ç½®
        /// </summary>
        /// <param name="commonstacker"></param>
        /// <param name="deviceCode"></param>
        /// <returns></returns>
        private int GetzicheWZ(SpeStackerCrane commonstacker, string deviceCode)
        {
            DeviceProDTO? RGVCurrentlocation = RgvOperationService.GetRGVDeviceProDTO(commonstacker, commonstacker.DeviceCode, "RGVCurrentlocation", "RGVCurrentlocation");
            return RgvOperationService.GetLine(commonstacker, RGVCurrentlocation.DeviceProAddress);
        }
@@ -838,6 +1519,170 @@
                return webResponse.Error("设备操作失败");
            }
}
        /// <summary>
        /// æŸ¥çœ‹æŠ¥è­¦
        /// </summary>
        public WebResponseContent LogAlarmToDatabase(string JobDeviceName)
        {
            // è®¾å¤‡åˆ†ç±» - åˆå¹¶ç‰ˆæœ¬
            var deviceCategories = new Dictionary<string, List<string>>
            {
                ["MotherCar"] = new List<string> { "RGV112", "RGV110", "RGV114", "RGV115", "RGV103", "RGV105", "RGV108", "RGV109" },
                ["TransferCar"] = new List<string> { "RGV116", "RGV111", "RGV104", "RGV107" },
                ["ExternalRGV"] = new List<string> { "RGV118", "RGV101" }
            };
            WebResponseContent webResponse = new WebResponseContent();
            string DeviceName = JobDeviceName;    //设备名称
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            if (device == null) return webResponse.Error();
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            DeviceProDTO? RGV_Resetoperation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand");
            DeviceProDTO? RGVCurrentlocation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGVCurrentlocation", "RGVCurrentlocation");
            DeviceProDTO? RGV_Rgvtaskid = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Rgvtaskid", "ReadDeviceCommand");
            int baoj = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress);
            if (baoj<=0)
            {
                return null;
            }
            int Currentlocation = RgvOperationService.GetLine(Commonstacker, RGVCurrentlocation.DeviceProAddress);
            int Rgvtaskid = RgvOperationService.GetLine(Commonstacker, RGV_Rgvtaskid.DeviceProAddress);
            string alarmMessage = "";
            if (deviceCategories["MotherCar"].Contains(DeviceName))
            {
                // æ¯è½¦ä¸“用报警处理逻辑
                alarmMessage = HandleMotherCarAlarm(baoj);
            }
            else if (deviceCategories["TransferCar"].Contains(DeviceName))
            {
                // å­è½¦ä¸“用报警处理逻辑
                alarmMessage = HandleTransferCarAlarm(baoj);
            }
            else if (deviceCategories["ExternalRGV"].Contains(DeviceName))
            {
                // å¤–口RGV专用报警处理逻辑
                alarmMessage = HandleExternalRGVAlarm(baoj);
            }
            // å†™å…¥æ–‡æœ¬æ—¥å¿—(按设备分组/按日切分)
            var logContent = $"设备:{DeviceName} | æŠ¥è­¦ç :{baoj} | æŠ¥è­¦æè¿°:{alarmMessage} | å½“前位置:{Currentlocation} | ä»»åŠ¡å·:{Rgvtaskid}";
            // groupName: Alarm,logName: è®¾å¤‡å
            WriteLog.Write_Log("Alarm", DeviceName, logContent, new
            {
                DeviceCode = DeviceName,
                AlarmCode = baoj,
                AlarmContent = alarmMessage,
                DeviceLocation = Currentlocation,
                TaskNum = Rgvtaskid,
                Time = DateTime.Now
            });
            return webResponse.OK();
        }
        // æŠ¥è­¦ä»£ç æ˜ å°„方法
        private string HandleExternalRGVAlarm(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
{
    {0, "无报警"},
    {1, "RGV小车急停被按下"},
    {2, "正转雷达报警"},
    {3, "反转雷达报警"},
    {4, "前进限位报警"},
    {5, "后退限位报警"},
    {6, ""},
    {7, "PLC模块故障"},
    {8, "PLC扩展模块故障"},
    {9, "称重模块故障"},
    {10, "扫码定位故障"},
    {11, "RGV长时间空转故障"},
    {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, "外型检测-上超出报警"}
};
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
        private string HandleTransferCarAlarm(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "扫码定位故障"},
        {7, "RGV长时间空转故障"},
        {8, "目的地不等于实际位置故障"},
        {9, "与总控通讯故障"},
        {10, "行走变频器故障"},
        {11, "液压单元过载保护故障"},
        {12, "液压上升超时报警"},
        {13, "液压下降超时报警"},
        {14, "取货时自身有货物报警"},
        {15, "放货时自身无货物报警"},
        {16, "取货检测不到货物报警"}
    };
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
        private string HandleMotherCarAlarm(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "RGV长时间空转故障"},
        {7, "目的地不等于实际位置故障"},
        {8, "与总控通讯故障"},
        {9, "行走变频器故障"},
        {10, "取货时自身有货物报警"},
        {11, "放货时自身无货物报警"},
        {12, "停止时位置过冲报警"}
    };
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
    }
}