2025-04-30 17:25:35 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
2025-05-08 15:12:37 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Helpers;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
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-05-12 14:02:22 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.T37612012.AnalysisData;
|
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-26 19:04:50 +08:00
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 5.12.2.4.46 F49:当前电压、电流相位角
|
|
|
|
|
|
/// </summary>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public class AFN12_F49_Analysis : IAnalysisStrategy<TB3761>
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN12_F49_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
private readonly DataStorage _dataStorage;
|
|
|
|
|
|
public AFN12_F49_Analysis(ILogger<AFN12_F49_Analysis> logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage)
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_analysisStrategyContext = analysisStrategyContext;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
_dataStorage = dataStorage;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<string> DataType { get; set; } = new List<string>() { "Uab_Ua", "Ub", "Ucb_Uc", "Ia", "Ib", "Ic" };
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
List<string> data = await AnalysisDataUnitAsync(input.UnitData?.HexMessageList!);
|
|
|
|
|
|
List<string> remarks = new List<string>() { "Uab/Ua 相位角", "Ub 相位角", "Ucb/Uc 相位角", "Ia 相位角", "Ib 相位角", "Ic 相位角" };
|
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 = 0; i < data.Count; i++)
|
|
|
|
|
|
{
|
2025-05-08 15:12:37 +08:00
|
|
|
|
AnalysisBaseDto<decimal?> dto = new AnalysisBaseDto<decimal?>
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceType = MeterTypeEnum.Ammeter
|
|
|
|
|
|
};
|
2025-04-24 19:31:28 +08:00
|
|
|
|
var errorCodeInfo = data[i].CheckErrorCode();
|
|
|
|
|
|
if (errorCodeInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
dto.ValidData = false;
|
|
|
|
|
|
dto.ErrorCodeMsg = errorCodeInfo.Item2;
|
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))
|
|
|
|
|
|
dto.DataValue = value;
|
|
|
|
|
|
}
|
2025-04-24 19:31:28 +08:00
|
|
|
|
dto.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}_{DataType[i]}";
|
2025-05-08 17:20:07 +08:00
|
|
|
|
dto.FiledName = dto.DataType.GetDataFieldByGatherDataType() ?? string.Empty;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
dto.FiledDesc= remarks[i];
|
|
|
|
|
|
list.Add(dto);
|
|
|
|
|
|
}
|
2025-05-12 14:02:22 +08:00
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 查询电表信息
|
|
|
|
|
|
AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(list[0].DeviceType.ToString(), "15");
|
|
|
|
|
|
if (ammeterInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
list.ForEach(item =>
|
|
|
|
|
|
{
|
|
|
|
|
|
item.ProjectId = ammeterInfo.ProjectID;
|
|
|
|
|
|
item.DeviceId = ammeterInfo.MeterId;
|
|
|
|
|
|
item.DatabaseBusiID = ammeterInfo.DatabaseBusiID;
|
|
|
|
|
|
item.DeviceAddress = ammeterInfo.AmmerterAddress;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-08 15:12:37 +08:00
|
|
|
|
UnitDataAnalysis<List<AnalysisBaseDto<decimal?>>> unitDataAnalysis = new UnitDataAnalysis<List<AnalysisBaseDto<decimal?>>>
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
2025-04-29 09:16:48 +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,
|
2025-05-12 14:02:22 +08:00
|
|
|
|
ReceivedHexMessage = input.BaseHexMessage.HexMessageString,
|
2025-04-29 11:43:16 +08:00
|
|
|
|
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);
|
2025-05-12 14:02:22 +08:00
|
|
|
|
await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis);
|
2025-04-29 09:16:48 +08:00
|
|
|
|
return await Task.FromResult(true);
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, $"0C_49解析失败:{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>();
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var arr = hexMessageList.GetRange(4 + (i * 2), 2);
|
|
|
|
|
|
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_A5), arr, (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
values.Add(value.ToString());
|
|
|
|
|
|
});
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return values;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|