2025-04-24 19:31:28 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
|
|
|
|
|
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-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.101 F145:当月正向有功最大需量及发生时间(总、费率 1~M)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class AFN12_F145_Analysis : IAnalysisStrategy<TB3761, UnitDataAnalysis<AFN12_F145_AnalysisDto>>
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN12_F145_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
|
|
|
|
|
|
|
|
|
|
|
public AFN12_F145_Analysis(ILogger<AFN12_F145_Analysis> logger, AnalysisStrategyContext analysisStrategyContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_analysisStrategyContext = analysisStrategyContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<UnitDataAnalysis<AFN12_F145_AnalysisDto>> ExecuteAsync(TB3761 input)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList);
|
|
|
|
|
|
List<string> datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList);
|
|
|
|
|
|
AFN12_F145_AnalysisDto data = GenerateFinalResult(2, datas, "当月正向有功最大需量及发生时间");
|
|
|
|
|
|
data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}";
|
|
|
|
|
|
UnitDataAnalysis<AFN12_F145_AnalysisDto> unitDataAnalysis = new UnitDataAnalysis<AFN12_F145_AnalysisDto>
|
|
|
|
|
|
{
|
|
|
|
|
|
Code = input.A.Code,
|
|
|
|
|
|
AFN = input.AFN_FC.AFN,
|
|
|
|
|
|
Fn = input.DT.Fn,
|
|
|
|
|
|
Pn = input.DA.Pn,
|
|
|
|
|
|
Data = data
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(unitDataAnalysis);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, $"0C_145解析失败:{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>();
|
|
|
|
|
|
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 * 7, 3);
|
|
|
|
|
|
var errorCode = arr.CheckErrorCode();
|
|
|
|
|
|
if (errorCode != null)
|
|
|
|
|
|
values.Add(errorCode.Item1);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var value = await _analysisStrategyContext.ExecuteAsync<List<string>, decimal>(nameof(Appendix_A23), arr);
|
|
|
|
|
|
values.Add(value.ToString());//正向有功总最大需量
|
|
|
|
|
|
}
|
|
|
|
|
|
arr = hexMessageList.GetRange(10 + i * 7 + 3, 4);
|
|
|
|
|
|
|
|
|
|
|
|
errorCode = arr.CheckErrorCode();
|
|
|
|
|
|
if (errorCode != null)
|
|
|
|
|
|
values.Add(errorCode.Item1);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var value = await _analysisStrategyContext.ExecuteAsync<List<string>, string>(nameof(Appendix_A17), arr);
|
|
|
|
|
|
values.Add(value.ToString());//正向有功总最大需量发生时间
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return values;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AFN12_F145_AnalysisDto GenerateFinalResult(int index, List<string> data, string remark = "")
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN12_F145_AnalysisDto dto = new AFN12_F145_AnalysisDto();
|
|
|
|
|
|
|
|
|
|
|
|
decimal value = 0;
|
|
|
|
|
|
var errorCode = data[2].CheckErrorCode();
|
|
|
|
|
|
if (errorCode != null)
|
|
|
|
|
|
dto.ValidData = false;
|
|
|
|
|
|
else
|
|
|
|
|
|
decimal.TryParse(data[2], out value);
|
|
|
|
|
|
|
|
|
|
|
|
dto.DataValue = value;
|
|
|
|
|
|
dto.TimeSpan = $"{DateTime.Now.Year}-{data[3].Substring(0, 2)}-{data[3].Substring(2, 2)} {data[3].Substring(4, 2)}:{data[3].Substring(6, 2)}:00";//$"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)}";
|
|
|
|
|
|
if (DateTime.TryParse(dto.TimeSpan, out DateTime readingDate))
|
|
|
|
|
|
{
|
|
|
|
|
|
dto.ReadingDate = readingDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
return dto;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|