1
HuBingJie
9 天以前 28110912ca4803e5793f181517d7bf2d7a5ea2ad
´úÂë¹ÜÀí/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs
@@ -1,4 +1,4 @@
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
#region << ç‰ˆ æœ¬ æ³¨ é‡Š >>
/*----------------------------------------------------------------
 * å‘½åç©ºé—´ï¼šWIDESEAWCS_TaskInfoService
 * åˆ›å»ºè€…:胡童庆
@@ -41,6 +41,7 @@
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.Enum;
@@ -53,6 +54,7 @@
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEA_Common.Log;
namespace WIDESEAWCS_TaskInfoService
{
@@ -61,6 +63,7 @@
        private readonly IAgvStationService _gvStationService;
        private readonly IServiceProvider _serviceProvider;
        private static bool _isMonitoring = false;
        private readonly IRepository<DeviceAlarmLog> _deviceAlarmLog;
        //private static CancellationTokenSource _cancellationTokenSource;
        // åœ¨ç±»çº§åˆ«æ·»åŠ ç‹¬ç«‹çš„ç›‘æŽ§çŠ¶æ€
@@ -74,10 +77,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;
            _serviceProvider = serviceProvider;
            _deviceAlarmLog = deviceAlarmLog;
        }
@@ -693,12 +697,35 @@
                    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";
                    DeviceProParamType = "DeviceCommand";
@@ -838,6 +865,162 @@
                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, "货叉到达初始位但中位传感器未检测到报警"}
            };
            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] : "未知报警代码";
        }
    }
}