2025-05-06 14:33:12 +08:00
|
|
|
|
using GatherService.WattMeter.AnalysisData.AFN_10H;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Helpers;
|
|
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Dto;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Interfaces;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.T37612012.Appendix;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol3761;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using static FreeSql.Internal.GlobalFilter;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H
|
|
|
|
|
|
{
|
2025-05-08 15:12:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 透抄 电网频率
|
|
|
|
|
|
/// </summary>
|
2025-05-06 14:33:12 +08:00
|
|
|
|
public class AFN16_F97_Analysis : IAnalysisStrategy<TB3761>
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN16_F97_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
|
|
|
|
|
private readonly DataStorage _dataStorage;
|
|
|
|
|
|
public AFN16_F97_Analysis(ILogger<AFN16_F97_Analysis> logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_analysisStrategyContext = analysisStrategyContext;
|
|
|
|
|
|
_dataStorage = dataStorage;
|
|
|
|
|
|
}
|
|
|
|
|
|
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
AnalysisBaseDto<decimal?> data = GenerateFinalResult(datas);
|
2025-05-06 14:33:12 +08:00
|
|
|
|
// 查询电表信息
|
2025-05-07 11:53:50 +08:00
|
|
|
|
AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.DeviceType.ToString(), "15");
|
2025-05-06 14:33:12 +08:00
|
|
|
|
if (ammeterInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
data.ProjectId = ammeterInfo.ProjectID;
|
2025-05-07 11:53:50 +08:00
|
|
|
|
data.DeviceId = ammeterInfo.MeterId;
|
2025-05-06 14:33:12 +08:00
|
|
|
|
data.DatabaseBusiID = ammeterInfo.DatabaseBusiID;
|
2025-05-08 09:25:41 +08:00
|
|
|
|
data.DeviceAddress = ammeterInfo.AmmerterAddress;
|
2025-05-06 14:33:12 +08:00
|
|
|
|
}
|
2025-05-08 15:12:37 +08:00
|
|
|
|
UnitDataAnalysis<AnalysisBaseDto<decimal?>> unitDataAnalysis = new UnitDataAnalysis<AnalysisBaseDto<decimal?>>
|
2025-05-06 14:33:12 +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,
|
|
|
|
|
|
HexMessage = input.BaseHexMessage.HexMessageString,
|
|
|
|
|
|
MessageId = input.MessageId,
|
2025-05-07 08:37:57 +08:00
|
|
|
|
TimeDensity = 1,//密度-间隔,
|
2025-05-06 14:33:12 +08:00
|
|
|
|
DensityUnit = DensityUnit.Hour,
|
|
|
|
|
|
ReceivedTime = input.ReceivedTime
|
|
|
|
|
|
};
|
2025-05-08 15:12:37 +08:00
|
|
|
|
await _dataStorage.SaveDataToIotDbAsync<decimal?>(unitDataAnalysis);
|
2025-05-06 14:33:12 +08:00
|
|
|
|
result?.Invoke(unitDataAnalysis);
|
|
|
|
|
|
return await Task.FromResult(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, $"10_97解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}");
|
|
|
|
|
|
return await Task.FromResult(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-08 15:12:37 +08:00
|
|
|
|
private AnalysisBaseDto<decimal?> GenerateFinalResult(List<string> data)
|
2025-05-06 14:33:12 +08:00
|
|
|
|
{
|
2025-05-08 15:12:37 +08:00
|
|
|
|
AnalysisBaseDto<decimal?> meter = new AnalysisBaseDto<decimal?>();
|
|
|
|
|
|
|
2025-05-06 14:33:12 +08:00
|
|
|
|
var errorCode = data[7].CheckErrorCode();
|
|
|
|
|
|
if (errorCode != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
meter.ValidData = false;
|
|
|
|
|
|
meter.ErrorCodeMsg = errorCode.Item2;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-05-08 15:12:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(decimal.TryParse(data[7], out decimal value))
|
|
|
|
|
|
meter.DataValue = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-06 14:33:12 +08:00
|
|
|
|
meter.DataType = "10_97";
|
|
|
|
|
|
meter.ValidData = data[2].Equals("91") || data[2].Equals("B1");
|
|
|
|
|
|
meter.FiledDesc = "电网频率";//"电网频率";
|
|
|
|
|
|
meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty;
|
|
|
|
|
|
return meter;
|
|
|
|
|
|
}
|
|
|
|
|
|
private async Task<List<string>> AnalysisDataUnitAsync(List<string> hexMessageList)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<string> values = new List<string>();
|
|
|
|
|
|
values.Add(hexMessageList.GetRange(4, 1)[0].HexToDec().ToString());//端口号
|
|
|
|
|
|
var contentLengthArr = hexMessageList.GetRange(5, 2);
|
|
|
|
|
|
contentLengthArr.Reverse();
|
|
|
|
|
|
int contentLength = string.Join("", contentLengthArr).HexToDec();
|
|
|
|
|
|
//TODO:转发内容
|
|
|
|
|
|
List<string> contentArr = hexMessageList.GetRange(7, contentLength);
|
|
|
|
|
|
//TODO:表地址
|
|
|
|
|
|
var addressList = contentArr.GetRange(1, 6);
|
|
|
|
|
|
addressList.Reverse();
|
|
|
|
|
|
var address = string.Join("", addressList);
|
|
|
|
|
|
values.Add(address);
|
|
|
|
|
|
//TODO:控制码
|
|
|
|
|
|
var controlCode = contentArr.GetRange(8, 1)[0];
|
|
|
|
|
|
values.Add(controlCode);
|
|
|
|
|
|
//TODO:长度
|
|
|
|
|
|
var len = contentArr.GetRange(9, 1)[0].HexToDec();
|
|
|
|
|
|
//values.Add(len.ToString());
|
|
|
|
|
|
//TODO:数据域
|
|
|
|
|
|
var dataField = contentArr.GetRange(10, len);
|
|
|
|
|
|
if (dataField.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
string dataMark = string.Join("",dataField.GetRange(0, 4).ReduceHex33(true));
|
|
|
|
|
|
values.Add(dataMark);//数据标识
|
|
|
|
|
|
var readValue = dataField.GetRange(4, len - 4).ReduceHex33(true);//值
|
|
|
|
|
|
await _analysisStrategyContext.ExecuteAsync<List<string>>($" Appendix_{dataMark}", readValue, (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
values.Add(value.ToString());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return values;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|