diff --git a/modules/JiShe.CollectBus.Kafka/Consumer/ConsumerService.cs b/modules/JiShe.CollectBus.Kafka/Consumer/ConsumerService.cs index 7f8c31c..fc853e9 100644 --- a/modules/JiShe.CollectBus.Kafka/Consumer/ConsumerService.cs +++ b/modules/JiShe.CollectBus.Kafka/Consumer/ConsumerService.cs @@ -169,7 +169,7 @@ namespace JiShe.CollectBus.Kafka.Consumer // 检查 Header 是否符合条件 if (!headersFilter.Match(result.Message.Headers)) { - //consumer.Commit(result); // 提交偏移量 + consumer.Commit(result); // 提交偏移量 // 跳过消息 continue; } @@ -252,7 +252,7 @@ namespace JiShe.CollectBus.Kafka.Consumer // 检查 Header 是否符合条件 if (!headersFilter.Match(result.Message.Headers)) { - //consumer.Commit(result); // 提交偏移量 + consumer.Commit(result); // 提交偏移量 // 跳过消息 continue; } @@ -356,7 +356,7 @@ namespace JiShe.CollectBus.Kafka.Consumer // 检查 Header 是否符合条件 if (!headersFilter.Match(result.Message.Headers)) { - //consumer.Commit(result); // 提交偏移量 + consumer.Commit(result); // 提交偏移量 // 跳过消息 continue; } @@ -493,7 +493,7 @@ namespace JiShe.CollectBus.Kafka.Consumer // 检查 Header 是否符合条件 if (!headersFilter.Match(result.Message.Headers)) { - //consumer.Commit(result); // 提交偏移量 + consumer.Commit(result); // 提交偏移量 // 跳过消息 continue; } diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs index 658985f..fd93dab 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F1_Analysis.cs @@ -6,7 +6,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_09H +namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_09H { /// /// 5.9.1.2 F1:终端版本信息 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs index 253f2d1..7be676d 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F129_Analysis.cs @@ -45,21 +45,6 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH MSA= input.A.A3.D1_D7, PSEQ= input.SEQ.PSEQ, }; - string taskMark = CommonHelper.GetTaskMark(unitDataAnalysis.AFN, unitDataAnalysis.Fn, unitDataAnalysis.Pn, unitDataAnalysis.MSA, unitDataAnalysis.PSEQ); - string scoreValue = $"{unitDataAnalysis.Code}.{taskMark}".Md5Fun(); - - var conditions = new List(); - conditions.Add(new QueryCondition() - { - Field = "ScoreValue", - Operator = "=", - IsNumber = false, - Value = scoreValue - }); - var taskSendInfo = await _dbProvider.QueryAsync(new IoTDBQueryOptions() { TableNameOrTreePath = DevicePathBuilder.GetTableName(), Conditions = conditions,PageIndex=0,PageSize=1}); - - - List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); List list = GenerateFinalResult(2, datas, "正向有功电能示值", input.AFN_FC.AFN, input.DT.Fn); unitDataAnalysis.Data= list; @@ -121,14 +106,5 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH } return list; } - - ///// - ///// 生成最终结果 - ///// - ///// - //public Task SaveIotDbAsync() - //{ - - //} } } diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs index 009e9d2..5ccd69b 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs @@ -1,4 +1,6 @@ -using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol.T37612012.Appendix; diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs index cd7b565..bb85538 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs @@ -1,47 +1,69 @@ -using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; 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.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.105 F149:上月(上一结算日)正向有功最大需量及发生时间(总、费率 1~M) /// - public class AFN12_F149_Analysis : IAnalysisStrategy> + public class AFN12_F149_Analysis : IAnalysisStrategy>> { private readonly ILogger _logger; private readonly AnalysisStrategyContext _analysisStrategyContext; - - public AFN12_F149_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) + private readonly DataStorage _dataStorage; + public AFN12_F149_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) { _logger = logger; _analysisStrategyContext = analysisStrategyContext; + _dataStorage= dataStorage; } - public async Task> ExecuteAsync(TB3761 input) + public async Task>> ExecuteAsync(TB3761 input) { try { ArgumentNullException.ThrowIfNull(input); ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); List datas = await AnalysisDataUnit(input.UnitData.HexMessageList); - AFN12_F149_AnalysisDto data = GenerateFinalResult(2, datas, "上月(上一结算日)正向有功最大需量及发生时间"); - data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; - UnitDataAnalysis unitDataAnalysis = new UnitDataAnalysis - { - Code = input.A?.Code, - AFN = input.AFN_FC?.AFN ?? 0, - Fn = input.DT?.Fn ?? 0, - Pn = input.DA?.Pn ?? 0, - Data = data - }; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + AnalysisBaseDto data = GenerateFinalResult(datas, dataType,"上月(上一结算日)正向有功最大需量及发生时间"); + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ProjectId = ammeterInfo.ProjectID; + data.MeterId = ammeterInfo.MeterId; + data.DatabaseBusiID=ammeterInfo.DatabaseBusiID; + data.MeterAddress= ammeterInfo.AmmerterAddress; + } + 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 = data, + HexMessage=input.BaseHexMessage.HexMessageString, + MessageId=input.MessageId, + TimeDensity=1, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); return await Task.FromResult(unitDataAnalysis); } catch (Exception ex) @@ -82,33 +104,43 @@ namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH } return values; } - public AFN12_F149_AnalysisDto GenerateFinalResult(int index, List data, string remark = "") + public AnalysisBaseDto GenerateFinalResult(List data,string dataType, string filedDesc = "") { - AFN12_F149_AnalysisDto dto = new AFN12_F149_AnalysisDto(); + AnalysisBaseDto dto = new AnalysisBaseDto(); var errorCodeInfo = data[2].CheckErrorCode(); if (errorCodeInfo != null) + { dto.ValidData = false; + dto.ErrorCodeMsg= errorCodeInfo.Item2; + } decimal.TryParse(data[2], out decimal value); dto.DataValue = value; - + dto.MeterType= MeterTypeEnum.Ammeter; //TODO:最大需量发生时间 errorCodeInfo = data[3].CheckErrorCode(); if (data[3].Length != 8 && errorCodeInfo != null) + { dto.ValidData = false; + dto.ErrorCodeMsg = errorCodeInfo.Item2; + } else - dto.TimeSpan = $"{DateTime.Now.Year}-{data[3].Substring(0, 2)}-{data[3].Substring(2, 2)} {data[3].Substring(4, 2)}:{data[3].Substring(6, 2)}:00"; - - - //TODO:时间标 - if (!DateTime.TryParse(dto.TimeSpan, out DateTime readingDate)) - dto.ValidData = false; - dto.ReadingDate = readingDate; + { + string timeSpan = $"{DateTime.Now.Year}-{data[3].Substring(0, 2)}-{data[3].Substring(2, 2)} {data[3].Substring(4, 2)}:{data[3].Substring(6, 2)}:00"; + + //TODO:时间标 + if (!DateTime.TryParse(timeSpan, out DateTime dataTime)) + dto.ValidData = false; + dto.DataTime = dataTime; + } if (DateTime.Now.Month.Equals(1))//如果为1月份,则日期减去1年 { - dto.ReadingDate = dto.ReadingDate.AddYears(-1); - dto.TimeSpan = dto.ReadingDate.ToString("yyyy-MM-dd HH:mm:ss"); + dto.DataTime = dto.DataTime.AddYears(-1); + dto.TimeSpan= dto.DataTime; } + + dto.FiledDesc = "上月(上一结算日)正向有功最大需量及发生时间"; + dto.FiledName = dataType.GetDataFieldByGatherDataType() ?? string.Empty; return dto; } diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs index b8113af..e3eaee7 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F188_Analysis.cs @@ -5,7 +5,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 水表抄读取 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs index 512aa3d..8a25c25 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs @@ -1,4 +1,6 @@ using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; @@ -6,7 +8,7 @@ using JiShe.CollectBus.Protocol.T37612012.Appendix; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.22 F25:当前三相及总有/无功功率、功率因数,三相电压、电流、零序电流、视在功率 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs index 1874bb5..a7be791 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs @@ -1,4 +1,6 @@ using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; @@ -6,7 +8,7 @@ using JiShe.CollectBus.Protocol.T37612012.Appendix; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.1 F2:终端日历时钟 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs index 3f33b9f..43be990 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs @@ -1,11 +1,13 @@ -using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; +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; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.30 F33:当前正向有/无功电能示值、一/四象限无功电能示值(总、费率 1~M,1≤M≤12) diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs index 4478952..aedb104 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs @@ -1,4 +1,6 @@ using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; @@ -6,7 +8,7 @@ using JiShe.CollectBus.Protocol.T37612012.Appendix; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.46 F49:当前电压、电流相位角 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F100_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F100_Analysis.cs new file mode 100644 index 0000000..177a9e9 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F100_Analysis.cs @@ -0,0 +1,108 @@ +using IdentityModel; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using Volo.Abp.Domain.Entities; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.78 F100:测量点反向无功总电能量曲线 + /// + public class AFN13_F100_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F100_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "反向无功总电能量"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_100解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A13), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F101_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F101_Analysis.cs new file mode 100644 index 0000000..cc7d3f8 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F101_Analysis.cs @@ -0,0 +1,102 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.79 F101:测量点正向有功总电能示值曲线 + /// + public class AFN13_F101_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F101_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "正向有功总电能示值"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_101解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F102_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F102_Analysis.cs new file mode 100644 index 0000000..b76b49a --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F102_Analysis.cs @@ -0,0 +1,103 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.80 F102:测量点正向无功总电能示值曲线 + /// + public class AFN13_F102_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F102_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "正向无功总电能示值"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_102解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F103_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F103_Analysis.cs new file mode 100644 index 0000000..832af3e --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F103_Analysis.cs @@ -0,0 +1,103 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.81 F103:测量点反向有功总电能示值曲线 + /// + public class AFN13_F103_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F103_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "反向有功总电能示值"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_103解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F104_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F104_Analysis.cs new file mode 100644 index 0000000..fa52755 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F104_Analysis.cs @@ -0,0 +1,103 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.82 F104:测量点反向无功总电能示值曲线 + /// + public class AFN13_F104_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F104_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "反向无功总电能示值"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_104解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F105_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F105_Analysis.cs new file mode 100644 index 0000000..69a2206 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F105_Analysis.cs @@ -0,0 +1,104 @@ +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.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.83 F105:测量点功率因数曲线 + /// + public class AFN13_F105_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F105_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "功率因数"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_105解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A5), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F106_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F106_Analysis.cs new file mode 100644 index 0000000..3b5c2ad --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F106_Analysis.cs @@ -0,0 +1,105 @@ +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.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.84 F106:测量点 A相功率因数曲线 + /// + public class AFN13_F106_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F106_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "A相功率因数"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_106解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A5), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F107_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F107_Analysis.cs new file mode 100644 index 0000000..7ac43b0 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F107_Analysis.cs @@ -0,0 +1,101 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.84 F107:测量点 B相功率因数曲线 + /// + public class AFN13_F107_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F107_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "B相功率因数"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_107解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A5), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F108_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F108_Analysis.cs new file mode 100644 index 0000000..f45a58e --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F108_Analysis.cs @@ -0,0 +1,102 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.84 F108:测量点 C相功率因数曲线 + /// + public class AFN13_F108_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F108_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "C相功率因数"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_107解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A5), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F11_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F11_Analysis.cs new file mode 100644 index 0000000..a534be9 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F11_Analysis.cs @@ -0,0 +1,160 @@ +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using System.Data; +using System.Diagnostics.Metrics; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.11 F11:抄表日冻结电能表正向有/无功最大需量及发生时间(总、费率 1~M,1≤M≤12) + /// + public class AFN13_F11_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F11_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + List> data = GenerateFinalResult(datas,3, dataType, "抄表日冻结电能表正向有功最大需量及发生时间"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_11解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 3));//日冻结类数据时标 Td_d + values.Add(hexMessageList.GetReadTime(7, 5));//终端抄表时间 + int ratingCount = hexMessageList.GetRatingCount(12, 1);//费率数 M(1≤M≤12) + values.Add(ratingCount.ToString()); + int handlerNum = 13; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3 * (ratingCount + 1);//12 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1);//28 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向无功总最大需量 + handlerNum += 3 * (ratingCount + 1);//48 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向无功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1); + return values; + } + + private async Task> GetDataAsync(List data, int ratingCount, int len, string appendixName) + { + List values = new List(); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = data.GetRange(0 + (i * len), len); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(nameof(Appendix_A5), arr); + values.Add(value.ToString()); + } + } + return values; + } + + public List> GenerateFinalResult(List data, int index, string dataType, string filedDesc = "") + { + List> list = new List>(); + int fCount = Convert.ToInt32(data[2]) + 1; + for (int i = 1; i <= 2; i++) + { + AnalysisBaseDto meter = new AnalysisBaseDto + { + MeterType = MeterTypeEnum.Ammeter + }; + int startIndex = i == 1 ? 3 : (3 + i * fCount); + + decimal value = 0; + var errorCode = data[startIndex].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[startIndex], out value); + + meter.DataValue = value; + string timeSpan = $"{DateTime.Now.Year}-{data[startIndex + fCount].Substring(0, 2)}-{data[startIndex + fCount].Substring(2, 2)} {data[startIndex + fCount].Substring(4, 2)}:{data[startIndex + fCount].Substring(6, 2)}:00"; + DateTime readingDate = DateTime.Now; + if (DateTime.TryParse(timeSpan, out readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.DataType = i == 1 ? dataType : $"{dataType}_{ i - 1}"; + filedDesc = i == 1 ? filedDesc : filedDesc.Replace("有功", "无功"); + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + + list.Add(meter); + } + return list; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F145_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F145_Analysis.cs new file mode 100644 index 0000000..03c2078 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F145_Analysis.cs @@ -0,0 +1,101 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.104 F145:测量点一象限无功总电能示值曲线 + /// + public class AFN13_F145_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F145_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "一象限无功电能示值"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_145解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F146_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F146_Analysis.cs new file mode 100644 index 0000000..043eed8 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F146_Analysis.cs @@ -0,0 +1,101 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.105 F146:测量点四象限无功总电能示值曲线 + /// + public class AFN13_F146_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F146_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "四象限无功电能示值"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_146解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F147_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F147_Analysis.cs new file mode 100644 index 0000000..f47b308 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F147_Analysis.cs @@ -0,0 +1,101 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.106 F147:测量点二象限无功总电能示值曲线 + /// + public class AFN13_F147_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F147_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "二象限无功电能示值"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_147解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F148_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F148_Analysis.cs new file mode 100644 index 0000000..2b2eefc --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F148_Analysis.cs @@ -0,0 +1,101 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.107 F148:测量点三象限无功总电能示值曲线 + /// + public class AFN13_F148_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F148_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "三象限无功电能示值"); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_148解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F161_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F161_Analysis.cs new file mode 100644 index 0000000..85217b2 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F161_Analysis.cs @@ -0,0 +1,107 @@ +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; +using JiShe.CollectBus.Common.Extensions; +using System; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.116 F161:日冻结正向有功电能示值(总、费率 1~M) + /// + public class AFN13_F161_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F161_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType,timeSpan, "正向有功总电能示值").IsValidData(new List() { "0D_161", "0D_161_1", "0D_161_2", "0D_161_3", "0D_161_4" }); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_161解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 5), 5); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A14), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F162_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F162_Analysis.cs new file mode 100644 index 0000000..0a39411 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F162_Analysis.cs @@ -0,0 +1,103 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.117 F162:日冻结正向无功(组合无功 1)电能示值(总、费率 1~M) + /// + public class AFN13_F162_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F162_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "正向无功(组合无功 1)电能示值").IsValidData(new List() { "0D_162", "0D_162_1", "0D_162_2", "0D_162_3", "0D_162_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_162解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F163_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F163_Analysis.cs new file mode 100644 index 0000000..03637b4 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F163_Analysis.cs @@ -0,0 +1,104 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.118 F163:日冻结反向有功电能示值(总、费率 1~M) + /// + public class AFN13_F163_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F163_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "反向有功总电能示值").IsValidData(new List() { "0D_163", "0D_163_1", "0D_163_2", "0D_163_3", "0D_163_4" }); + + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_163解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 5), 5); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A14), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F164_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F164_Analysis.cs new file mode 100644 index 0000000..0ef0ff5 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F164_Analysis.cs @@ -0,0 +1,105 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.119 F164:日冻结反向无功(组合无功 1)电能示值(总、费率 1~M) + /// + public class AFN13_F164_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F164_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "日冻结反向无功(组合无功 1)电能示值").IsValidData(new List() { "0D_164", "0D_164_1", "0D_164_2", "0D_164_3", "0D_164_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_164解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F165_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F165_Analysis.cs new file mode 100644 index 0000000..aa025a0 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F165_Analysis.cs @@ -0,0 +1,105 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.120 F165:日冻结一象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F165_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F165_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "日冻结一象限无功电能示值").IsValidData(new List() { "0D_165", "0D_165_1", "0D_165_2", "0D_165_3", "0D_165_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_165解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F166_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F166_Analysis.cs new file mode 100644 index 0000000..a97ab9a --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F166_Analysis.cs @@ -0,0 +1,104 @@ +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.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.121 F166:日冻结二象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F166_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F166_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "日冻结二象限无功电能示值").IsValidData(new List() { "0D_166", "0D_166_1", "0D_166_2", "0D_166_3", "0D_166_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_166解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F167_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F167_Analysis.cs new file mode 100644 index 0000000..49d1258 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F167_Analysis.cs @@ -0,0 +1,104 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.122 F167:日冻结三象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F167_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F167_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "日冻结三象限无功电能示值").IsValidData(new List() { "0D_167", "0D_167_1", "0D_167_2", "0D_167_3", "0D_167_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_167解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F168_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F168_Analysis.cs new file mode 100644 index 0000000..1f1ff37 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F168_Analysis.cs @@ -0,0 +1,104 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.123 F168:日冻结四象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F168_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F168_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "日冻结四象限无功电能示值").IsValidData(new List() { "0D_168", "0D_168_1", "0D_168_2", "0D_168_3", "0D_168_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_168解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3), + hexMessageList.GetReadTime(7, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = hexMessageList.GetRange(13 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F177_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F177_Analysis.cs new file mode 100644 index 0000000..46253e1 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F177_Analysis.cs @@ -0,0 +1,105 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.132 F177:月冻结正向有功电能示值(总、费率 1~M) + /// + public class AFN13_F177_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F177_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结正向有功电能示值").IsValidData(new List() { "0D_177", "0D_177_1", "0D_177_2", "0D_177_3", "0D_177_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_177解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 * 5), 5); + + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A14), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F178_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F178_Analysis.cs new file mode 100644 index 0000000..0ce4edc --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F178_Analysis.cs @@ -0,0 +1,105 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// F178:月冻结正向无功(组合无功 1)电能示值(总、费率 1~M) + /// + public class AFN13_F178_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F178_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结正向无功(组合无功 1)电能示值").IsValidData(new List() { "0D_178", "0D_178_1", "0D_178_2", "0D_178_3", "0D_178_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_178解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F179_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F179_Analysis.cs new file mode 100644 index 0000000..2d46789 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F179_Analysis.cs @@ -0,0 +1,104 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.134 F179:月冻结反向有功电能示值(总、费率 1~M) + /// + public class AFN13_F179_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F179_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "反向有功总电能示值").IsValidData(new List() { "0D_179", "0D_179_1", "0D_179_2", "0D_179_3", "0D_179_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_179解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 * 5), 5); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A14), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F180_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F180_Analysis.cs new file mode 100644 index 0000000..ea1c6c0 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F180_Analysis.cs @@ -0,0 +1,104 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.135 F180:月冻结反向无功(组合无功 1)电能示值(总、费率 1~M) + /// + public class AFN13_F180_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F180_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结反向无功(组合无功 1)电能示值").IsValidData(new List() { "0D_180", "0D_180_1", "0D_180_2", "0D_180_3", "0D_180_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_180解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F181_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F181_Analysis.cs new file mode 100644 index 0000000..aecb3e1 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F181_Analysis.cs @@ -0,0 +1,104 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.136 F181:月冻结一象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F181_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F181_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结一象限无功电能示值(总、费率 1~M)").IsValidData(new List() { "0D_181", "0D_181_1", "0D_181_2", "0D_181_3", "0D_181_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_181解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F182_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F182_Analysis.cs new file mode 100644 index 0000000..91ab2d1 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F182_Analysis.cs @@ -0,0 +1,103 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.137 F182:月冻结二象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F182_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F182_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结二象限无功电能示值(总、费率 1~M)").IsValidData(new List() { "0D_182", "0D_182_1", "0D_182_2", "0D_182_3", "0D_182_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_182解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F183_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F183_Analysis.cs new file mode 100644 index 0000000..bc201a8 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F183_Analysis.cs @@ -0,0 +1,103 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.138 F183:月冻结三象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F183_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F183_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结三象限无功电能示值(总、费率 1~M)").IsValidData(new List() { "0D_183", "0D_183_1", "0D_183_2", "0D_183_3", "0D_183_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_183解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F184_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F184_Analysis.cs new file mode 100644 index 0000000..74d7144 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F184_Analysis.cs @@ -0,0 +1,103 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.139 F184:月冻结四象限无功电能示值(总、费率 1~M) + /// + public class AFN13_F184_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F184_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List 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"; + List> data = datas.GenerateFinalResultTd_m(3, dataType, timeSpan, "月冻结四象限无功电能示值(总、费率 1~M)").IsValidData(new List() { "0D_184", "0D_184_1", "0D_184_2", "0D_184_3", "0D_184_4" }); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_184解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + 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 + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A11), arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F189_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F189_Analysis.cs new file mode 100644 index 0000000..9c58696 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F189_Analysis.cs @@ -0,0 +1,113 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.144 F189:抄表日冻结正向有功最大需量及发生时间(总、费率 1~M) + /// + public class AFN13_F189_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F189_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string timeSpan = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_d(3, dataType, timeSpan, "抄表日冻结正向有功最大需量及发生时间"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_189解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 3)); + values.Add(hexMessageList.GetReadTime(7, 5)); + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + int handlerNum = 13; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3), ratingCount, 3, nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4), ratingCount, 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + return values; + } + + private async Task> GetDataAsync(List data, int ratingCount, int len, string appendixName) + { + List values = new List(); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = data.GetRange(0 + (i * len), len); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(appendixName, arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F190_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F190_Analysis.cs new file mode 100644 index 0000000..0289fad --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F190_Analysis.cs @@ -0,0 +1,143 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using System.Data; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Common.Consts; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.145 F190:抄表日冻结正向无功最大需量及发生时间(总、费率 1~M) + /// + public class AFN13_F190_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F190_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + + AnalysisBaseDto data = GenerateFinalResult(datas, "抄表日冻结正向无功最大需量及发生时间"); + data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ProjectId = ammeterInfo.ProjectID; + data.MeterId = ammeterInfo.MeterId; + data.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + data.MeterAddress = ammeterInfo.AmmerterAddress; + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_190解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 3)); + values.Add(hexMessageList.GetReadTime(7, 5)); + int ratingCount = hexMessageList.GetRatingCount(12, 1); + values.Add(ratingCount.ToString()); + int handlerNum = 13; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3 * (ratingCount + 1);//12 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1);//28 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向无功总最大需量 + handlerNum += 3 * (ratingCount + 1);//48 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向无功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1); + return values; + } + + private async Task> GetDataAsync(List data, int ratingCount, int len, string appendixName) + { + List values = new List(); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = data.GetRange(0 + (i * len), len); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(appendixName, arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + + public AnalysisBaseDto GenerateFinalResult(List data, string filedDesc = "") + { + List> list = new List>(); + AnalysisBaseDto meter = new AnalysisBaseDto + { + MeterType = MeterTypeEnum.Ammeter + }; + + decimal value = 0; + var errorCode = data[3].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[3], out value); + meter.DataValue = value; + + string timeSpan = $"{DateTime.Now.Year}-{data[4].Substring(0, 2)}-{data[4].Substring(2, 2)} {data[4].Substring(4, 2)}:{data[4].Substring(6, 2)}:00";//$"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)}"; + DateTime readingDate = DateTime.Now; + if (DateTime.TryParse(timeSpan, out readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + return meter; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F193_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F193_Analysis.cs new file mode 100644 index 0000000..1b23303 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F193_Analysis.cs @@ -0,0 +1,132 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Common.Consts; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.148 F193:月冻结正向有功最大需量及发生时间(总、费率 1~M) + /// + public class AFN13_F193_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F193_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + + AnalysisBaseDto data = GenerateFinalResult(datas, "月冻结正向有功最大需量及发生时间"); + data.DataType= $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ProjectId = ammeterInfo.ProjectID; + data.MeterId = ammeterInfo.MeterId; + data.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + data.MeterAddress = ammeterInfo.AmmerterAddress; + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_193解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 2), + hexMessageList.GetReadTime(6, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(11, 1); + values.Add(ratingCount.ToString()); + int handlerNum = 12; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3), 3, nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4), 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + return values; + } + + private async Task> GetDataAsync(List data, int len, string appendixName) + { + List values = new List(); + var errorCode = data.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(appendixName, data); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + return values; + } + public AnalysisBaseDto GenerateFinalResult(List data, string filedDesc = "") + { + AnalysisBaseDto meter = new AnalysisBaseDto + { + MeterType = MeterTypeEnum.Ammeter, + }; + + decimal value = 0; + var errorCode = data[3].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[3], out value); + meter.DataValue = value; + + string timeSpan = $"{data[0].Substring(0, 4)}-{data[4].Substring(0, 2)}-{data[4].Substring(2, 2)} {data[4].Substring(4, 2)}:{data[4].Substring(6, 2)}:00";//$"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)}"; + DateTime readingDate = DateTime.Now; + if (DateTime.TryParse(timeSpan, out readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + return meter; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F195_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F195_Analysis.cs new file mode 100644 index 0000000..cb3f6b8 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F195_Analysis.cs @@ -0,0 +1,132 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.150 F195:月冻结反向有功最大需量及发生时间(总、费率 1~M) + /// + public class AFN13_F195_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F195_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + + AnalysisBaseDto data = GenerateFinalResult(datas, "月冻结反向有功最大需量及发生时间"); + data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ProjectId = ammeterInfo.ProjectID; + data.MeterId = ammeterInfo.MeterId; + data.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + data.MeterAddress = ammeterInfo.AmmerterAddress; + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Month + }; + await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_195解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 2), + hexMessageList.GetReadTime(6, 5) + }; + int ratingCount = hexMessageList.GetRatingCount(11, 1); + values.Add(ratingCount.ToString()); + int handlerNum = 12; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3), 3,nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4), 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + return values; + } + + private async Task> GetDataAsync(List data, int len, string appendixName) + { + List values = new List(); + var errorCode = data.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(appendixName, data); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + return values; + } + public AnalysisBaseDto GenerateFinalResult(List data, string filedDesc = "") + { + AnalysisBaseDto meter = new AnalysisBaseDto + { + MeterType = MeterTypeEnum.Ammeter + }; + + decimal value = 0; + var errorCode = data[3].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[3], out value); + meter.DataValue = value; + + string timeSpan = $"{data[0].Substring(0, 4)}-{data[4].Substring(0, 2)}-{data[4].Substring(2, 2)} {data[4].Substring(4, 2)}:{data[4].Substring(6, 2)}:00";//$"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)}"; + DateTime readingDate = DateTime.Now; + if (DateTime.TryParse(timeSpan, out readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + return meter; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F19_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F19_Analysis.cs new file mode 100644 index 0000000..bb375c5 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F19_Analysis.cs @@ -0,0 +1,153 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using System.Data; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.15 F19:月冻结电能表正向有/无功最大需量及发生时间(总、费率 1~M,1≤M≤12) + /// + public class AFN13_F19_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F19_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + List> data = GenerateFinalResult(datas, dataType, "月冻结电能表正向有功最大需量及发生时间"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_19解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetReadTime(4, 2));//月冻结类数据时标 Td_m + values.Add(hexMessageList.GetReadTime(6, 5));// + int ratingCount = hexMessageList.GetRatingCount(11, 1); + values.Add(ratingCount.ToString()); + int handlerNum = 12; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3 * (ratingCount + 1); + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1); + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向无功总最大需量 + handlerNum += 3 * (ratingCount + 1); + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向无功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1); + return values; + } + + private async Task> GetDataAsync(List data, int ratingCount, int len, string appendixName) + { + List values = new List(); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = data.GetRange(0 + (i * len), len); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(appendixName, arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + + public List> GenerateFinalResult(List data, string dataType,string filedDesc = "") + { + List> list = new List>(); + int fCount = Convert.ToInt32(data[2]) + 1; + for (int i = 1; i <= 2; i++) + { + AnalysisBaseDto meter = new AnalysisBaseDto(); + meter.MeterType= MeterTypeEnum.Ammeter; + int startIndex = i == 1 ? 3 : (3 + i * fCount); + decimal value = 0; + var errorCode = data[startIndex].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[startIndex], out value); + meter.DataValue = value; + //2021 01 15 + string timeSpan = $"{DateTime.Now.Year}-{data[startIndex + fCount].Substring(0, 2)}-{data[startIndex + fCount].Substring(2, 2)} {data[startIndex + fCount].Substring(4, 2)}:{data[startIndex + fCount].Substring(6, 2)}:00"; + DateTime readingDate = DateTime.Now; + if (DateTime.TryParse(timeSpan, out readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.DataType = i == 1 ? dataType : $"{dataType}_{ i - 1}"; + + filedDesc = i == 1 ? filedDesc : filedDesc.Replace("有功", "无功"); + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + list.Add(meter); + } + return list; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F3_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F3_Analysis.cs new file mode 100644 index 0000000..ef838b3 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F3_Analysis.cs @@ -0,0 +1,180 @@ +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; +using System.Data; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using Volo.Abp.Domain.Entities; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Common.Consts; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.3 F3:日冻结正向有/无功最大需量及发生时间(总、费率 1~M,1≤M≤12) + /// + public class AFN13_F3_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F3_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + //冻结数据时标 + var time = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + + List> data = GenerateFinalResult(datas,dataType, "日冻结正向有/无功最大需量及发生时间"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_3解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3),//日冻结类数据时标 Td_d + hexMessageList.GetReadTime(7, 5)//终端抄表时间 + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1);//费率数 M(1≤M≤12) + values.Add(ratingCount.ToString()); + int handlerNum = 13; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3 * (ratingCount + 1);//12 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1);//28 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向无功总最大需量 + handlerNum += 3 * (ratingCount + 1);//48 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向无功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1); + return values; + } + + private async Task> GetDataAsync(List data, int ratingCount, int len, string appendixName) + { + List values = new List(); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = data.GetRange(0 + (i * len), len); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(appendixName, arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + + public List> GenerateFinalResult(List data,string dataType, string filedDesc = "") + { + List> list = new List>(); + int fCount = Convert.ToInt32(data[2]) + 1; + for (int i = 1; i <= 2; i++) + { + try + { + AnalysisBaseDto meter = new AnalysisBaseDto + { + MeterType = MeterTypeEnum.Ammeter + }; + int startIndex = i == 1 ? 3 : (3 + i * fCount); + + var errorCode = data[startIndex].CheckErrorCode(); + if (errorCode != null) + meter.ValidData = false; + decimal.TryParse(data[startIndex], out decimal value);//decimal.TryParse(data[startIndex], out value); + meter.DataValue = value; + + //TODO:日冻结类数据时标Td 20210824 + var dataTime = string.Empty; + errorCode = data[0].CheckErrorCode(); + if (data[0].Length == 8 && errorCode is null) + dataTime = $"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} 00:00:00"; + if (!DateTime.TryParse(dataTime, out DateTime readingDate)) + meter.ValidData = false; + meter.TimeSpan = readingDate;// + + //TODO:最大需量发生时间 + errorCode = data[startIndex + fCount].CheckErrorCode(); + if (errorCode != null && data[startIndex + fCount].Length != 8) + meter.ValidData = false; + else + { + string timeSpan = $"{data[0].Substring(0, 4)}-{data[startIndex + fCount].Substring(0, 2)}-{data[startIndex + fCount].Substring(2, 2)} {data[startIndex + fCount].Substring(4, 2)}:{data[startIndex + fCount].Substring(6, 2)}:00"; + if (!DateTime.TryParse(timeSpan, out DateTime tsField)) + meter.ValidData = false; + else + meter.TimeSpan=tsField; + } + + meter.DataType = i == 1 ? dataType : $"{dataType}_{ i - 1}"; + filedDesc = i == 1 ? filedDesc : filedDesc.Replace("有功", "无功"); + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + list.Add(meter); + } + catch + { + } + } + if (list.Count == 0) + throw new Exception("错误数据"); + + return list; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F4_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F4_Analysis.cs new file mode 100644 index 0000000..8391e08 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F4_Analysis.cs @@ -0,0 +1,173 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using AutoMapper.Internal.Mappers; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Common.Consts; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.4 F4:日冻结反向有/无功最大需量及发生时间(总、费率 1~M,1≤M≤12) + /// + public class AFN13_F4_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F4_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + //冻结数据时标 + var time = $"{datas[0].Substring(0, 4)}-{datas[0].Substring(4, 2)}-{datas[0].Substring(6, 2)} 00:00:00"; + + List> data = GenerateFinalResult(datas, dataType, "日冻结反向有/无功最大需量及发生时间"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔, + DensityUnit = DensityUnit.Day + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_4解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List + { + hexMessageList.GetReadTime(4, 3),//日冻结类数据时标 Td_d + hexMessageList.GetReadTime(7, 5)//终端抄表时间 + }; + int ratingCount = hexMessageList.GetRatingCount(12, 1);//费率数 M(1≤M≤12) + values.Add(ratingCount.ToString()); + int handlerNum = 13; + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向有功总最大需量 + handlerNum += 3 * (ratingCount + 1);//12 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向有功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1);//28 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 3 * (ratingCount + 1)), ratingCount, 3, nameof(Appendix_A23)));//正向无功总最大需量 + handlerNum += 3 * (ratingCount + 1);//48 + values.AddRange(await GetDataAsync(hexMessageList.GetRange(handlerNum, 4 * (ratingCount + 1)), ratingCount, 4, nameof(Appendix_A17)));//正向无功总最大需量发生时间 + handlerNum += 4 * (ratingCount + 1); + return values; + } + + private async Task> GetDataAsync(List data, int ratingCount, int len, string appendixName) + { + List values = new List(); + for (int i = 0; i < ratingCount + 1; i++) + { + var arr = data.GetRange(0 + (i * len), len); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, T>(appendixName, arr); //从第10个开始,每加5个字节为下一个值的开始 + values.Add(value.ToString()); + } + } + return values; + } + + public List> GenerateFinalResult(List data,string dataType, string filedDesc = "") + { + List> list = new List>(); + int fCount = Convert.ToInt32(data[2]) + 1; + for (int i = 1; i <= 2; i++) + { + AnalysisBaseDto meter = new AnalysisBaseDto + { + MeterType = MeterTypeEnum.Ammeter + }; + int startIndex = i == 1 ? 3 : (3 + i * fCount); + + var errorCode = data[startIndex].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + decimal.TryParse(data[startIndex], out decimal value);//decimal.TryParse(data[startIndex], out value); + meter.DataValue = value; + + //TODO:日冻结类数据时标Td 20210824 + var dataTime = string.Empty; + errorCode = data[0].CheckErrorCode(); + if (data[0].Length == 8 && errorCode is null) + dataTime = $"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} 00:00:00"; + if (!DateTime.TryParse(dataTime, out DateTime readingDate)) + meter.ValidData = false; + meter.TimeSpan = readingDate; + + //TODO:最大需量发生时间 + errorCode = data[startIndex + fCount].CheckErrorCode(); + if (errorCode != null && data[startIndex + fCount].Length != 8) + meter.ValidData = false; + else + { + string timeSpan = $"{data[0].Substring(0, 4)}-{data[startIndex + fCount].Substring(0, 2)}-{data[startIndex + fCount].Substring(2, 2)} {data[startIndex + fCount].Substring(4, 2)}:{data[startIndex + fCount].Substring(6, 2)}:00"; + if (!DateTime.TryParse(timeSpan, out DateTime tsField)) + meter.ValidData = false; + else + meter.TimeSpan = tsField; + } + meter.DataType = i == 1 ? dataType : $"{dataType}_{ i - 1}"; + filedDesc = i == 1 ? filedDesc : filedDesc.Replace("有功", "无功"); + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + list.Add(meter); + + } + return list; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F81_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F81_Analysis.cs new file mode 100644 index 0000000..ea4949c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F81_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.60 F81:测量点有功功率曲线 + /// + public class AFN13_F81_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F81_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "有功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_81解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F82_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F82_Analysis.cs new file mode 100644 index 0000000..a20eb9b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F82_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.61 F82:测量点 A相有功功率曲线 + /// + public class AFN13_F82_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F82_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "A相有功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_82解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F83_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F83_Analysis.cs new file mode 100644 index 0000000..e4e0892 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F83_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.61 F83:测量点 B相有功功率曲线 + /// + public class AFN13_F83_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F83_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "B相有功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_83解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F84_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F84_Analysis.cs new file mode 100644 index 0000000..fdcdc50 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F84_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.61 F84:测量点 C相有功功率曲线 + /// + public class AFN13_F84_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F84_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "C相有功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_84解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F85_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F85_Analysis.cs new file mode 100644 index 0000000..c74bf58 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F85_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.64 F85:测量点无功功率曲线 + /// + public class AFN13_F85_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F85_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "无功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_85解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F86_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F86_Analysis.cs new file mode 100644 index 0000000..b602bb6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F86_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.65 F86:测量点 A相无功功率曲线 + /// + public class AFN13_F86_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F86_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "A相无功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_86解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F87_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F87_Analysis.cs new file mode 100644 index 0000000..c7c6853 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F87_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.66 F87:测量点 B相无功功率曲线 + /// + public class AFN13_F87_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F87_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "B相无功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_87解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F88_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F88_Analysis.cs new file mode 100644 index 0000000..1b46937 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F88_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.67 F88:测量点 C相无功功率曲线 + /// + public class AFN13_F88_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F88_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "C相无功功率曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_88解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A9), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F89_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F89_Analysis.cs new file mode 100644 index 0000000..9d36520 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F89_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.68 F89:测量点 A相电压曲线 + /// + public class AFN13_F89_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F89_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "A相电压曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_89解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A7), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F90_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F90_Analysis.cs new file mode 100644 index 0000000..5e877b6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F90_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.68 F89:测量点 B相电压曲线 + /// + public class AFN13_F90_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F90_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "B相电压曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_90解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A7), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F91_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F91_Analysis.cs new file mode 100644 index 0000000..b108759 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F91_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.68 F89:测量点 C相电压曲线 + /// + public class AFN13_F91_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F91_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "C相电压曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_91解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 2), 2); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A7), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F92_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F92_Analysis.cs new file mode 100644 index 0000000..a3bec22 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F92_Analysis.cs @@ -0,0 +1,101 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.71 F92:测量点 A相电流曲线 + /// + public class AFN13_F92_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F92_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "A相电流曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_92解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A25), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F93_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F93_Analysis.cs new file mode 100644 index 0000000..1171649 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F93_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.72 F93:测量点 B相电流曲线 + /// + public class AFN13_F93_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F93_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "B相电流曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_93解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A25), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F94_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F94_Analysis.cs new file mode 100644 index 0000000..0374018 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F94_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.73 F94:测量点 C相电流曲线 + /// + public class AFN13_F94_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F94_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "C相电流曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_94解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A25), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F95_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F95_Analysis.cs new file mode 100644 index 0000000..58269ec --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F95_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.74 F95:测量点零序电流曲线 + /// + public class AFN13_F95_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F95_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "测量点零序电流曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_95解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 3), 3); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A25), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F97_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F97_Analysis.cs new file mode 100644 index 0000000..b02b807 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F97_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.75 F97:测量点正向有功总电能量曲线 + /// + public class AFN13_F97_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F97_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "正向有功总电能量曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_97解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A13), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F98_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F98_Analysis.cs new file mode 100644 index 0000000..b827871 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F98_Analysis.cs @@ -0,0 +1,101 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.76 F98:测量点正向无功总电能量曲线 + /// + public class AFN13_F98_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F98_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "正向无功总电能量曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_98解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A13), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F99_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F99_Analysis.cs new file mode 100644 index 0000000..6e52836 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F99_Analysis.cs @@ -0,0 +1,102 @@ +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; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.77 F99:测量点反向有功总电能量曲线 + /// + public class AFN13_F99_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F99_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "反向有功总电能量曲线"); + if (data.Count > 0) + { + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data[0].MeterType.ToString(), "15"); + if (ammeterInfo != null) + { + data.ForEach(item => + { + item.ProjectId = ammeterInfo.ProjectID; + item.MeterId = ammeterInfo.MeterId; + item.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + item.MeterAddress = ammeterInfo.AmmerterAddress; + }); + } + } + 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 = data, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + await _dataStorage.SaveMultipleDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_99解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A13), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs new file mode 100644 index 0000000..ecb3a3e --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs @@ -0,0 +1,81 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AFN_00H; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0EH +{ + /// + /// 请求重要事件 + /// Item1=停电事件 + /// Item2=上电事件 + /// + public class AFN14_F1_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + + public AFN14_F1_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task>> ExecuteAsync(TB3761 tB3761) + { + try + { + ArgumentNullException.ThrowIfNull(nameof(tB3761)); + ArgumentNullException.ThrowIfNull(nameof(tB3761.UnitData.HexMessageList)); + int erc = tB3761.UnitData.HexMessageList![8].HexToDec(); + bool isOnOffPower = erc.Equals(14) ? true : false; + if (!isOnOffPower) + { + throw new Exception($"ERC{erc}非上掉电事件"); + } + UnitDataAnalysis> dto = new UnitDataAnalysis> + { + Code = tB3761.A.Code!, + AFN = tB3761.AFN_FC.AFN, + Fn = tB3761.DT.Fn, + Pn = tB3761.DA.Pn, + Data = AnalysisDataUnit(tB3761.UnitData.HexMessageList) + }; + // meterData.DataType = "0E_1"; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0E_1解析失败:{tB3761.A.Code}-{tB3761.DT.Fn}-{tB3761.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private Tuple AnalysisDataUnit(List hexMessageList) + { + /// Item1=停电事件 + /// Item2=上电事件 + return Tuple.Create(HandlerTime(hexMessageList.GetRange(10, 5)), HandlerTime(hexMessageList.GetRange(15, 5))); + } + /// + /// /解析时间 + /// + /// + /// 时间验证失败是否默认为当前时间 + /// + private string HandlerTime(List times) + { + var time = string.Empty; + try + { + times.Reverse(); + time = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{times[0]}-{times[1]}-{times[2]} {times[3]}:{times[4]}:00"; + + } + catch { } + return time; + } + } +} + diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs new file mode 100644 index 0000000..2f091c2 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs @@ -0,0 +1,58 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AFN_09H; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using System.Text; + +namespace GatherService.WattMeter.AnalysisData.AFN_10H +{ + /// + /// 5.16.1.2.1 F1:透明转发 读取SIM卡信息 + /// + public class AFN16_F101_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN16_F101_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = AnalysisDataUnit(input.UnitData.HexMessageList) //SIM卡 + }; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"10_101解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + private string AnalysisDataUnit(List hexMessageList) + { + //TODO:转发内容 + var dataArray = hexMessageList.Skip(18).ToList(); + var contentLengthArr = dataArray.Skip(1).Take(2).ToList(); + contentLengthArr.Reverse(); + int contentLength = string.Join("", contentLengthArr).HexToDec(); + var dataField = dataArray.Skip(3).Take(contentLength).ToList(); + var sim = string.Join("", dataField).TrimStart('0'); + return sim.Length != 20 ? "" : sim; + } + } +} 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 new file mode 100644 index 0000000..9f9b120 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F1_Analysis.cs @@ -0,0 +1,68 @@ +using GatherService.WattMeter.AnalysisData.AFN_10H; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +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; +using TouchSocket.Core; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H +{ + /// + /// 5.16 数据转发(AFN=10H) + /// + public class AFN16_F1_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN16_F1_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code!, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = AnalysisDataUnit(input.UnitData.HexMessageList) + }; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"10_101解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + + + private string AnalysisDataUnit(List hexMessageList) + { + // TODO: 待定,等确认如何匹配规则 + string value = string.Join(" ", hexMessageList); + if (value.Contains(F10TranspondMatch.ReadNormal)) + { + if (value.Contains(F10TranspondMatch.PowerHz))//电网频率 + return "AFN16_F97_Analysis"; + //else if (value.Contains(F10TranspondMatch.ReadData))//读取电表地址 + // result = "AFN16_F105_Analysis"; + } + return ""; + } + + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs new file mode 100644 index 0000000..d919425 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs @@ -0,0 +1,107 @@ +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.Protocol.T37612012.AnalysisData.AFN_0DH; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Common.Extensions; + +namespace GatherService.WattMeter.AnalysisData.AFN_10H +{ + /// + /// 透明转发---跳合闸 + /// + public class AFN16_F98_Analysis : IAnalysisStrategy> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN16_F98_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = AnalysisDataUnit(input.UnitData.HexMessageList); + + // 查询电表信息 + //AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15"); + //if (ammeterInfo != null) + //{ + // data.ProjectId = ammeterInfo.ProjectID; + // data.MeterId = ammeterInfo.MeterId; + // data.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + // data.MeterAddress = ammeterInfo.AmmerterAddress; + //} + 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 = (datas[2].Equals("9C") || datas[2].Equals("94")) ? true : false, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔分钟数, + DensityUnit = DensityUnit.Second + }; + //await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"10_98跳合闸解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private List AnalysisDataUnit(List hexMessageList) + { + List values = new List(); + 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 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].DataConvert(16); + //values.Add(len.ToString()); + //TODO:数据域 + //var dataField = contentArr.GetRange(10, len); + //if (dataField.Count > 0) + //{ + // string dataMark = string.Join("", CalculateErrControl(dataField.GetRange(0, 4))); + // values.Add(dataMark);//数据标识 + // var readValue = CalculateErrControl(dataField.GetRange(4, len - 4));//值 + // var valueData = GetValue>(readValue, (AppendixEnums)Enum.Parse(typeof(AppendixEnums), dataMark)); + // values.AddRange(valueData); + //} + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs index 574a207..6914c3c 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs @@ -1,17 +1,247 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using JiShe.CollectBus.Common; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Encrypt; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Common.Helpers; +using JiShe.CollectBus.IoTDB.Context; +using JiShe.CollectBus.IoTDB.Interface; +using JiShe.CollectBus.IoTDB.Model; +using JiShe.CollectBus.IoTDB.Options; +using JiShe.CollectBus.IoTDB.Provider; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.IotSystems.MeterReadingRecords; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; +using Volo.Abp.Guids; namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData { public class DataStorage:ITransientDependency { - public DataStorage() - { - + private readonly IGuidGenerator _guidGenerator; + private readonly IIoTDbProvider _dbProvider; + private readonly ServerApplicationOptions _applicationOptions; + private readonly IoTDBRuntimeContext _runtimeContext; + public DataStorage(IIoTDbProvider dbProvider, IOptions applicationOptions, IGuidGenerator guidGenerator, IoTDBRuntimeContext runtimeContext) + { + _dbProvider= dbProvider; + _applicationOptions = applicationOptions.Value; + _guidGenerator= guidGenerator; + _runtimeContext= runtimeContext; } + + /// + /// 获取缓存电表信息 + /// + /// + /// + /// + public async Task GetMeterInfoAsync(string meterType,string timeDensity="15") + { + var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, _applicationOptions.SystemType, _applicationOptions.ServerTagName, meterType, timeDensity)}"; + return await Task.FromResult(new AmmeterInfo()); + } + + /// + /// 保存数据到IotDb + /// + /// + /// + /// + public async Task SaveDataToIotDbAsync(UnitDataAnalysis> analysisBaseDto) + { + var data = analysisBaseDto.Data!; + + string taskMark = CommonHelper.GetTaskMark(analysisBaseDto.AFN, analysisBaseDto.Fn, analysisBaseDto.Pn, analysisBaseDto.MSA, analysisBaseDto.PSEQ); + string scoreValue = $"{analysisBaseDto.Code}.{taskMark}".Md5Fun(); + + var conditions = new List(); + conditions.Add(new QueryCondition() + { + Field = "ScoreValue", + Operator = "=", + IsNumber = false, + Value = scoreValue + }); + conditions.Add(new QueryCondition() + { + Field = "TaskMark", + Operator = "=", + IsNumber = false, + Value = taskMark + }); + conditions.Add(new QueryCondition() + { + Field = "IsReceived", + Operator = "=", + IsNumber = false, + Value = false + }); + var meter = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{data.MeterId}", + DeviceType = $"{data.MeterType}", + ProjectId = $"{data.ProjectId}", + Timestamps = data.TimeSpan.GetDateTimeOffset().ToUnixTimeMilliseconds(), + SingleMeasuring = new Tuple(data.FiledName ?? string.Empty, data.DataValue ?? default) + }; + _runtimeContext.UseTableSessionPool = true; // 使用表模型池 + var taskSendInfo = await _dbProvider.QueryAsync(new IoTDBQueryOptions() { TableNameOrTreePath = DevicePathBuilder.GetTableName(), Conditions = conditions, PageIndex = 0, PageSize = 1 }); + var taskData = taskSendInfo?.Items.FirstOrDefault(); + if (taskData != null) + { + // 更新 + meter.Timestamps = taskData.Timestamps; + taskData.IsReceived=true; + taskData.ReceivedMessageHexString= analysisBaseDto.HexMessage; + taskData.ReceivedMessageId= analysisBaseDto.MessageId ?? string.Empty; + } + else + { + // 新建 + var currentTime = DateTime.Now; + taskData = new MeterReadingTelemetryPacketInfo() + { + SystemName = _applicationOptions.SystemType, + ProjectId = $"{data.ProjectId}", + DeviceType = $"{data.MeterType}", + DeviceId = $"{data.MeterId}", + Timestamps = DateTime.Now.CheckTimePoint().GetDateTimeOffset().ToUnixTimeNanoseconds(), + DatabaseBusiID = data.DatabaseBusiID, + PendingCopyReadTime = data.DataTime.CheckTimePoint(), + CreationTime = currentTime, + MeterAddress = data.MeterAddress, + AFN = analysisBaseDto.AFN, + Fn = analysisBaseDto.Fn, + Seq = analysisBaseDto.PSEQ, + MSA = analysisBaseDto.MSA, + ItemCode = data.DataType, + TaskMark = taskMark, + IsSend = false, + ManualOrNot = false, + Pn = analysisBaseDto.Pn, + ReceivedMessageId = analysisBaseDto.MessageId?? string.Empty, + ReceivedMessageHexString = analysisBaseDto.HexMessage, + IsReceived = true, + ReceivedRemark = data.ErrorCodeMsg ?? string.Empty, + ScoreValue = $"{analysisBaseDto.Code}.{taskMark}".Md5Fun(), + }; + } + + await _dbProvider.InsertAsync(taskData); + //如果无字段名,则不保存数据 + if (string.IsNullOrWhiteSpace(data.FiledName)) + { + _runtimeContext.UseTableSessionPool = false; // 使树模型池 + await _dbProvider.InsertAsync(meter); + } + return await Task.FromResult(true); + } + + + /// + /// 保存数据到IotDb + /// + /// + /// + /// + public async Task SaveMultipleDataToIotDbAsync(UnitDataAnalysis>> analysisBaseDto) + { + var data = analysisBaseDto.Data!; + foreach (var item in data) + { + string taskMark = CommonHelper.GetTaskMark(analysisBaseDto.AFN, analysisBaseDto.Fn, analysisBaseDto.Pn, analysisBaseDto.MSA, analysisBaseDto.PSEQ); + string scoreValue = $"{analysisBaseDto.Code}.{taskMark}".Md5Fun(); + + var conditions = new List(); + conditions.Add(new QueryCondition() + { + Field = "ScoreValue", + Operator = "=", + IsNumber = false, + Value = scoreValue + }); + conditions.Add(new QueryCondition() + { + Field = "TaskMark", + Operator = "=", + IsNumber = false, + Value = taskMark + }); + conditions.Add(new QueryCondition() + { + Field = "IsReceived", + Operator = "=", + IsNumber = false, + Value = false + }); + var meter = new TreeModelSingleMeasuringEntity() + { + SystemName = _applicationOptions.SystemType, + DeviceId = $"{item.MeterId}", + DeviceType = $"{item.MeterType}", + ProjectId = $"{item.ProjectId}", + Timestamps = item.TimeSpan.GetDateTimeOffset().ToUnixTimeMilliseconds(), + SingleMeasuring = new Tuple(item.FiledName ?? string.Empty, item.DataValue ?? default) + }; + _runtimeContext.UseTableSessionPool = true; // 使用表模型池 + var taskSendInfo = await _dbProvider.QueryAsync(new IoTDBQueryOptions() { TableNameOrTreePath = DevicePathBuilder.GetTableName(), Conditions = conditions, PageIndex = 0, PageSize = 1 }); + var taskData = taskSendInfo?.Items.FirstOrDefault(); + if (taskData != null) + { + // 更新 + meter.Timestamps = taskData.Timestamps; + taskData.IsReceived = true; + taskData.ReceivedMessageHexString = analysisBaseDto.HexMessage; + taskData.ReceivedMessageId = analysisBaseDto.MessageId ?? string.Empty; + } + else + { + // 新建 + var currentTime = DateTime.Now; + taskData = new MeterReadingTelemetryPacketInfo() + { + SystemName = _applicationOptions.SystemType, + ProjectId = $"{item.ProjectId}", + DeviceType = $"{item.MeterType}", + DeviceId = $"{item.MeterId}", + Timestamps = DateTime.Now.CheckTimePoint().GetDateTimeOffset().ToUnixTimeNanoseconds(), + DatabaseBusiID = item.DatabaseBusiID, + PendingCopyReadTime = item.DataTime.CheckTimePoint(), + CreationTime = currentTime, + MeterAddress = item.MeterAddress, + AFN = analysisBaseDto.AFN, + Fn = analysisBaseDto.Fn, + Seq = analysisBaseDto.PSEQ, + MSA = analysisBaseDto.MSA, + ItemCode = item.DataType, + TaskMark = taskMark, + IsSend = false, + ManualOrNot = false, + Pn = analysisBaseDto.Pn, + ReceivedMessageId = analysisBaseDto.MessageId ?? string.Empty, + ReceivedMessageHexString = analysisBaseDto.HexMessage, + IsReceived = true, + ReceivedRemark = item.ErrorCodeMsg ?? string.Empty, + ScoreValue = $"{analysisBaseDto.Code}.{taskMark}".Md5Fun(), + }; + } + + await _dbProvider.InsertAsync(taskData); + //如果无字段名,则不保存数据 + if (string.IsNullOrWhiteSpace(item.FiledName)) + { + _runtimeContext.UseTableSessionPool = false; // 使树模型池 + await _dbProvider.InsertAsync(meter); + } + } + return await Task.FromResult(true); + } + + } } diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/F10TranspondMatch.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/F10TranspondMatch.cs new file mode 100644 index 0000000..f7b1176 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/F10TranspondMatch.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData +{ + public class F10TranspondMatch + { + /// + /// 188协议良禾水表透传解析 + /// + public const string WaterLiangHe188 = "1F 90 00"; + /// + /// 188协议良禾水表透传解析 + /// + public const string WaterLiangHe188_1 = "90 1F 00"; + /// + /// 电网频率 + /// + public const string PowerHz = "35 33 B3 35"; + + /// + /// 读取数据 + /// + public const string ReadData = "34 37 33 37"; + + /// + /// 跳合闸 正常应答帧 + /// + public const string JumpClosingNormal = "68 9C"; + /// + /// 跳合闸 异常应答帧 + /// + public const string JumpClosingError = "68 DC"; + /// + /// 写数据正常应答帧 + /// + public const string WriteNormal = "68 94 00"; + /// + /// 写数据异常应答帧 + /// + public const string WriteError = "68 D4 01"; + + /// + /// 读数据异常应答帧 + /// + public const string ReadError = "68 D1"; + + /// + /// 读数据正常应答帧 + /// + public const string ReadNormal = "68 91"; + /// + /// 捷先电动阀门(DN50) + /// + public const string CJT_188_2018 = "84 05 A0 17 00"; + + public const string DLT_645_1997 = "68 84 00"; + /// + /// ES190_DC 4G水表 + /// + public const string ES190_DC = "FF D5"; + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs index 7245d70..ae83974 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 2 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs index 7c2db74..5b48334 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 年时区数 p≤14 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs index 20870cd..55ab33d 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 日时段表数 q≤8 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs index cf0c882..4d0a919 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 日时段数(每日切换数) m≤14 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs index 56ab772..eefd7ce 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 费率数 k≤63 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs index 4ce52fc..0d3fbe2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套时区表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs index deb25fe..c3a7de2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 1 日时段表数据: diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs index 3dee4da..9d268a2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 2 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs index d3693c2..84302ac 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 3 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs index 68faa82..b1e04bf 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 4 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs index 9ef615f..5fa7d0e 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 5 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs index a31ae33..e421d38 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 6 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs index 5142cf7..ec77ea1 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 7 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs index 0074290..c49d998 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 8 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs index 86d2149..f0ea795 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A1 : IAnalysisStrategy, string> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs index 2713adb..40d9580 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 附录A.11数据格式 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs index 51d73ab..9c0cb36 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 附录A.13数据格式 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs index 5d21ee8..8d67953 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 附录A.14数据格式 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs index 284c3f6..8b2a4d5 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A15 : IAnalysisStrategy, string> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs index 942fc95..93e1939 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs @@ -1,6 +1,6 @@ using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A17 : IAnalysisStrategy, string> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs index 1a6efb5..7a10686 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A23 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs index 3cda672..094e468 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A25 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs index 3815e85..31fb8f1 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A5 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs index b75d733..63dcd65 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A7 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs index a3a0b38..f6845c9 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.T37612012.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A9 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs index 5242c43..2045a06 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs @@ -1,5 +1,9 @@ -using System.Text.RegularExpressions; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using NUglify.JavaScript.Syntax; +using System.Text.RegularExpressions; namespace JiShe.CollectBus.Protocol.T37612012 { @@ -120,5 +124,235 @@ namespace JiShe.CollectBus.Protocol.T37612012 } + /// + /// 判断当前时间所在时标(15分钟) + /// + /// + /// + public static DateTime CheckTimePoint(this DateTime curTime) + { + var curMinute = Convert.ToInt32(curTime.ToString("mm")); + string dataTime; + if (curMinute >= 0 && curMinute < 15) + dataTime = curTime.ToString("yyyy-MM-dd HH:00:00"); + else if (curMinute >= 15 && curMinute < 30) + dataTime = curTime.ToString("yyyy-MM-dd HH:15:00"); + else if (curMinute >= 30 && curMinute < 45) + dataTime = curTime.ToString("yyyy-MM-dd HH:30:00"); + else + dataTime = curTime.ToString("yyyy-MM-dd HH:45:00"); + return DateTime.Parse(dataTime); + } + + public static DateTime CheckTimeFivePoint(this DateTime curTime) + { + string dataTime; + var curMinute = Convert.ToInt32(curTime.ToString("mm")); + if (curMinute >= 0 && curMinute < 5) + dataTime = curTime.ToString("yyyy-MM-dd HH:00:00"); + else if (curMinute >= 5 && curMinute < 10) + dataTime = curTime.ToString("yyyy-MM-dd HH:5:00"); + else if (curMinute >= 10 && curMinute < 15) + dataTime = curTime.ToString("yyyy-MM-dd HH:10:00"); + else if (curMinute >= 15 && curMinute < 20) + dataTime = curTime.ToString("yyyy-MM-dd HH:15:00"); + else if (curMinute >= 20 && curMinute < 25) + dataTime = curTime.ToString("yyyy-MM-dd HH:20:00"); + else if (curMinute >= 25 && curMinute < 30) + dataTime = curTime.ToString("yyyy-MM-dd HH:25:00"); + else if (curMinute >= 30 && curMinute < 35) + dataTime = curTime.ToString("yyyy-MM-dd HH:30:00"); + else if (curMinute >= 35 && curMinute < 40) + dataTime = curTime.ToString("yyyy-MM-dd HH:35:00"); + else if (curMinute >= 40 && curMinute < 45) + dataTime = curTime.ToString("yyyy-MM-dd HH:40:00"); + else if (curMinute >= 45 && curMinute < 50) + dataTime = curTime.ToString("yyyy-MM-dd HH:45:00"); + else if (curMinute >= 50 && curMinute < 55) + dataTime = curTime.ToString("yyyy-MM-dd HH:50:00"); + else + dataTime = curTime.ToString("yyyy-MM-dd HH:55:00"); + return DateTime.Parse(dataTime); + } + + /// + /// 数据时标 + /// + /// + /// + /// + /// + /// + public static List GetReadTimeTd_c(this List hexMessageList, int index, int len) + { + if (len != 7) + throw new ArgumentException("数据时标 Td_c参数为不标准长度"); + var list = hexMessageList.GetRange(index, len); + List values = new List + { + GetReadTime(list.GetRange(0, 5)), + list[5].HexToDec().ToString(),//密度 + list[6].HexToDec().ToString()//数据点数 + }; + return values; + } + + + + /// + /// 数据时标型(曲线类型) + /// + /// + /// + public static List> GenerateFinalResultTd_c(this List data, int index,int density,string dataType, string filedDesc = "") + { + List> list = new List>(); + for (int i = index; i < data.Count; i++) + { + AnalysisBaseDto meter = new AnalysisBaseDto(); + meter.MeterType= MeterTypeEnum.Ammeter; + + decimal value = 0; + var errorCode = data[i].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[i], out value); + meter.DataValue = value; + meter.DataType = dataType; + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + if (DateTime.TryParse(CalculateTimeSpan(i - 3, data[0], density), out DateTime readingDate)) + meter.TimeSpan = readingDate; + list.Add(meter); + } + return list; + } + + /// + /// 月冻结 + /// + /// + /// + /// + /// + /// + /// + public static List> GenerateFinalResultTd_m(this List data, int index,string dataType,string timeSpan, string filedDesc = "") + { + List> list = new List>(); + for (int i = index; i < data.Count; i++) + { + AnalysisBaseDto meter = new AnalysisBaseDto(); + meter.MeterType = MeterTypeEnum.Ammeter; + decimal value = 0; + var errorCode = data[i].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[i], out value); + meter.DataValue = value; + if (DateTime.TryParse(timeSpan, out DateTime readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.DataType = i - index == 0 ? dataType : $"{dataType}_{i - index}"; + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + list.Add(meter); + } + return list; + } + + /// + /// 日冻结 + /// + /// + /// + /// + /// + public static List> GenerateFinalResultTd_d(this List data, int index,string dataType, string timeSpan, string filedDesc = "") + { + List> list = new List>(); + int typeIndex = 0; + for (int i = index; i < data.Count; i++) + { + AnalysisBaseDto meter = new AnalysisBaseDto + { + MeterType = MeterTypeEnum.Ammeter + }; + decimal value = 0; + var errorCode = data[i].CheckErrorCode(); + if (errorCode != null) + { + meter.ValidData = false; + meter.ErrorCodeMsg = errorCode.Item2; + } + else + decimal.TryParse(data[i], out value); + meter.DataValue = value; + if (DateTime.TryParse(timeSpan, out DateTime readingDate)) + { + meter.TimeSpan = readingDate; + } + meter.DataType = i - index == 0 ? dataType : $"{dataType}_{i - index}"; + meter.FiledDesc = filedDesc; + meter.FiledName = meter.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + list.Add(meter); + typeIndex++; + } + return list; + } + + /// + /// 计算时标 + /// + /// + /// + /// + /// + private static string CalculateTimeSpan(int index, string time, int intervalTime) + { + var startTime = Convert.ToDateTime($"{time.Substring(0, 4)}-{time.Substring(4, 2)}-{time.Substring(6, 2)} {time.Substring(8, 2)}:{time.Substring(10, 2)}"); + return startTime.AddMinutes(index * intervalTime).ToString("yyyy-MM-dd HH:mm:ss"); + } + + /// + /// 校验数据值精度 + /// + /// + /// + /// + public static List> IsValidData(this List> meterDatas, List mark) + { + bool isUpload = false; + var jfpgSum = 0M; + var totalItem = meterDatas.Find(f => f.DataType.Equals(mark[0]));//meterDatas.Find(f => f.DataType.Equals(mark[0])); + for (int i = 1; i <= meterDatas.Count - 1; i++) + { + var value = meterDatas[i];//meterDatas.Find(f => f.DataType.Equals(mark[i])); + if (value.ValidData) + jfpgSum += value.DataValue; + } + var floatingNum = (jfpgSum * 5 / 100);//上下浮动数据 + var minjfpgSum = jfpgSum - floatingNum;//100-(100*5/100); + var maxjfpgSum = jfpgSum + floatingNum; + if (totalItem.DataValue <= maxjfpgSum || totalItem.DataValue >= minjfpgSum)//总值,在JFPG之和的浮动范围内 + isUpload = true; + else + isUpload = false; + if (!isUpload) + meterDatas.ForEach(f => + { + f.ValidData = false; + }); + return meterDatas; + } } } diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs index 2e71564..1fc8d2a 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs @@ -114,7 +114,7 @@ namespace JiShe.CollectBus.Protocol.T37612012 return; //TODO:根据AFN进行分流推送到kafka string topicName = string.Format(ProtocolConst.AFNTopicNameFormat, tB3761.AFN_FC.AFN.ToString().PadLeft(2, '0')); - + tB3761.MessageId = Guid.NewGuid().ToString(); MessageProtocolAnalysis messageReceivedAnalysis = new MessageProtocolAnalysis() { ClientId = tcpSessionClient.Id, @@ -122,7 +122,7 @@ namespace JiShe.CollectBus.Protocol.T37612012 ClientPort = tcpSessionClient.Port, MessageHexString = tB3761.BaseHexMessage.HexMessageString!, DeviceNo = tB3761.A.Code!, - MessageId = Guid.NewGuid().ToString(), + MessageId = tB3761.MessageId, ReceivedTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Data = tB3761 }; diff --git a/services/JiShe.CollectBus.Domain/Protocol3761/Dto/AnalysisBaseDto.cs b/services/JiShe.CollectBus.Domain/Protocol3761/Dto/AnalysisBaseDto.cs index 49f9054..f637e57 100644 --- a/services/JiShe.CollectBus.Domain/Protocol3761/Dto/AnalysisBaseDto.cs +++ b/services/JiShe.CollectBus.Domain/Protocol3761/Dto/AnalysisBaseDto.cs @@ -1,5 +1,7 @@ -using System; +using JiShe.CollectBus.Common.Enums; +using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -17,22 +19,59 @@ namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto /// /// 数据类型 /// - public string DataType { get; set; } + public string DataType { get; set; } = null!; /// /// 错误码信息 /// - public string ErrorCodeMsg { get; set; } + public string? ErrorCodeMsg { get; set; } /// /// 字段名 /// - public string FiledName { get; set; } + public string? FiledName { get; set; } /// /// 字段描述 /// - public string FiledDesc { get; set; } + public string? FiledDesc { get; set; } + + /// + /// 数据时标 + /// + public DateTime TimeSpan { get; set; } + + /// + /// 数据时间 + /// + public DateTime DataTime { get; set; } + + /// + /// 项目Id + /// + public int ProjectId { get; set; } + + /// + /// 电表ID + /// + public int MeterId { get; set; } + + /// + /// 表类型 + /// + public MeterTypeEnum MeterType { get; set;} + + + /// + /// 数据业务库ID + /// + public int DatabaseBusiID { get; set; } + + /// + /// 表地址 + /// + public string MeterAddress { get; set; } = null!; + } public class AnalysisBaseDto : AnalysisBaseDto diff --git a/services/JiShe.CollectBus.Domain/Protocol3761/Dto/UnitDataAnalysis.cs b/services/JiShe.CollectBus.Domain/Protocol3761/Dto/UnitDataAnalysis.cs index d10594b..b691b3a 100644 --- a/services/JiShe.CollectBus.Domain/Protocol3761/Dto/UnitDataAnalysis.cs +++ b/services/JiShe.CollectBus.Domain/Protocol3761/Dto/UnitDataAnalysis.cs @@ -1,4 +1,6 @@ -namespace JiShe.CollectBus.Protocol.Dto +using JiShe.CollectBus.Common.Enums; + +namespace JiShe.CollectBus.Protocol.Dto { public class UnitDataAnalysis { @@ -32,6 +34,26 @@ /// public int PSEQ { get; set; } + /// + /// 响应帧 + /// + public string? HexMessage { get; set; } = null; + + /// + /// 消息ID + /// + public string? MessageId { get; set; } + + /// + /// 采集密度 + /// + public int TimeDensity { get; set; } + + /// + /// 采集密度单位 + /// + public DensityUnit DensityUnit { get; set; }= DensityUnit.Minute; + } public class UnitDataAnalysis: UnitDataAnalysis diff --git a/services/JiShe.CollectBus.Domain/Protocol3761/TB3761.cs b/services/JiShe.CollectBus.Domain/Protocol3761/TB3761.cs index d5e647f..8f9f776 100644 --- a/services/JiShe.CollectBus.Domain/Protocol3761/TB3761.cs +++ b/services/JiShe.CollectBus.Domain/Protocol3761/TB3761.cs @@ -17,6 +17,11 @@ namespace JiShe.CollectBus.Protocol3761 /// public BaseHexMessage BaseHexMessage { get; set;}=new BaseHexMessage(); + /// + /// 报文ID + /// + public string? MessageId { get; set; } + /// /// 控制域C /// diff --git a/shared/JiShe.CollectBus.Common/Consts/DataFieldConst.cs b/shared/JiShe.CollectBus.Common/Consts/DataFieldConst.cs index 62973ef..9cde24b 100644 --- a/shared/JiShe.CollectBus.Common/Consts/DataFieldConst.cs +++ b/shared/JiShe.CollectBus.Common/Consts/DataFieldConst.cs @@ -54,6 +54,7 @@ namespace JiShe.CollectBus.Common.Consts public const string ADL = "ADL"; public const string BDL = "BDL"; public const string CDL = "CDL"; + public const string LXDL = "LXDL"; public const string PowerGridFrequency = "PowerGridFrequency"; @@ -106,6 +107,7 @@ namespace JiShe.CollectBus.Common.Consts public const string ADL = "0D_92"; //A相电流曲线 public const string BDL = "0D_93"; //B相电流曲线 public const string CDL = "0D_94"; //C相电流曲线 + public const string LXDL = "0D_95"; // 零序电流 public const string PowerGridFrequency = "10_97"; //电网频率 diff --git a/shared/JiShe.CollectBus.Common/Enums/376Enums.cs b/shared/JiShe.CollectBus.Common/Enums/376Enums.cs index 6ea182d..cff3340 100644 --- a/shared/JiShe.CollectBus.Common/Enums/376Enums.cs +++ b/shared/JiShe.CollectBus.Common/Enums/376Enums.cs @@ -373,4 +373,50 @@ namespace JiShe.CollectBus.Common.Enums 登录 = 1, 心跳 = 3 } + + /// + /// 数据冻结密度 + /// + public enum DensityEnums + { + Sec_1 = 255, + Sec_5 = 254, + Sec_60 = 3, + Sec_30 = 2, + Sec_15 = 1, + Sec_0 = 0 + } + + /// + /// 数据冻结密度单位 + /// + public enum DensityUnit + { + /// + /// 秒 + /// + Second=0, + /// + /// 分钟 + /// + Minute=1, + /// + /// 小时 + /// + Hour=2, + /// + /// 天 + /// + Day=3, + /// + /// 月 + /// + Month=4, + /// + /// 年 + /// + Year=5 + + } + } diff --git a/web/JiShe.CollectBus.Host/appsettings.json b/web/JiShe.CollectBus.Host/appsettings.json index 2716f53..3b55c90 100644 --- a/web/JiShe.CollectBus.Host/appsettings.json +++ b/web/JiShe.CollectBus.Host/appsettings.json @@ -145,6 +145,7 @@ "ServerApplicationOptions": { "ServerTagName": "JiSheCollectBus100", + "SystemType": null, "FirstCollectionTime": "2025-04-22 16:07:00", "AutomaticVerificationTime": "16:07:00", "AutomaticGetTerminalVersionTime": "17:07:00",