报警编码

master
CZ 2 months ago
parent b32ec7a117
commit d89d5a6085

@ -23,7 +23,9 @@ namespace Service.Charger.Handler;
public class SummaryFailuresReqHandler : SimpleChannelInboundHandler<SummaryFailuresReq>, IBaseHandler
{
private EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
private EquipAlarmRecordRepository equipAlarmRecordRepository { get; set; }
private EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
private EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; }
/// <summary>
///
/// </summary>
@ -37,7 +39,7 @@ public class SummaryFailuresReqHandler : SimpleChannelInboundHandler<SummaryFail
EquipAlarmDefine alarm = lstEquipAlarmDefine.Where(i => i.ErrorCode == number).First();
if (alarm != null)
{
equipAlarmRecordRepository.Insert(new EquipAlarmRecord()
EquipAlarmRecordRepository.Insert(new EquipAlarmRecord()
{
EquipTypeCode = alarm.EquipTypeCode,
EquipCode = alarm.EquipCode,
@ -48,8 +50,6 @@ public class SummaryFailuresReqHandler : SimpleChannelInboundHandler<SummaryFail
StartTime = DateTime.Now,
});
}
}
/// <summary>
@ -213,18 +213,66 @@ public class SummaryFailuresReqHandler : SimpleChannelInboundHandler<SummaryFail
Alarm("72");
//查询当前PLC的实时报警信息
var lstNowEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipCode == "plc");
var sqllstAlarm = lstNowEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList(); //当前报警列表
// 找出实时报警中存在但数据库中不存在的元素
List<string> uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList();
// 找出数据库中存在但实时报警中不存在的元素
List<string> uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList();
if (uniqueToList1.Count > 0)
{
//这里要添加新的报警数据
foreach (var errorCode in uniqueToList1)
{
EquipAlarmDefine? alarmDefine =
EquipAlarmDefineRepository.QueryByClause(i => i.ErrorCode == errorCode);
if (alarmDefine != null)
{
EquipAlarmRecord record = new EquipAlarmRecord()
{
EquipTypeCode = alarmDefine.EquipTypeCode,
EquipCode = "plc",
ErrorCode = errorCode,
ErrorLevel = alarmDefine.ErrorLevel,
ErrorMsg = alarmDefine.ErrorMsg,
ProcessMethod = alarmDefine.ProcessMethod,
StartTime = DateTime.Now
};
EquipAlarmRecordRepository.Insert(record);
}
}
}
else if (uniqueToList2.Count > 0)
{
//这些是要清除实时报警,并且处理记录的。
// 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
List<EquipAlarmRecord> filteredObjectList = lstNowEquipAlarmRecord
.Where(obj => uniqueToList2.Contains(obj.ErrorCode))
.ToList();
foreach (var VARIABLE in filteredObjectList)
{
EquipAlarmProcessRecord EquipAlarmProcessRecord = new EquipAlarmProcessRecord();
EquipAlarmProcessRecord.EquipTypeCode = VARIABLE.EquipTypeCode;
EquipAlarmProcessRecord.EquipCode = VARIABLE.EquipCode;
EquipAlarmProcessRecord.ErrorCode = VARIABLE.ErrorCode;
EquipAlarmProcessRecord.ErrorLevel = VARIABLE.ErrorLevel;
EquipAlarmProcessRecord.ErrorMsg = VARIABLE.ErrorMsg;
EquipAlarmProcessRecord.ProcessMethod = VARIABLE.ProcessMethod;
EquipAlarmProcessRecord.StartTime = VARIABLE.StartTime;
EquipAlarmProcessRecord.ProcessTime = DateTime.Now;
EquipAlarmProcessRecordRepository.Insert(EquipAlarmProcessRecord);
}
EquipAlarmRecordRepository.Delete(filteredObjectList);
}
ClientMgr.PlcClient.Auto = msg.T3 == 1;
ClientMgr.PlcClient.Remote = msg.T3 == 1;
ClientMgr.PlcClient.Init = msg.T6 == 1;
}
}
Loading…
Cancel
Save