2025-04-30 17:25:35 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
2025-05-06 19:25:15 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Helpers;
|
2025-04-30 17:25:35 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Dto;
|
2025-04-25 14:35:59 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Interfaces;
|
2025-04-27 09:16:37 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.T37612012.Appendix;
|
2025-04-25 14:35:59 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol3761;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-05-08 15:12:37 +08:00
|
|
|
|
using YamlDotNet.Core.Tokens;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
|
2025-04-27 09:16:37 +08:00
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 5.12.2.4.88 F132:当前反向无功(组合无功 2)电能示值(总、费率 1~M)
|
|
|
|
|
|
/// </summary>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public class AFN12_F132_Analysis : IAnalysisStrategy<TB3761>
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<AFN12_F132_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
|
|
|
|
|
|
|
|
|
|
|
public AFN12_F132_Analysis(ILogger<AFN12_F132_Analysis> logger, AnalysisStrategyContext analysisStrategyContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_analysisStrategyContext = analysisStrategyContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList);
|
|
|
|
|
|
List<string> datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList);
|
2025-05-06 19:25:15 +08:00
|
|
|
|
string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}";
|
2025-05-08 15:12:37 +08:00
|
|
|
|
List<AnalysisBaseDto<decimal?>> list = GenerateFinalResult(2, datas, "反向无功电能示值", dataType);
|
|
|
|
|
|
UnitDataAnalysis<List<AnalysisBaseDto<decimal?>>> unitDataAnalysis = new UnitDataAnalysis<List<AnalysisBaseDto<decimal?>>>
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
2025-04-29 11:43:16 +08:00
|
|
|
|
Code = input.A.Code!,
|
2025-04-24 19:31:28 +08:00
|
|
|
|
AFN = input.AFN_FC.AFN,
|
|
|
|
|
|
Fn = input.DT.Fn ,
|
|
|
|
|
|
Pn = input.DA.Pn,
|
2025-04-29 11:43:16 +08:00
|
|
|
|
Data = list,
|
|
|
|
|
|
HexMessage = input.BaseHexMessage.HexMessageString,
|
|
|
|
|
|
MessageId = input.MessageId,
|
2025-04-30 17:25:35 +08:00
|
|
|
|
ReceivedTime = input.ReceivedTime,
|
|
|
|
|
|
DensityUnit = DensityUnit.Second,
|
|
|
|
|
|
TimeDensity = 0
|
2025-04-24 19:31:28 +08:00
|
|
|
|
};
|
2025-04-29 09:16:48 +08:00
|
|
|
|
result?.Invoke(unitDataAnalysis);
|
|
|
|
|
|
return await Task.FromResult(true);
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, $"0C_132解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}");
|
2025-04-29 09:16:48 +08:00
|
|
|
|
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
2025-04-29 09:16:48 +08:00
|
|
|
|
return await Task.FromResult(false);
|
2025-04-24 19:31:28 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private async Task<List<string>> AnalysisDataUnitAsync(List<string> hexMessageList)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<string> values = new List<string>();
|
|
|
|
|
|
values.Add(hexMessageList.GetReadTime(4, 5));
|
|
|
|
|
|
int ratingCount = hexMessageList.GetRatingCount(9, 1);
|
|
|
|
|
|
values.Add(ratingCount.ToString());
|
|
|
|
|
|
for (int i = 0; i < ratingCount + 1; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var arr = hexMessageList.GetRange(10 + (i * 4), 4);
|
|
|
|
|
|
var errorCode = arr.CheckErrorCode();
|
|
|
|
|
|
if (errorCode != null)
|
|
|
|
|
|
values.Add(errorCode.Item1);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-04-29 09:16:48 +08:00
|
|
|
|
await _analysisStrategyContext.ExecuteAsync<List<string>>(nameof(Appendix_A11), arr, (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
values.Add(value.ToString());
|
|
|
|
|
|
}); //从第10个开始,每加5个字节为下一个值的开始
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return values;
|
|
|
|
|
|
}
|
2025-05-08 15:12:37 +08:00
|
|
|
|
public List<AnalysisBaseDto<decimal?>> GenerateFinalResult(int index, List<string> data, string dataType, string filedDesc = "")
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
2025-05-08 15:12:37 +08:00
|
|
|
|
List<AnalysisBaseDto<decimal?>> list = new List<AnalysisBaseDto<decimal?>>();
|
2025-04-24 19:31:28 +08:00
|
|
|
|
for (int i = index; i < data.Count; i++)
|
|
|
|
|
|
{
|
2025-05-08 15:12:37 +08:00
|
|
|
|
AnalysisBaseDto<decimal?> meter = new AnalysisBaseDto<decimal?>
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceType = MeterTypeEnum.Ammeter
|
|
|
|
|
|
};
|
2025-04-24 19:31:28 +08:00
|
|
|
|
var errorCode = data[i].CheckErrorCode();
|
|
|
|
|
|
if (errorCode != null)
|
2025-05-08 15:12:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
meter.ErrorCodeMsg = errorCode.Item2;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
meter.ValidData = false;
|
2025-05-08 15:12:37 +08:00
|
|
|
|
}
|
2025-04-24 19:31:28 +08:00
|
|
|
|
else
|
2025-05-08 15:12:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(decimal.TryParse(data[i], out decimal value))
|
|
|
|
|
|
meter.DataValue = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-06 19:25:15 +08:00
|
|
|
|
meter.DataType = $"{dataType}_{i - index}";
|
2025-05-08 15:12:37 +08:00
|
|
|
|
string timeSpan = $"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00";
|
|
|
|
|
|
if (DateTime.TryParse(timeSpan,out DateTime readingDate))
|
|
|
|
|
|
{
|
|
|
|
|
|
meter.TimeSpan = readingDate;
|
|
|
|
|
|
}
|
2025-05-06 19:25:15 +08:00
|
|
|
|
meter.FiledDesc = filedDesc;
|
|
|
|
|
|
meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
list.Add(meter);
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|