76 lines
2.9 KiB
C#
Raw Normal View History

2025-04-30 17:25:35 +08:00
using JiShe.CollectBus.Common.Enums;
2025-05-07 11:53:50 +08:00
using JiShe.CollectBus.IotSystems.Ammeters;
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
2025-04-30 17:25:35 +08:00
using JiShe.CollectBus.Protocol.Dto;
using JiShe.CollectBus.Protocol.Interfaces;
using JiShe.CollectBus.Protocol3761;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_02H
{
/// <summary>
/// 5.3.3.2 F2退出登录
/// </summary>
public class AFN2_F2_Analysis : IAnalysisStrategy<TB3761>
{
private readonly ILogger<AFN2_F2_Analysis> _logger;
2025-05-07 11:53:50 +08:00
private readonly DataStorage _dataStorage;
public AFN2_F2_Analysis(ILogger<AFN2_F2_Analysis> logger, DataStorage dataStorage)
{
_logger = logger;
2025-05-07 11:53:50 +08:00
_dataStorage = dataStorage;
}
2025-05-07 11:53:50 +08:00
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
{
try
{
2025-04-29 11:43:16 +08:00
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(input.A.Code);
2025-05-07 11:53:50 +08:00
var data = new AnalysisBaseDto<string>()
{
FiledDesc = "退出登录",
FiledName = "Type",
DataValue = "LogOut"
};
// 查询电表信息
AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(MeterTypeEnum.Focus.ToString(), "15");
if (ammeterInfo != null)
{
data.ProjectId = ammeterInfo.ProjectID;
data.DeviceId = ammeterInfo.FocusId;
data.DatabaseBusiID = ammeterInfo.DatabaseBusiID;
2025-05-08 09:25:41 +08:00
data.DeviceAddress = ammeterInfo.Address;
2025-05-07 11:53:50 +08:00
data.DeviceType = MeterTypeEnum.Focus;
}
UnitDataAnalysis<AnalysisBaseDto<string>> dto = new UnitDataAnalysis<AnalysisBaseDto<string>>
{
2025-04-29 11:43:16 +08:00
Code = input.A.Code,
AFN = input.AFN_FC.AFN,
Fn = input.DT.Fn,
Pn = input.DA.Pn,
2025-05-07 11:53:50 +08:00
Data = data,
2025-04-29 11:43:16 +08:00
HexMessage = input.BaseHexMessage.HexMessageString,
MessageId = input.MessageId,
2025-04-30 17:25:35 +08:00
ReceivedTime = input.ReceivedTime,
DensityUnit = DensityUnit.None,
TimeDensity = -1
};
result?.Invoke(dto);
2025-05-07 11:53:50 +08:00
await _dataStorage.SaveStatusToIotDbAsync<string>(dto);
return await Task.FromResult(true);
}
catch (Exception ex)
{
2025-04-29 11:43:16 +08:00
_logger.LogError(ex, $"02_2解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}");
}
2025-05-07 11:53:50 +08:00
return await Task.FromResult(false);
}
}
}