From d89d5a6085d23fd4313aefb61d08375a138714fe Mon Sep 17 00:00:00 2001 From: CZ Date: Sat, 21 Sep 2024 09:52:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plc/Handler/SummaryFailuresReqHandler.cs | 76 +++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/Service/Plc/Handler/SummaryFailuresReqHandler.cs b/Service/Plc/Handler/SummaryFailuresReqHandler.cs index a1f6795..7e263c6 100644 --- a/Service/Plc/Handler/SummaryFailuresReqHandler.cs +++ b/Service/Plc/Handler/SummaryFailuresReqHandler.cs @@ -23,21 +23,23 @@ namespace Service.Charger.Handler; public class SummaryFailuresReqHandler : SimpleChannelInboundHandler, IBaseHandler { private EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; } - private EquipAlarmRecordRepository equipAlarmRecordRepository { get; set; } + private EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; } + private EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; } + /// /// /// private static readonly ILog Log = LogManager.GetLogger(typeof(SummaryFailuresReqHandler)); - List lstEquipAlarmDefine=new List(); + List lstEquipAlarmDefine = new List(); void Alarm(string number) { EquipAlarmDefine alarm = lstEquipAlarmDefine.Where(i => i.ErrorCode == number).First(); - if (alarm!=null) + 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 @@ -64,7 +64,7 @@ public class SummaryFailuresReqHandler : SimpleChannelInboundHandler i.EquipCode == "plc"); + lstEquipAlarmDefine = EquipAlarmDefineRepository.QueryListByClause(i => i.EquipCode == "plc"); List lstAlarm = new List(); if (msg.ScreenEmergencyStop) @@ -213,18 +213,66 @@ public class SummaryFailuresReqHandler : SimpleChannelInboundHandler i.EquipCode == "plc"); + var sqllstAlarm = lstNowEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList(); //当前报警列表 + // 找出实时报警中存在但数据库中不存在的元素 + List uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList(); - ClientMgr.PlcClient.Auto = msg.T3 == 1; - ClientMgr.PlcClient.Remote = msg.T3 == 1; - ClientMgr.PlcClient.Init = msg.T6 == 1; - + // 找出数据库中存在但实时报警中不存在的元素 + List 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 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; } } \ No newline at end of file