You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
5.6 KiB

4 months ago
using Common.Const;
using DotNetty.Transport.Channels;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
4 months ago
using Repository.Station;
using Service.Fire.Client;
using Service.Fire.Common;
using Service.Fire.Msg.Fire.Req;
namespace Service.Fire.Handler;
/// <summary>
/// 发送事件
/// <code>
/// 1保存日志到log
/// </code>
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class DataNoAddresReqHandler : SimpleChannelInboundHandler<DataNoAddresReq>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(DataNoAddresReqHandler));
4 months ago
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}");
4 months ago
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);
}
}
}
}
4 months ago
/// <summary>
/// 处理报警方法
/// </summary>
/// <param name="errorCode">报警编码</param>
/// <param name="isAlarm">是否存在报警</param>
/// <returns></returns>
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;
}
}