From 4ad5cc8d27aba0583ed7dccb5e8739d3665b2d90 Mon Sep 17 00:00:00 2001 From: CZ Date: Mon, 22 Jul 2024 14:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=B5=E6=B1=A0=E6=95=85?= =?UTF-8?q?=E9=9A=9C=E6=8A=A5=E8=AD=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Station/EquipAlarmDefineRepository.cs | 12 + Service/Charger/Handler/UpAlarmHandler.cs | 232 ++++++++++++++++++ .../Handler/UploadRemoteSignalDataHandler.cs | 23 -- Service/Charger/Msg/Charger/Resp/UpAlarm.cs | 158 ++++++++---- 4 files changed, 360 insertions(+), 65 deletions(-) diff --git a/Repository/Station/EquipAlarmDefineRepository.cs b/Repository/Station/EquipAlarmDefineRepository.cs index 8e4f2b3..d80e754 100644 --- a/Repository/Station/EquipAlarmDefineRepository.cs +++ b/Repository/Station/EquipAlarmDefineRepository.cs @@ -10,4 +10,16 @@ public class EquipAlarmDefineRepository : BaseRepository public EquipAlarmDefineRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) { } + /// + /// + /// + /// 0-充电机;1-电表;2-水冷;3-plc; + /// + /// + /// + public EquipAlarmDefine? SelectByEquipCodeAndErrorCode(int equipTypeCode, string equipCode) + { + return this.QueryByClause(it => it.EquipTypeCode == equipTypeCode && + it.EquipCode == equipCode); + } } \ No newline at end of file diff --git a/Service/Charger/Handler/UpAlarmHandler.cs b/Service/Charger/Handler/UpAlarmHandler.cs index b210823..093d000 100644 --- a/Service/Charger/Handler/UpAlarmHandler.cs +++ b/Service/Charger/Handler/UpAlarmHandler.cs @@ -22,7 +22,239 @@ namespace Service.Charger.Handler if (ClientMgr.TryGetClient(ctx.Channel, out string sn, out var client)) { Log.Info($"receive {msg} from {sn}"); + + #region 故障处理 + + string bms = "bms"; + List lstAlarm = new List(); + + if (msg.SingleBattery == 1) + { + lstAlarm.Add(bms + sn + "100"); + } + else if (msg.SingleBattery == 2) + { + lstAlarm.Add(bms + sn + "101"); + } + + if (msg.VoltageOvershoot == 2) + { + lstAlarm.Add(bms + sn + "102"); + } + + if (msg.TemperatureExceedance == 1) + { + lstAlarm.Add(bms + sn + "103"); + } + else if (msg.TemperatureExceedance == 2) + { + lstAlarm.Add(bms + sn + "104"); + } + + if (msg.TemperatureDifference == 2) + { + lstAlarm.Add(bms + sn + "105"); + } + + if (msg.LowSOC == 1) + { + lstAlarm.Add(bms + sn + "106"); + } + + if (msg.DischargeCurrent == 2) + { + lstAlarm.Add(bms + sn + "107"); + } + + if (msg.ChargingCurrentLimit == 1) + { + lstAlarm.Add(bms + sn + "108"); + } + else if (msg.ChargingCurrentLimit == 2) + { + lstAlarm.Add(bms + sn + "109"); + } + + if (msg.TotalTemp == 2) + { + lstAlarm.Add(bms + sn + "110"); + } + + if (msg.HighVoltageLow == 2) + { + lstAlarm.Add(bms + sn + "111"); + } + + if (msg.MonomerLimit == 1) + { + lstAlarm.Add(bms + sn + "112"); + } + else if (msg.MonomerLimit == 1) + { + lstAlarm.Add(bms + sn + "113"); + } + + if (msg.VoltageDifference == 2) + { + lstAlarm.Add(bms + sn + "114"); + } + + if (msg.TemperatureOvershoot == 1) + { + lstAlarm.Add(bms + sn + "115"); + } + else if (msg.TemperatureOvershoot == 2) + { + lstAlarm.Add(bms + sn + "116"); + } + + if (msg.TempDifference == 2) + { + lstAlarm.Add(bms + sn + "117"); + } + + if (msg.VeryLowSoc == 1) + { + lstAlarm.Add(bms + sn + "118"); + } + + if (msg.DischargeCurrentLimit == 2) + { + lstAlarm.Add(bms + sn + "119"); + } + + if (msg.ChargingCurrent == 2) + { + lstAlarm.Add(bms + sn + "120"); + } + + if (msg.TotalTempLimit == 2) + { + lstAlarm.Add(bms + sn + "121"); + } + + if (msg.HighVoltageInsulation == 1) + { + lstAlarm.Add(bms + sn + "122"); + } + + if (msg.HardwareFailure == 1) + { + lstAlarm.Add(bms + sn + "123"); + } + + if (msg.BatteryFaultCode != 0) + { + lstAlarm.Add(bms + sn + msg.BatteryFaultCode.ToString()); + } + + SaveAlarmInfo(lstAlarm); + + #endregion + } } + + #region 故障处理方法 + + private void SaveAlarmInfo(List lstAlarm) + { + string bms = "bms"; + + if (lstAlarm.Count > 0) + { + #region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录 + + var lstEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipTypeCode == (int)EquipmentType.BMS); + 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.BMS, bms); + 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.QueryListByClause(i => i.EquipTypeCode == (int)EquipmentType.BMS); + 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(lstEquipAlarmRecord); + + #endregion + } + } + + #endregion + } } diff --git a/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs b/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs index 1a387e3..f0b40cc 100644 --- a/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs +++ b/Service/Charger/Handler/UploadRemoteSignalDataHandler.cs @@ -171,29 +171,6 @@ namespace Service.Charger.Handler EquipAlarmRecordRepository.Delete(filteredObjectList); } } - //else - //{ - /*var lstNowEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i => i.EquipCode == sn); - if (lstNowEquipAlarmRecord.Count > 0) - { - foreach (var VARIABLE in lstNowEquipAlarmRecord) - { - 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 } } diff --git a/Service/Charger/Msg/Charger/Resp/UpAlarm.cs b/Service/Charger/Msg/Charger/Resp/UpAlarm.cs index 5907982..662cf3e 100644 --- a/Service/Charger/Msg/Charger/Resp/UpAlarm.cs +++ b/Service/Charger/Msg/Charger/Resp/UpAlarm.cs @@ -29,107 +29,181 @@ namespace Service.Charger.Msg.Charger.Resp /// /// 单体蓄电池或蓄电池模块电压越限 /// - [Property(32, 16)] - public short SingleBattery { get; set; } + [Property(32, 2)] + public byte SingleBattery { get; set; } /// /// 电压偏差越限 /// - [Property(48, 16)] - public short VoltageOvershoot { get; set; } + [Property(34, 2)] + public byte VoltageOvershoot { get; set; } /// /// 温度越限 /// - [Property(64, 16)] - public short TemperatureExceedance { get; set; } + [Property(36, 2)] + public byte TemperatureExceedance { get; set; } /// /// 温度偏差越限 /// - [Property(80, 16)] - public short TemperatureDifference { get; set; } + [Property(38, 2)] + public byte TemperatureDifference { get; set; } /// /// SOC 低 /// - [Property(96, 16)] - public short LowSOC { get; set; } + [Property(40, 2)] + public byte LowSOC { get; set; } /// /// 放电电流越限 /// - [Property(112, 16)] - public short DischargeCurrent { get; set; } + [Property(42, 2)] + public byte DischargeCurrent { get; set; } /// /// 充电电流限 /// - [Property(128, 16)] - public short ChargingCurrentLimit { get; set; } + [Property(44, 2)] + public byte ChargingCurrentLimit { get; set; } /// /// 总正负极柱温度越限 /// - [Property(144, 16)] - public short TotalTemp { get; set; } + [Property(46, 2)] + public byte TotalTemp { get; set; } /// /// 电池系统故障码 + /// + /// 0x1011 单体温度过高一级 + /// 0x1012 单体温度过高二级 + /// 0x1013 单体温度过高三级 + /// 0x1021 单体温度过低一级 + /// 0x1022 单体温度过低二级 + /// 0x1023 单体温度过低三级 + /// 0x1031 单体过压一级 + /// 0x1032 单体过压二级 + /// 0x1033 单体过压三级 + /// 0x1041 单体欠压一级 + /// 0x1042 单体欠压二级 + /// 0x1043 单体欠压三级 + /// 0x10A1 电池包总压过高一级 + /// 0x10A2 电池包总压过高二级 + /// 0x10A3 电池包总压过高三级 + /// 0x10B1 电池包总压过低一级 + /// 0x10B2 电池包总压过低二级 + /// 0x10B3 电池包总压过低三级 + /// 0x1061 放电过流一级 + /// 0x1062 放电过流二级 + /// 0x1063 放电过流三级 + /// 0x1091 充电过流一级 + /// 0x1092 充电过流二级 + /// 0x1093 充电过流三级 + /// 0x10E1 单体压差过大一级 + /// 0x10E2 单体压差过大二级 + /// 0x10E3 单体压差过大三级 + /// 0x10D1 单体温差过大一级 + /// 0x10D2 单体温差过大二级 + /// 0x10D3 单体温差过大三级 + /// 0x10C1 绝缘过低一级 + /// 0x10C2 绝缘过低二级 + /// 0x10C3 绝缘过低三级 + /// 0x10F1 SOC 过低一级 + /// 0x10F2 SOC 过低二级 + /// 0x10F3 SOC 过低三级 + /// 0x1111 供电电压过低一级 + /// 0x1112 供电电压过低二级 + /// 0x1113 供电电压过低三级 + /// 0x1121 供电电压过高一级 + /// 0x1122 供电电压过高二级 + /// 0x1123 供电电压过高三级 + /// 0x1141 电池温升过快一级 + /// 0x1142 电池温升过快二级 + /// 0x1143 电池温升过快三级 + /// 0x1103 Pack 回路断开 + /// 0x2013 从板通讯丢失 + /// 0x2033 充电机丢失 + /// 0x2043 绝缘仪通讯丢失 + /// 0x2053 电流传感器通讯丢失 + /// 0x2073 热管理机组通讯丢失 + /// 0x20E3 电流传感器采样异常 + /// 0x20D3 绝缘采样异常 + /// 0x4013 主正继电器开路故障 + /// 0x4023 主负继电器开路故障 + /// 0x40F2 主正继电器粘连故障 + /// 0x4102 主负继电器粘连故障 + /// 0x5013 外部短路故障 + /// 0x5032 高压互锁故障 + /// 0x5053 CC2 电压异常 + /// 0x5153 充电枪连接故障 + /// 0x6033 充电系统不匹配故障 + /// 0x6023 充电电流异常 + /// 0x7022 均衡故障 + /// 0x8023 火灾报警 + /// 0x8013 自保护故障 + /// 0x8033 电池过放 + /// 0x8043 电池过充 + /// 0x5123 预充故障 + /// 0x90B3 电池电压采样线开路 + /// 0x90C3 电池温度采样线开路 + /// 0x90E3 电池电压采样异常 + /// 0x90F3 电池温度采样异常 /// - [Property(160, 16)] + [Property(48, 16)] public short BatteryFaultCode { get; set; } /// /// 高压绝缘低 /// - [Property(176, 16)] - public short HighVoltageLow { get; set; } + [Property(64, 2)] + public byte HighVoltageLow { get; set; } /// /// 单体蓄电池或蓄电池模块电压越极限 /// - [Property(192, 16)] - public short MonomerLimit { get; set; } + [Property(66, 2)] + public byte MonomerLimit { get; set; } /// - /// 电压偏差越极限a + /// 电压偏差越极限 /// - [Property(200, 16)] - public short VoltageDifference { get; set; } + [Property(68, 2)] + public byte VoltageDifference { get; set; } /// /// 温度越极限 /// - [Property(216, 16)] - public short TemperatureOvershoot { get; set; } + [Property(70, 2)] + public byte TemperatureOvershoot { get; set; } /// /// 温度偏差越极限 /// - [Property(232, 16)] - public short TempDifference { get; set; } + [Property(72, 2)] + public byte TempDifference { get; set; } /// /// SOC 极低 /// - [Property(248, 16)] - public short VeryLowSOC { get; set; } + [Property(74, 2)] + public byte VeryLowSoc { get; set; } /// /// 放电电流越极限 /// - [Property(264, 16)] - public short DischargeCurrentLimit { get; set; } + [Property(76, 2)] + public byte DischargeCurrentLimit { get; set; } /// /// 充电电流越极限 /// - [Property(280, 16)] - public short ChargingCurrent { get; set; } + [Property(78, 2)] + public byte ChargingCurrent { get; set; } /// /// 总正负极柱温度越极限 /// - [Property(296, 16)] - public short TotalTempLimit { get; set; } + [Property(80, 2)] + public byte TotalTempLimit { get; set; } /// /// 高压绝缘极低 /// - [Property(312, 16)] - public short highVoltageInsulation { get; set; } + [Property(82, 2)] + public byte HighVoltageInsulation { get; set; } /// /// 硬件故障 /// - [Property(328, 16)] - public short HardwareFailure { get; set; } + [Property(84, 2)] + public byte HardwareFailure { get; set; } /// /// 保留 /// - [Property(344, 16)] - public short Reserve { get; set; } + [Property(86, 2)] + public byte Reserve { get; set; } } }