diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F1_Analysis.cs index d760e94..627b1da 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F1_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F1_Analysis.cs @@ -1,11 +1,12 @@ -using GatherService.WattMeter.AnalysisData.AFN_10H; -using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Consts; using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.IotSystems.Devices; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H.Ammeter; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H.Watermeter; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; using System; @@ -54,6 +55,11 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H { result?.Invoke(dto); }); + else if (value.Contains(F10TranspondMatch.ES190_DC)) + await _analysisStrategyContext.ExecuteAsync(nameof(ES190DC_Analysis), input, dto => + { + result?.Invoke(dto); + }); else { //TODO: 写入1条日志 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F101_Analysis.cs similarity index 96% rename from protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs rename to protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F101_Analysis.cs index 284aaab..6066e26 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F101_Analysis.cs @@ -11,7 +11,7 @@ using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; using System.Text; -namespace GatherService.WattMeter.AnalysisData.AFN_10H +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H.Ammeter { /// /// 5.16.1.2.1 F1:透明转发 读取SIM卡信息 @@ -64,7 +64,7 @@ namespace GatherService.WattMeter.AnalysisData.AFN_10H DataType = IOTDBDataTypeConst.Data, }; result?.Invoke(dto); - await _dataStorage.SaveDataToIotDbAsync(dto); + await _dataStorage.SaveDataToIotDbAsync(dto); return await Task.FromResult(true); } catch (Exception ex) diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F97_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F97_Analysis.cs similarity index 95% rename from protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F97_Analysis.cs rename to protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F97_Analysis.cs index 1df5604..04eee33 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F97_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F97_Analysis.cs @@ -1,5 +1,4 @@ -using DeviceDetectorNET.Parser.Device; -using GatherService.WattMeter.AnalysisData.AFN_10H; +using DeviceDetectorNET.Parser.Device; using JiShe.CollectBus.Common.Consts; using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; @@ -19,7 +18,7 @@ using System.Text; using System.Threading.Tasks; using static FreeSql.Internal.GlobalFilter; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H.Ammeter { /// /// 透抄 电网频率 @@ -74,7 +73,7 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H }; result?.Invoke(unitDataAnalysis); - await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); + await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); return await Task.FromResult(true); } @@ -134,7 +133,7 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H 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>($"Appendix_{dataMark}", readValue, (value) => + await _analysisStrategyContext.ExecuteAsync($"Appendix_{dataMark}", readValue, (value) => { values.Add(value.ToString()); }); diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F98_Analysis.cs similarity index 96% rename from protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs rename to protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F98_Analysis.cs index bb504e9..ae0512f 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Ammeter/AFN16_F98_Analysis.cs @@ -11,7 +11,7 @@ using JiShe.CollectBus.Protocol.T37612012.AnalysisData; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace GatherService.WattMeter.AnalysisData.AFN_10H +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H.Ammeter { /// /// 透明转发---跳合闸 @@ -42,7 +42,7 @@ namespace GatherService.WattMeter.AnalysisData.AFN_10H var data = new AnalysisBaseDto() { FiledDesc = "跳合闸", - DataValue = (datas[2].Equals("9C") || datas[2].Equals("94")) ? true : false, + DataValue = datas[2].Equals("9C") || datas[2].Equals("94") ? true : false, ItemType= "10_98", }; diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Watermeter/ES190DC_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Watermeter/ES190DC_Analysis.cs new file mode 100644 index 0000000..e831c9c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/Watermeter/ES190DC_Analysis.cs @@ -0,0 +1,130 @@ +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Common.Helpers; +using JiShe.CollectBus.IotSystems.Devices; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H.Ammeter; +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_10H.Watermeter +{ + /// + /// ES_190DC 4G水表读数解析 + /// + public class ES190DC_Analysis : IAnalysisStrategy + { + private readonly ILogger _logger; + private readonly DataStorage _dataStorage; + public ES190DC_Analysis(ILogger logger, DataStorage dataStorage) + { + _logger = logger; + _dataStorage = dataStorage; + } + + public async Task ExecuteAsync(TB3761 input, Action? result = null) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.A.Code); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List> list = GenerateFinalResult(input.UnitData.HexMessageList); + if (list.Count > 0) + { + // 查询设备信息 + DeviceInfo? deviceInfo = await _dataStorage.GetDeviceInfoAsync(input.A.Code, input.DA.Pn, list[0].DeviceAddress); + if (deviceInfo != null) + { + list.ForEach(item => + { + item.ProjectId = deviceInfo.ProjectID; + item.DeviceId = deviceInfo.MeterId; + item.DatabaseBusiID = deviceInfo.DatabaseBusiID; + item.DeviceAddress = deviceInfo.MeterAddress; + item.FocusId = deviceInfo.FocusId; + }); + } + } + UnitDataAnalysis>> unitDataAnalysis = new UnitDataAnalysis>> + { + 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 = list, + ReceivedHexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Hour, + ReceivedTime = input.ReceivedTime, + DataType = IOTDBDataTypeConst.Data + + }; + result?.Invoke(unitDataAnalysis); + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + + return await Task.FromResult(true); + } + catch (Exception ex) + { + _logger.LogError(ex, $"ES190DC 4G水表解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return await Task.FromResult(false); + } + } + + private List> GenerateFinalResult(List hexMessageList) + { + List> list = new List>(); + string address = string.Join("", hexMessageList.Skip(12).Take(7).Reverse()); + if (hexMessageList[19].Contains("81")) + { + int count = Convert.ToInt32(hexMessageList[36].HexToDec()); + DateTime startTime = Convert.ToDateTime($"{DateTime.Now.Year.ToString().Substring(0, 2)}{hexMessageList[41]}-{hexMessageList[40]}-{hexMessageList[39]} {hexMessageList[38]}:{hexMessageList[37]}:00"); + + List valueArr = hexMessageList.GetRange(42, count * 4); + int nextIndex = 0; + for (int i = 1; i <= count; i++) + { + AnalysisBaseDto meter = new AnalysisBaseDto(); + meter.DeviceType = MeterTypeEnum.WaterMeter; + meter.DeviceAddress = address; + var arr = valueArr.GetRange(nextIndex, 4); + var errorCode = arr[4].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + { + string val = $"{arr[3]}{arr[2]}{arr[1]}.{arr[0]}"; + if (decimal.TryParse(val, out decimal value)) + meter.DataValue = value; + } + string timeSpan = startTime.AddHours(i - 1).ToString("yyyy-MM-dd HH:mm:ss"); + if (DateTime.TryParse(timeSpan, out DateTime readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.ItemType = "10_250"; + meter.FiledDesc = "当前累积流量"; + meter.FiledName = meter.ItemType.GetDataFieldByGatherDataType() ?? string.Empty; + nextIndex += 4; + } + } + return list; + } + } +} diff --git a/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs b/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs index 604a294..219bd60 100644 --- a/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs +++ b/services/JiShe.CollectBus.Application/DataChannels/DataChannelManageService.cs @@ -19,7 +19,7 @@ using System.Linq; using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; +using Volo.Abp.DependencyInjection; namespace JiShe.CollectBus.DataChannels {