71 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using JiShe.CollectBus.Common.Enums;
using JiShe.CollectBus.IotSystems.Ammeters;
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
using JiShe.CollectBus.Protocol.Dto;
using JiShe.CollectBus.Protocol.Interfaces;
using JiShe.CollectBus.Protocol3761;
using Microsoft.Extensions.Logging;
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0AH
{
/// <summary>
/// 5.5.1.3.55 F68定时上报 2 类数据任务启动/停止设置
/// </summary>
public class AFN10_F68_Analysis : IAnalysisStrategy<TB3761>
{
private readonly ILogger<AFN10_F68_Analysis> _logger;
private readonly DataStorage _dataStorage;
public AFN10_F68_Analysis(ILogger<AFN10_F68_Analysis> logger, DataStorage dataStorage)
{
_logger = logger;
_dataStorage = dataStorage;
}
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
{
try
{
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList);
var data = new AnalysisBaseDto<bool?>()
{
FiledDesc = "终端电能表/交流采样装置配置参数",
DataValue = input.UnitData.HexMessageList[4].Equals("55")
};
// 查询电表信息
AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(MeterTypeEnum.Focus.ToString(), "15");
if (ammeterInfo != null)
{
data.ProjectId = ammeterInfo.ProjectID;
data.DeviceId = ammeterInfo.FocusId;
data.DatabaseBusiID = ammeterInfo.DatabaseBusiID;
data.DeviceAddress = ammeterInfo.Address;
data.DeviceType = MeterTypeEnum.Focus;
}
UnitDataAnalysis<AnalysisBaseDto<bool?>> dto = new UnitDataAnalysis<AnalysisBaseDto<bool?>>
{
Code = input.A.Code!,
AFN = input.AFN_FC.AFN,
Fn = input.DT.Fn,
Pn = input.DA.Pn,
Data = data,
ReceivedHexMessage = input.BaseHexMessage.HexMessageString,
MessageId = input.MessageId,
ReceivedTime = input.ReceivedTime,
DensityUnit = DensityUnit.None,
TimeDensity = -1
};
result?.Invoke(dto);
await _dataStorage.SaveDataToIotDbAsync<bool?>(dto);
return await Task.FromResult(true);
}
catch (Exception ex)
{
_logger.LogError(ex, $"0A_68解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}");
}
return await Task.FromResult(false);
}
}
}