2025-04-26 19:04:50 +08:00
|
|
|
|
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;
|
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.Common.Extensions;
|
2025-04-27 09:31:12 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
2025-05-12 16:09:53 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Consts;
|
2025-05-13 17:49:12 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Devices;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 5.13.2.4.139 F184:月冻结四象限无功电能示值(总、费率 1~M)
|
|
|
|
|
|
/// </summary>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public class AFN13_F184_Analysis : IAnalysisStrategy<TB3761>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN13_F184_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
|
|
|
|
|
private readonly DataStorage _dataStorage;
|
|
|
|
|
|
public AFN13_F184_Analysis(ILogger<AFN13_F184_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);
|
2025-05-13 17:49:12 +08:00
|
|
|
|
ArgumentNullException.ThrowIfNull(input.A.Code);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
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";
|
2025-05-13 17:49:12 +08:00
|
|
|
|
List<AnalysisBaseDto<decimal?>> list = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结四象限无功电能示值(总、费率 1~M)").IsValidData(new List<string>() { "0D_184", "0D_184_1", "0D_184_2", "0D_184_3", "0D_184_4" });
|
|
|
|
|
|
if (list.Count > 0)
|
2025-04-27 09:31:12 +08:00
|
|
|
|
{
|
2025-05-13 17:49:12 +08:00
|
|
|
|
// 查询设备信息
|
2025-06-03 11:58:17 +08:00
|
|
|
|
DeviceCacheInfo? deviceInfo = await _dataStorage.GetDeviceInfoAsync(input.A.Code, input.DA.Pn);
|
2025-05-13 17:49:12 +08:00
|
|
|
|
if (deviceInfo != null)
|
2025-04-27 09:31:12 +08:00
|
|
|
|
{
|
2025-05-13 17:49:12 +08:00
|
|
|
|
list.ForEach(item =>
|
2025-04-27 09:31:12 +08:00
|
|
|
|
{
|
2025-06-03 23:01:46 +08:00
|
|
|
|
item.ProjectId = deviceInfo.ProjectId;
|
2025-05-13 17:49:12 +08:00
|
|
|
|
item.DeviceId = deviceInfo.MeterId;
|
|
|
|
|
|
item.DatabaseBusiID = deviceInfo.DatabaseBusiID;
|
|
|
|
|
|
item.DeviceAddress = deviceInfo.MeterAddress;
|
|
|
|
|
|
item.FocusId = deviceInfo.FocusId;
|
2025-04-27 09:31:12 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-08 15:12:37 +08:00
|
|
|
|
UnitDataAnalysis<List<AnalysisBaseDto<decimal?>>> unitDataAnalysis = new UnitDataAnalysis<List<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,
|
2025-05-13 17:49:12 +08:00
|
|
|
|
Data = list,
|
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.Month,
|
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.SaveMultipleDataToIotDbAsync<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_184解析失败:{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>
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
2025-04-29 09:16:48 +08:00
|
|
|
|
await _analysisStrategyContext.ExecuteAsync<List<string>>(nameof(Appendix_A11), arr, (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
values.Add(value.ToString());
|
|
|
|
|
|
});
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return values;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|