using Common.Const; using DotNetty.Transport.Channels; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Repository.Station; using Service.Fire.Client; using Service.Fire.Common; using Service.Fire.Msg.Fire.Req; namespace Service.Fire.Handler; /// /// 发送事件 /// /// 1,保存日志到log /// /// [Order(8)] [Scope("InstancePerDependency")] public class DataNoAddresReqHandler : SimpleChannelInboundHandler, IBaseHandler { private static readonly ILog Log = LogManager.GetLogger(typeof(DataNoAddresReqHandler)); public EquipAlarmDefineRepository _equipAlarmDefineRepository { get; set; } public EquipAlarmRecordRepository _equipAlarmRecordRepository { get; set; } public EquipAlarmProcessRecordRepository _equipAlarmProcessRecordRepository { get; set; } public DataNoAddresReqHandler(EquipAlarmDefineRepository equipAlarmDefineRepository, EquipAlarmRecordRepository equipAlarmRecordRepository, EquipAlarmProcessRecordRepository equipAlarmProcessRecordRepository) { _equipAlarmDefineRepository = equipAlarmDefineRepository; _equipAlarmRecordRepository = equipAlarmRecordRepository; _equipAlarmProcessRecordRepository = equipAlarmProcessRecordRepository; } protected override void ChannelRead0(IChannelHandlerContext ctx, DataNoAddresReq msg) { if (FireMgr.TryGetClient(ctx.Channel, out var sn, out var client)) { Log.Info($"receive {msg} from {sn}"); if (msg.Building == 1) //1栋左 { if (msg.DeviceStatus == 0x05) //火警 { Troubleshoot("85", true); } else if (msg.DeviceStatus == 0x00) //火警消除 { Troubleshoot("85", false); } if (msg.DeviceType == 0xED) //气体现场动作 { Troubleshoot("86", true); } else //报警消除 { Troubleshoot("86", false); } } else if (msg.Building == 2) //2栋右 { if (msg.DeviceStatus == 0x05) //火警 { Troubleshoot("87", true); } else if (msg.DeviceStatus == 0x00) //火警消除 { Troubleshoot("87", false); } if (msg.DeviceType == 0xED) //气体现场动作 { Troubleshoot("88", true); } else //报警消除 { Troubleshoot("85", false); } } } } /// /// 处理报警方法 /// /// 报警编码 /// 是否存在报警 /// public bool Troubleshoot(string errorCode, bool isAlarm) { if (isAlarm) //存在报警 { EquipAlarmDefine EquipAlarmDefine = _equipAlarmDefineRepository.QueryByClause(i => i.ErrorCode == errorCode && i.EquipTypeCode == (int)EquipmentType.Fire); if (EquipAlarmDefine!=null) { var isfault=_equipAlarmRecordRepository.QueryByClause(i => i.ErrorCode == errorCode && i.EquipTypeCode == (int)EquipmentType.Fire); if (isfault!=null) //判断这个报警是否已经添加了 { return true; } EquipAlarmRecord EquipAlarmRecord = new EquipAlarmRecord() { EquipTypeCode = EquipAlarmDefine.EquipTypeCode, EquipCode = EquipAlarmDefine.EquipCode, ErrorCode = EquipAlarmDefine.ErrorCode, ErrorLevel = EquipAlarmDefine.ErrorLevel, ErrorMsg = EquipAlarmDefine.ErrorMsg, StartTime = DateTime.Now, }; _equipAlarmRecordRepository.Insert(EquipAlarmRecord); //添加故障处理 } } else { EquipAlarmRecord EquipAlarmRecord = _equipAlarmRecordRepository.QueryByClause(i => i.ErrorCode == errorCode && i.EquipTypeCode == (int)EquipmentType.Fire); if (EquipAlarmRecord != null) { EquipAlarmProcessRecord EquipAlarmProcessRecord = new EquipAlarmProcessRecord() { EquipTypeCode = EquipAlarmRecord.EquipTypeCode, EquipCode = EquipAlarmRecord.EquipCode, ErrorCode = EquipAlarmRecord.ErrorCode, ErrorLevel = EquipAlarmRecord.ErrorLevel, ErrorMsg = EquipAlarmRecord.ErrorMsg, StartTime = EquipAlarmRecord.StartTime, ProcessTime = DateTime.Now, }; _equipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord); //保存记录 _equipAlarmRecordRepository.Delete(i => i.ErrorCode == errorCode && i.EquipTypeCode == (int)EquipmentType.Fire); } } return true; } }