diff --git a/Entity/DbModel/Station/EquipAlarmProcessRecord.cs b/Entity/DbModel/Station/EquipAlarmProcessRecord.cs
index d00cda9..4b82126 100644
--- a/Entity/DbModel/Station/EquipAlarmProcessRecord.cs
+++ b/Entity/DbModel/Station/EquipAlarmProcessRecord.cs
@@ -67,7 +67,13 @@ namespace Entity.DbModel.Station
///
[SugarColumn(ColumnName = "process_method")]
public string ProcessMethod { get; set; }
-
+ ///
+ /// Desc:开始时间
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName = "start_time")]
+ public DateTime? StartTime { get; set; }
///
/// Desc:处理时间
/// Default:
diff --git a/Entity/DbModel/Station/EquipAlarmRecord.cs b/Entity/DbModel/Station/EquipAlarmRecord.cs
index 75903e6..d348638 100644
--- a/Entity/DbModel/Station/EquipAlarmRecord.cs
+++ b/Entity/DbModel/Station/EquipAlarmRecord.cs
@@ -68,6 +68,14 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "process_method")]
public string ProcessMethod { get; set; }
+ ///
+ /// Desc:开始时间
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName = "start_time")]
+ public DateTime? StartTime { get; set; }
+
}
}
diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs
index 78b9dfc..d2466ce 100644
--- a/Service/Plc/Client/PlcClient.cs
+++ b/Service/Plc/Client/PlcClient.cs
@@ -63,29 +63,40 @@ public class PlcClient : ModbusTcpMaster
}
- var bytes03 = master.BatchReadHolderRegister(701, 10);
+ var bytes03 = master.BatchReadHolderRegister(701, 32);
if (bytes03 != null)
{
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
- EndingConst.WordSeq.DC);
- SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode01.Value, PlcMgr.PlcFaultData.ErrorCode01.Value);
- SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode03.Value, PlcMgr.PlcFaultData.ErrorCode03.Value);
- SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode05.Value, PlcMgr.PlcFaultData.ErrorCode05.Value);
- SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode07.Value, PlcMgr.PlcFaultData.ErrorCode07.Value);
- SaveAlarmInfo(PlcMgr.LastPlcFaultData.ErrorCode09.Value, PlcMgr.PlcFaultData.ErrorCode09.Value);
+ EndingConst.WordSeq.CD);
+ List alarm = new List()
+ {
+ PlcMgr.PlcFaultData.ErrorCode01.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode02.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode03.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode04.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode05.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode06.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode07.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode08.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode09.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode10.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode11.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode12.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode13.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode14.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode15.Value.ToString(),
+ PlcMgr.PlcFaultData.ErrorCode16.Value.ToString(),
+ };
+ SaveAlarmInfo(alarm);
}
}
- private void SaveAlarmInfo(int lastErrorCode, int errorCode)
+ private void SaveAlarmInfo(List lstAlarm)
{
- if (lastErrorCode == errorCode)
- {
- return;
- }
string plc = "plc";
- if (errorCode != 0)
+ /*if (errorCode != 0)
{
EquipAlarmDefine? alarmDefine = EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode.ToString());
if (alarmDefine == null)
@@ -104,8 +115,6 @@ public class PlcClient : ModbusTcpMaster
ProcessMethod = alarmDefine.ProcessMethod
};
EquipAlarmRecordRepository.Insert(record);
-
-
}
else
{
@@ -125,8 +134,96 @@ public class PlcClient : ModbusTcpMaster
EquipAlarmProcessRecordRepository.Insert(processRecord);
EquipAlarmRecordRepository.DeleteById(alarmRecord.Id);
}
+ }*/
+
+ if (lstAlarm.Count > 0)
+ {
+ #region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录
+
+ var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query();
+ var sqllstAlarm=lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList();
+
+ // 找出实时报警中存在但数据库中不存在的元素
+ List uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList();
+
+ // 找出数据库中存在但实时报警中不存在的元素
+ List uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList();
+
+ if (uniqueToList1.Count > 0)
+ {//这里要添加新的报警数据
+ foreach (var errorCode in uniqueToList1)
+ {
+ EquipAlarmDefine? alarmDefine = EquipAlarmDefineRepository.SelectByEquipCodeAndErrorCode((int)EquipmentType.Plc, plc, errorCode);
+ if (alarmDefine != null)
+ {
+ EquipAlarmRecord record = new EquipAlarmRecord()
+ {
+ EquipTypeCode = alarmDefine.EquipTypeCode,
+ EquipCode = alarmDefine.EquipCode,
+ ErrorCode = alarmDefine.ErrorCode,
+ ErrorLevel = alarmDefine.ErrorLevel,
+ ErrorMsg = alarmDefine.ErrorMsg,
+ ProcessMethod = alarmDefine.ProcessMethod,
+ StartTime= DateTime.Now
+ };
+ EquipAlarmRecordRepository.Insert(record);
+ }
+ }
+ }
+
+ if (uniqueToList2.Count > 0)
+ {//这些是要清除实时报警,并且处理记录的。
+ // 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
+ List filteredObjectList = lstEquipAlarmRecord
+ .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);
+ }
+
+ #endregion
}
+ else
+ {
+ #region 没报警把已处理记录更新并删除实时报警
+ var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query();
+ if (lstEquipAlarmRecord.Count > 0)
+ {
+ foreach (var VARIABLE in lstEquipAlarmRecord)
+ {
+ 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(i=>i.Id>0);
+
+ #endregion
+
+
+ }
}
private void UpdateBinInfo(int exists, string binNo)
diff --git a/Service/Plc/Msg/PlcFault.cs b/Service/Plc/Msg/PlcFault.cs
index 52d7df6..a7c3af6 100644
--- a/Service/Plc/Msg/PlcFault.cs
+++ b/Service/Plc/Msg/PlcFault.cs
@@ -5,9 +5,20 @@ namespace Service.Plc.Msg
public class PlcFault
{
public ModbusProperty ErrorCode01 { get; set; } = new(40701,length :2, value: 0); // 错误码
- public ModbusProperty ErrorCode03 { get; set; } = new(40703,length :2, value: 0); // 错误码
- public ModbusProperty ErrorCode05 { get; set; } = new(40705,length :2, value: 0); // 错误码
- public ModbusProperty ErrorCode07 { get; set; } = new(40707,length :2, value: 0); // 错误码
- public ModbusProperty ErrorCode09 { get; set; } = new(40709, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode02 { get; set; } = new(40703,length :2, value: 0); // 错误码
+ public ModbusProperty ErrorCode03 { get; set; } = new(40705,length :2, value: 0); // 错误码
+ public ModbusProperty ErrorCode04 { get; set; } = new(40707,length :2, value: 0); // 错误码
+ public ModbusProperty ErrorCode05 { get; set; } = new(40709, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode06 { get; set; } = new(40711, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode07 { get; set; } = new(40713, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode08 { get; set; } = new(40715, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode09 { get; set; } = new(40717, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode10 { get; set; } = new(40719, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode11 { get; set; } = new(40721, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode12 { get; set; } = new(40723, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode13 { get; set; } = new(40725, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode14 { get; set; } = new(40727, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode15 { get; set; } = new(40729, length: 2, value: 0); // 错误码
+ public ModbusProperty ErrorCode16 { get; set; } = new(40731, length: 2, value: 0); // 错误码
}
}
diff --git a/WebStarter/db/cz624.sql b/WebStarter/db/cz624.sql
new file mode 100644
index 0000000..9f449db
--- /dev/null
+++ b/WebStarter/db/cz624.sql
@@ -0,0 +1,4 @@
+ALTER TABLE equip_alarm_record
+ ADD COLUMN start_time DATETIME NULL COMMENT '开始时间';
+ALTER TABLE equip_alarm_process_record
+ ADD COLUMN start_time DATETIME NULL COMMENT '开始时间';