2025-05-12 16:09:53 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Consts;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
2025-04-30 17:25:35 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
2025-05-13 17:49:12 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Devices;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Dto;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Interfaces;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol3761;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0EH
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 请求重要事件
|
|
|
|
|
|
/// Item1=停电事件
|
|
|
|
|
|
/// Item2=上电事件
|
|
|
|
|
|
/// </summary>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public class AFN14_F1_Analysis : IAnalysisStrategy<TB3761>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN14_F1_Analysis> _logger;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
private readonly DataStorage _dataStorage;
|
|
|
|
|
|
public AFN14_F1_Analysis(ILogger<AFN14_F1_Analysis> logger, DataStorage dataStorage)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
_dataStorage= dataStorage;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 09:25:41 +08:00
|
|
|
|
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-05-13 17:49:12 +08:00
|
|
|
|
ArgumentNullException.ThrowIfNull(input);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.A.Code);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList);
|
2025-04-29 11:43:16 +08:00
|
|
|
|
int erc = input.UnitData.HexMessageList![8].HexToDec();
|
2025-04-26 19:04:50 +08:00
|
|
|
|
bool isOnOffPower = erc.Equals(14) ? true : false;
|
|
|
|
|
|
if (!isOnOffPower)
|
|
|
|
|
|
{
|
2025-05-08 09:25:41 +08:00
|
|
|
|
// TODO:非终端停/上电事件直接确认
|
|
|
|
|
|
_logger.LogWarning($"0E_1解析ERC{erc}非终端停/上电事件:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString}");
|
|
|
|
|
|
return await Task.FromResult(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-13 17:49:12 +08:00
|
|
|
|
List<AnalysisBaseDto<string>> list = AnalysisDataUnit(input.UnitData.HexMessageList);
|
|
|
|
|
|
if (list.Count > 0)
|
2025-05-08 09:25:41 +08:00
|
|
|
|
{
|
2025-05-13 17:49:12 +08:00
|
|
|
|
// 查询设备信息
|
|
|
|
|
|
DeviceInfo? deviceInfo = await _dataStorage.GetDeviceInfoAsync(input.A.Code, input.DA.Pn);
|
|
|
|
|
|
if (deviceInfo != null)
|
2025-05-08 09:25:41 +08:00
|
|
|
|
{
|
2025-05-13 17:49:12 +08:00
|
|
|
|
list.ForEach(item =>
|
2025-05-08 09:25:41 +08:00
|
|
|
|
{
|
2025-05-13 17:49:12 +08:00
|
|
|
|
item.ProjectId = deviceInfo.ProjectID;
|
|
|
|
|
|
item.DeviceId = deviceInfo.MeterId;
|
|
|
|
|
|
item.DatabaseBusiID = deviceInfo.DatabaseBusiID;
|
|
|
|
|
|
item.DeviceAddress = deviceInfo.MeterAddress;
|
|
|
|
|
|
item.FocusId = deviceInfo.FocusId;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
2025-05-08 09:25:41 +08:00
|
|
|
|
UnitDataAnalysis<List<AnalysisBaseDto<string>>> dto = new UnitDataAnalysis<List<AnalysisBaseDto<string>>>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
2025-04-29 11:43:16 +08:00
|
|
|
|
Code = input.A.Code!,
|
|
|
|
|
|
AFN = input.AFN_FC.AFN,
|
|
|
|
|
|
Fn = input.DT.Fn,
|
|
|
|
|
|
Pn = input.DA.Pn,
|
2025-05-13 17:49:12 +08:00
|
|
|
|
Data = list,
|
2025-05-12 14:02:22 +08:00
|
|
|
|
ReceivedHexMessage = input.BaseHexMessage.HexMessageString,
|
2025-04-29 11:43:16 +08:00
|
|
|
|
MessageId = input.MessageId,
|
2025-04-30 17:25:35 +08:00
|
|
|
|
ReceivedTime = input.ReceivedTime,
|
|
|
|
|
|
DensityUnit = DensityUnit.None,
|
2025-05-12 16:09:53 +08:00
|
|
|
|
TimeDensity = -1,
|
|
|
|
|
|
DataType = IOTDBDataTypeConst.Event,
|
2025-04-26 19:04:50 +08:00
|
|
|
|
};
|
|
|
|
|
|
// meterData.DataType = "0E_1";
|
2025-04-29 09:16:48 +08:00
|
|
|
|
result?.Invoke(dto);
|
2025-05-08 09:25:41 +08:00
|
|
|
|
await _dataStorage.SaveMultipleStatusToIotDbAsync<string>(dto);
|
|
|
|
|
|
return await Task.FromResult(true);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2025-04-29 11:43:16 +08:00
|
|
|
|
_logger.LogError(ex, $"0E_1解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}");
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
2025-05-08 09:25:41 +08:00
|
|
|
|
return await Task.FromResult(false);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 09:25:41 +08:00
|
|
|
|
private List<AnalysisBaseDto<string>> AnalysisDataUnit(List<string> hexMessageList)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// Item1=停电事件
|
|
|
|
|
|
/// Item2=上电事件
|
2025-05-08 09:25:41 +08:00
|
|
|
|
List <AnalysisBaseDto<string>> values = new List<AnalysisBaseDto<string>>
|
|
|
|
|
|
{
|
|
|
|
|
|
new AnalysisBaseDto<string>
|
|
|
|
|
|
{
|
|
|
|
|
|
FiledDesc = "停电事件",
|
|
|
|
|
|
FiledName = "Type",
|
|
|
|
|
|
DataValue = "PowerDownEvent",
|
|
|
|
|
|
TimeSpan=HandlerTime(hexMessageList.GetRange(10, 5))
|
|
|
|
|
|
},
|
|
|
|
|
|
new AnalysisBaseDto<string>
|
|
|
|
|
|
{
|
|
|
|
|
|
FiledDesc = "上电事件",
|
|
|
|
|
|
FiledName = "Type",
|
|
|
|
|
|
DataValue = "PowerOnEvent",
|
|
|
|
|
|
TimeSpan=HandlerTime(hexMessageList.GetRange(15, 5))
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
return values;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// /解析时间
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="times"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-05-08 09:25:41 +08:00
|
|
|
|
private DateTime? HandlerTime(List<string> times)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
times.Reverse();
|
2025-05-08 09:25:41 +08:00
|
|
|
|
string time = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{times[0]}-{times[1]}-{times[2]} {times[3]}:{times[4]}:00";
|
|
|
|
|
|
DateTime.TryParse(time, out DateTime dateTime);
|
|
|
|
|
|
return dateTime;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch { }
|
2025-05-08 09:25:41 +08:00
|
|
|
|
return null;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|