|
|
|
|
using Autofac;
|
|
|
|
|
using Common.Const;
|
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using Repository.Station;
|
|
|
|
|
|
|
|
|
|
namespace Service;
|
|
|
|
|
|
|
|
|
|
public class FaultHandling
|
|
|
|
|
{
|
|
|
|
|
public EquipAlarmDefineRepository EquipAlarmDefineRepository=AppInfo.Container.Resolve<EquipAlarmDefineRepository>();
|
|
|
|
|
public EquipAlarmRecordRepository EquipAlarmRecordRepository=AppInfo.Container.Resolve<EquipAlarmRecordRepository>();
|
|
|
|
|
public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository =AppInfo.Container.Resolve<EquipAlarmProcessRecordRepository>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设备不唯一的情况下,设备编码加EquipAlarmDefine中报警编码,组成实时报警中的报警编码
|
|
|
|
|
//没有报警也要把编码传进来,以为例如充电机不是一个数据帧报过来的
|
|
|
|
|
|
|
|
|
|
//情况1,没有报警编码直接消除
|
|
|
|
|
//情况2,收到报警编码消失消除
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设备报警批量处理方法,统一调用方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lstAlarm">设备报警列表</param>
|
|
|
|
|
/// <param name="equip_type_code">设备编码
|
|
|
|
|
/// 0充电机
|
|
|
|
|
/// 1电表
|
|
|
|
|
/// 2液冷机
|
|
|
|
|
/// 3plc
|
|
|
|
|
/// 4电池
|
|
|
|
|
/// 5消防
|
|
|
|
|
/// 6rfid
|
|
|
|
|
/// 7Ups
|
|
|
|
|
/// 8温湿度
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="equip_code">设备编码,数字类型</param>
|
|
|
|
|
/// <param name="type">报警编码为空是否直接消除</param>
|
|
|
|
|
/// <param name="created_by">创建人--同一帧数据创建人相同,用123...代替,以此递增</param>
|
|
|
|
|
public void SaveAlarmInfo(List<string> lstAlarm,EquipmentType equip_type_code,string equip_code,bool type,string created_by="1")
|
|
|
|
|
{
|
|
|
|
|
if (lstAlarm.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
#region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录
|
|
|
|
|
|
|
|
|
|
var lstEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i =>
|
|
|
|
|
i.EquipTypeCode == (int)equip_type_code && i.CreatedBy == created_by);
|
|
|
|
|
var sqllstAlarm = lstEquipAlarmRecord.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.SelectByEquipCodeAndErrorCode((int)equip_type_code, equip_code);
|
|
|
|
|
if (alarmDefine != null)
|
|
|
|
|
{
|
|
|
|
|
EquipAlarmRecord record = new EquipAlarmRecord()
|
|
|
|
|
{
|
|
|
|
|
EquipTypeCode = (int)alarmDefine.EquipTypeCode,
|
|
|
|
|
EquipCode = alarmDefine.EquipCode,
|
|
|
|
|
ErrorCode = 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<EquipAlarmRecord> 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 if(type)
|
|
|
|
|
{
|
|
|
|
|
#region 没报警把已处理记录更新并删除实时报警
|
|
|
|
|
|
|
|
|
|
var lstEquipAlarmRecord = EquipAlarmRecordRepository.QueryListByClause(i =>
|
|
|
|
|
i.EquipTypeCode == (int)equip_type_code && i.CreatedBy == created_by);
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|