|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
using Entity.DbModel.Station;
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
using HybirdFrameworkCore.Utils;
|
|
|
|
using log4net;
|
|
|
|
using log4net.Core;
|
|
|
|
using Magicodes.ExporterAndImporter.Core.Models;
|
|
|
|
using NetTaste;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Repository.Station;
|
|
|
|
using Service.Charger.Client;
|
|
|
|
using Service.Charger.Msg.Charger.Req;
|
|
|
|
using Service.Charger.Msg.Charger.Resp;
|
|
|
|
using SixLabors.ImageSharp;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Service.Charger.Handler;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 故障汇总 处理器
|
|
|
|
/// </summary>
|
|
|
|
[Order(8)]
|
|
|
|
[Scope("InstancePerDependency")]
|
|
|
|
public class SummaryFailuresReqHandler : SimpleChannelInboundHandler<SummaryFailuresReq>, IBaseHandler
|
|
|
|
{
|
|
|
|
public SummaryFailuresReqHandler(EquipAlarmDefineRepository equipAlarmDefineRepository,
|
|
|
|
EquipAlarmRecordRepository equipAlarmRecordRepository,
|
|
|
|
EquipAlarmProcessRecordRepository equipAlarmProcessRecordRepository
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EquipAlarmDefineRepository = equipAlarmDefineRepository;
|
|
|
|
EquipAlarmRecordRepository = equipAlarmRecordRepository;
|
|
|
|
EquipAlarmProcessRecordRepository = equipAlarmProcessRecordRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
private EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
|
|
|
|
private EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
|
|
|
|
private EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(SummaryFailuresReqHandler));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
protected override void ChannelRead0(IChannelHandlerContext ctx, SummaryFailuresReq msg)
|
|
|
|
{
|
|
|
|
Log.Info("Summary of failures");
|
|
|
|
|
|
|
|
var lstEquipAlarmDefine = EquipAlarmDefineRepository.QueryListByClause(i => i.EquipCode == "plc");
|
|
|
|
|
|
|
|
List<string> lstAlarm = new List<string>();
|
|
|
|
|
|
|
|
void Alarm(string number)
|
|
|
|
{
|
|
|
|
var alarm = lstEquipAlarmDefine.Where(i => i.ErrorCode == number);
|
|
|
|
if (alarm.Count() > 0)
|
|
|
|
lstAlarm.Add(alarm.ToList()[0].ErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.ScreenEmergencyStop)
|
|
|
|
Alarm("1");
|
|
|
|
if (msg.PassageEmergencyStop)
|
|
|
|
Alarm("2");
|
|
|
|
if (msg.RobotEmergencyStop)
|
|
|
|
Alarm("3");
|
|
|
|
if (msg.FaultyRelays)
|
|
|
|
Alarm("4");
|
|
|
|
if (msg.TelecommFailures)
|
|
|
|
Alarm("5");
|
|
|
|
if (msg.MasterFailures)
|
|
|
|
Alarm("6");
|
|
|
|
if (msg.TitleFailures)
|
|
|
|
Alarm("7");
|
|
|
|
if (msg.TitleXFailures)
|
|
|
|
Alarm("8");
|
|
|
|
if (msg.TitleYFailures)
|
|
|
|
Alarm("9");
|
|
|
|
if (msg.TitleZFailures)
|
|
|
|
Alarm("10");
|
|
|
|
if (msg.TitleMFailures)
|
|
|
|
Alarm("11");
|
|
|
|
if (msg.WireBroken0)
|
|
|
|
Alarm("12");
|
|
|
|
if (msg.WireBroken1)
|
|
|
|
Alarm("13");
|
|
|
|
if (msg.WireBroken2)
|
|
|
|
Alarm("14");
|
|
|
|
if (msg.WireBroken3)
|
|
|
|
Alarm("15");
|
|
|
|
if (msg.XPositiveLimit)
|
|
|
|
Alarm("16");
|
|
|
|
if (msg.XNegativeLimit)
|
|
|
|
Alarm("17");
|
|
|
|
if (msg.YPositiveLimit)
|
|
|
|
Alarm("18");
|
|
|
|
if (msg.YNegativeLimit)
|
|
|
|
Alarm("19");
|
|
|
|
if (msg.ZPositiveLimit)
|
|
|
|
Alarm("20");
|
|
|
|
if (msg.ZNegativeLimit)
|
|
|
|
Alarm("21");
|
|
|
|
if (msg.MPositiveLimit)
|
|
|
|
Alarm("22");
|
|
|
|
if (msg.MNegativeLimit)
|
|
|
|
Alarm("23");
|
|
|
|
if (msg.XDriveFailure)
|
|
|
|
Alarm("24");
|
|
|
|
if (msg.YDriveFailure)
|
|
|
|
Alarm("25");
|
|
|
|
if (msg.ZDriveFailure)
|
|
|
|
Alarm("26");
|
|
|
|
if (msg.MDriveFailure)
|
|
|
|
Alarm("27");
|
|
|
|
if (msg.DoorLeft)
|
|
|
|
Alarm("28");
|
|
|
|
if (msg.DoorcloseLeft)
|
|
|
|
Alarm("29");
|
|
|
|
if (msg.DoorRight)
|
|
|
|
Alarm("30");
|
|
|
|
if (msg.DoorcloseRight)
|
|
|
|
Alarm("31");
|
|
|
|
if (msg.DoorRepaiDhambers)
|
|
|
|
Alarm("32");
|
|
|
|
if (msg.DoorcloseRepairChambers)
|
|
|
|
Alarm("33");
|
|
|
|
if (msg.DoorRepaiCabinet)
|
|
|
|
Alarm("34");
|
|
|
|
if (msg.DoorRowFrames)
|
|
|
|
Alarm("35");
|
|
|
|
if (msg.X1RetractionFailure)
|
|
|
|
Alarm("36");
|
|
|
|
if (msg.X1StickingFault)
|
|
|
|
Alarm("37");
|
|
|
|
if (msg.X2RetractionFailure)
|
|
|
|
Alarm("38");
|
|
|
|
if (msg.X2StickingFault)
|
|
|
|
Alarm("39");
|
|
|
|
if (msg.LocalBattIncorrect)
|
|
|
|
Alarm("40");
|
|
|
|
if (msg.NoLocalBattery)
|
|
|
|
Alarm("41");
|
|
|
|
if (msg.LocalStorageBatteries)
|
|
|
|
Alarm("42");
|
|
|
|
if (msg.RemoteBattIncorrect)
|
|
|
|
Alarm("43");
|
|
|
|
if (msg.RemoteBattery)
|
|
|
|
Alarm("44");
|
|
|
|
if (msg.RemoteStorageBatteries)
|
|
|
|
Alarm("45");
|
|
|
|
if (msg.RemoteMoveLibraryBattery)
|
|
|
|
Alarm("46");
|
|
|
|
if (msg.RemoteLibraryBatteries)
|
|
|
|
Alarm("47");
|
|
|
|
if (msg.RemoteAreBatteries)
|
|
|
|
Alarm("48");
|
|
|
|
if (msg.RemoteMoveElectLibrary)
|
|
|
|
Alarm("49");
|
|
|
|
if (msg.RemoteelectrLibrary)
|
|
|
|
Alarm("50");
|
|
|
|
if (msg.RemoteelectrAreBatteries)
|
|
|
|
Alarm("51");
|
|
|
|
if (msg.RemoteStorageLibrary)
|
|
|
|
Alarm("52");
|
|
|
|
if (msg.RemotStorageAreBatteries)
|
|
|
|
Alarm("53");
|
|
|
|
if (msg.RemoteOutboundLibrary)
|
|
|
|
Alarm("54");
|
|
|
|
if (msg.RemotOutboundAreBatteries)
|
|
|
|
Alarm("55");
|
|
|
|
if (msg.RemoteBackupLibrary)
|
|
|
|
Alarm("56");
|
|
|
|
if (msg.RemotBackupAreBatteries)
|
|
|
|
Alarm("57");
|
|
|
|
if (msg.BatteryCompartAbnormal01)
|
|
|
|
Alarm("58");
|
|
|
|
if (msg.BatteryCompartAbnormal02)
|
|
|
|
Alarm("59");
|
|
|
|
if (msg.BatteryCompartAbnormal03)
|
|
|
|
Alarm("60");
|
|
|
|
if (msg.BatteryCompartAbnormal04)
|
|
|
|
Alarm("61");
|
|
|
|
if (msg.BatteryCompartAbnormal05)
|
|
|
|
Alarm("62");
|
|
|
|
if (msg.BatteryCompartAbnormal06)
|
|
|
|
Alarm("63");
|
|
|
|
if (msg.BatteryCompartAbnormal07)
|
|
|
|
Alarm("64");
|
|
|
|
if (msg.BatteryCompartAbnormal08)
|
|
|
|
Alarm("65");
|
|
|
|
if (msg.BatteryCompartAbnormal09)
|
|
|
|
Alarm("66");
|
|
|
|
if (msg.BatteryWasDetectCompartment)
|
|
|
|
Alarm("67");
|
|
|
|
if (msg.RepairWasDetectCompartment)
|
|
|
|
Alarm("68");
|
|
|
|
if (msg.WasDetectCompartment214)
|
|
|
|
Alarm("69");
|
|
|
|
if (msg.ZSpreaderForceSensor)
|
|
|
|
Alarm("70");
|
|
|
|
if (msg.YZSafetyBitAlarm)
|
|
|
|
Alarm("71");
|
|
|
|
if (msg.YZSafetyWarehouseBitAlarm)
|
|
|
|
Alarm("72");
|
|
|
|
|
|
|
|
|
|
|
|
//查询当前充电机的实时报警信息
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|