2025-05-12 16:09:53 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Consts;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
2025-04-27 10:20:22 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
2025-04-27 17:23:26 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Helpers;
|
2025-04-27 10:20:22 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Dto;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Interfaces;
|
2025-04-27 10:20:22 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.T37612012.Appendix;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol3761;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-05-12 16:48:45 +08:00
|
|
|
|
using static FreeSql.Internal.GlobalFilter;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 5.13.2.4.145 F190:抄表日冻结正向无功最大需量及发生时间(总、费率 1~M)
|
|
|
|
|
|
/// </summary>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public class AFN13_F190_Analysis : IAnalysisStrategy<TB3761>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN13_F190_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
|
|
|
|
|
private readonly DataStorage _dataStorage;
|
|
|
|
|
|
public AFN13_F190_Analysis(ILogger<AFN13_F190_Analysis> logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_analysisStrategyContext = analysisStrategyContext;
|
|
|
|
|
|
_dataStorage = dataStorage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList);
|
|
|
|
|
|
|
|
|
|
|
|
List<string> datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList);
|
2025-05-08 15:12:37 +08:00
|
|
|
|
string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}";
|
|
|
|
|
|
AnalysisBaseDto<decimal?> data = GenerateFinalResult(datas, "抄表日冻结正向无功最大需量及发生时间", dataType);
|
|
|
|
|
|
|
2025-04-26 19:04:50 +08:00
|
|
|
|
// 查询电表信息
|
2025-05-07 11:53:50 +08:00
|
|
|
|
AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.DeviceType.ToString(), "15");
|
2025-04-27 09:31:12 +08:00
|
|
|
|
if (ammeterInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
data.ProjectId = ammeterInfo.ProjectID;
|
2025-05-07 11:53:50 +08:00
|
|
|
|
data.DeviceId = ammeterInfo.MeterId;
|
2025-04-27 09:31:12 +08:00
|
|
|
|
data.DatabaseBusiID = ammeterInfo.DatabaseBusiID;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
data.DeviceAddress = ammeterInfo.AmmerterAddress;
|
2025-05-12 16:48:45 +08:00
|
|
|
|
data.FocusId = ammeterInfo.FocusId;
|
2025-04-27 09:31:12 +08:00
|
|
|
|
}
|
2025-05-08 15:12:37 +08:00
|
|
|
|
UnitDataAnalysis<AnalysisBaseDto<decimal?>> unitDataAnalysis = new UnitDataAnalysis<AnalysisBaseDto<decimal?>>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
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,
|
2025-05-12 14:02:22 +08:00
|
|
|
|
ReceivedHexMessage = input.BaseHexMessage.HexMessageString,
|
2025-04-26 19:04:50 +08:00
|
|
|
|
MessageId = input.MessageId,
|
|
|
|
|
|
TimeDensity = 1,//密度-间隔,
|
2025-04-29 11:43:16 +08:00
|
|
|
|
DensityUnit = DensityUnit.Day,
|
2025-05-12 16:09:53 +08:00
|
|
|
|
ReceivedTime = input.ReceivedTime,
|
|
|
|
|
|
DataType = IOTDBDataTypeConst.Data,
|
2025-04-26 19:04:50 +08:00
|
|
|
|
};
|
2025-05-08 15:12:37 +08:00
|
|
|
|
await _dataStorage.SaveDataToIotDbAsync<decimal?>(unitDataAnalysis);
|
2025-04-29 09:16:48 +08:00
|
|
|
|
result?.Invoke(unitDataAnalysis);
|
|
|
|
|
|
return await Task.FromResult(true);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, $"0D_190解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}");
|
2025-04-29 09:16:48 +08:00
|
|
|
|
return await Task.FromResult(false);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<string>> AnalysisDataUnitAsync(List<string> hexMessageList)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<string> values = new List<string>();
|
|
|
|
|
|
values.Add(hexMessageList.GetReadTime(4, 3));
|
|
|
|
|
|
values.Add(hexMessageList.GetReadTime(7, 5));
|
|
|
|
|
|
int ratingCount = hexMessageList.GetRatingCount(12, 1);
|
|
|
|
|
|
values.Add(ratingCount.ToString());
|
|
|
|
|
|
int handlerNum = 13;
|
2025-05-08 15:12:37 +08:00
|
|
|
|
values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向有功总最大需量
|
2025-04-26 19:04:50 +08:00
|
|
|
|
handlerNum += 3 * (ratingCount + 1);//12
|
2025-05-08 15:12:37 +08:00
|
|
|
|
values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间
|
2025-04-26 19:04:50 +08:00
|
|
|
|
handlerNum += 4 * (ratingCount + 1);//28
|
2025-05-08 15:12:37 +08:00
|
|
|
|
values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向无功总最大需量
|
2025-04-26 19:04:50 +08:00
|
|
|
|
handlerNum += 3 * (ratingCount + 1);//48
|
2025-05-08 15:12:37 +08:00
|
|
|
|
values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向无功总最大需量发生时间
|
2025-04-26 19:04:50 +08:00
|
|
|
|
handlerNum += 4 * (ratingCount + 1);
|
|
|
|
|
|
return values;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 15:12:37 +08:00
|
|
|
|
private async Task<List<string>> GetDataAsync(List<string> data, int ratingCount, int len, string appendixName)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
List<string> values = new List<string>();
|
|
|
|
|
|
for (int i = 0; i < ratingCount + 1; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var arr = data.GetRange(0 + (i * len), len);
|
|
|
|
|
|
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>>(appendixName, arr, (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
values.Add(value.ToString());
|
|
|
|
|
|
});
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return values;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 15:12:37 +08:00
|
|
|
|
public AnalysisBaseDto<decimal?> GenerateFinalResult(List<string> data, string filedDesc,string dataType)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
2025-05-08 15:12:37 +08:00
|
|
|
|
List<AnalysisBaseDto<decimal?>> list = new List<AnalysisBaseDto<decimal?>>();
|
|
|
|
|
|
AnalysisBaseDto<decimal?> meter = new AnalysisBaseDto<decimal?>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
2025-05-07 11:53:50 +08:00
|
|
|
|
DeviceType = MeterTypeEnum.Ammeter
|
2025-04-26 19:04:50 +08:00
|
|
|
|
};
|
|
|
|
|
|
var errorCode = data[3].CheckErrorCode();
|
|
|
|
|
|
if (errorCode != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
meter.ValidData = false;
|
|
|
|
|
|
meter.ErrorCodeMsg = errorCode.Item2;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-05-08 15:12:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(decimal.TryParse(data[3], out decimal value))
|
|
|
|
|
|
{
|
|
|
|
|
|
meter.DataValue = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
string timeSpan = $"{DateTime.Now.Year}-{data[4].Substring(0, 2)}-{data[4].Substring(2, 2)} {data[4].Substring(4, 2)}:{data[4].Substring(6, 2)}:00";
|
|
|
|
|
|
if (DateTime.TryParse(timeSpan, out DateTime readingDate))
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
meter.TimeSpan = readingDate;
|
|
|
|
|
|
}
|
2025-05-12 16:09:53 +08:00
|
|
|
|
meter.ItemType = dataType;
|
2025-04-27 09:31:12 +08:00
|
|
|
|
meter.FiledDesc = filedDesc;
|
2025-05-12 16:09:53 +08:00
|
|
|
|
meter.FiledName = meter.ItemType.GetDataFieldByGatherDataType() ?? string.Empty;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
return meter;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|