99 lines
4.6 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.Protocol.Contracts.Protocol.Dto;
using JiShe.CollectBus.Protocol.Contracts;
using JiShe.CollectBus.Protocol.Dto;
using JiShe.CollectBus.Protocol.Interfaces;
using JiShe.CollectBus.Protocol3761;
using Microsoft.Extensions.Logging;
using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix;
using JiShe.CollectBus.Common.Extensions;
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH
{
/// <summary>
/// 5.13.2.4.136 F181月冻结一象限无功电能示值总、费率 1M
/// </summary>
public class AFN13_F181_Analysis : IAnalysisStrategy<TB3761, UnitDataAnalysis<List<AnalysisBaseDto<decimal>>>>
{
private readonly ILogger<AFN13_F181_Analysis> _logger;
private readonly AnalysisStrategyContext _analysisStrategyContext;
private readonly DataStorage _dataStorage;
public AFN13_F181_Analysis(ILogger<AFN13_F181_Analysis> logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage)
{
_logger = logger;
_analysisStrategyContext = analysisStrategyContext;
_dataStorage = dataStorage;
}
public async Task<UnitDataAnalysis<List<AnalysisBaseDto<decimal>>>> ExecuteAsync(TB3761 input)
{
try
{
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList);
List<string> datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList);
string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}";
string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-01 00:00:00";
List<AnalysisBaseDto<decimal>> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结一象限无功电能示值(总、费率 1M").IsValidData(new List<string>() { "0D_181", "0D_181_1", "0D_181_2", "0D_181_3", "0D_181_4" });
// 查询电表信息
//AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15");
//if (ammeterInfo != null)
//{
// data.ProjectId = ammeterInfo.ProjectID;
// data.MeterId = ammeterInfo.MeterId;
// data.DatabaseBusiID = ammeterInfo.DatabaseBusiID;
// data.MeterAddress = ammeterInfo.AmmerterAddress;
//}
UnitDataAnalysis<List<AnalysisBaseDto<decimal>>> unitDataAnalysis = new UnitDataAnalysis<List<AnalysisBaseDto<decimal>>>
{
Code = input.A.Code!,
AFN = input.AFN_FC.AFN,
Fn = input.DT.Fn,
Pn = input.DA.Pn,
MSA = input.A.A3!.D1_D7!,
PSEQ = input.SEQ.PSEQ,
Data = data,
HexMessage = input.BaseHexMessage.HexMessageString,
MessageId = input.MessageId,
TimeDensity = 1,//密度-间隔,
DensityUnit = DensityUnit.Month
};
//await _dataStorage.SaveDataToIotDbAsync<decimal>(unitDataAnalysis);
return await Task.FromResult(unitDataAnalysis);
}
catch (Exception ex)
{
_logger.LogError(ex, $"0D_181解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}");
return null;
}
}
private async Task<List<string>> AnalysisDataUnitAsync(List<string> hexMessageList)
{
List<string> values = new List<string>
{
hexMessageList.GetReadTime(4, 2),
hexMessageList.GetReadTime(6, 5)
};
int ratingCount = hexMessageList.GetRatingCount(11, 1);
values.Add(ratingCount.ToString());
for (int i = 0; i < ratingCount + 1; i++)
{
var arr = hexMessageList.GetRange(12 + (i * 4), 4);
var errorCode = arr.CheckErrorCode();
if (errorCode != null)
values.Add(errorCode.Item1);
else
{
var value = await _analysisStrategyContext.ExecuteAsync<List<string>, decimal>(nameof(Appendix_A11), arr); //从第10个开始每加5个字节为下一个值的开始
values.Add(value.ToString());
}
}
return values;
}
}
}