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..248317d 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 @@ -1,9 +1,4 @@ -using JiShe.CollectBus.Common.Encrypt; -using JiShe.CollectBus.Common.Helpers; -using JiShe.CollectBus.IoTDB.Interface; -using JiShe.CollectBus.IoTDB.Options; -using JiShe.CollectBus.IoTDB.Provider; -using JiShe.CollectBus.IotSystems.MeterReadingRecords; +using JiShe.CollectBus.IoTDB.Interface; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; @@ -45,21 +40,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 +101,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_F149_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F149_Analysis.cs index cd7b565..07480f0 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,68 @@ -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.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; 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.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 +103,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..5b3cb9e 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 @@ -6,7 +6,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..44c94a7 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 @@ -6,7 +6,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..50bcfd8 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 @@ -5,7 +5,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.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..3e6f45a 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 @@ -6,7 +6,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..80af3c8 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F100_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.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_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..4a81d20 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F101_Analysis.cs @@ -0,0 +1,99 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..7f9d101 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F102_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..0882271 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F103_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..408a5af --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F104_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..1d1fd4c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F105_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.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_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..5dbd7a3 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F106_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.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_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..d5b1584 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F107_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..3a54a06 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F108_Analysis.cs @@ -0,0 +1,99 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..495f0dc --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F11_Analysis.cs @@ -0,0 +1,155 @@ +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.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_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..125ef90 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F145_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..3113c9b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F146_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..cdc58cc --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F147_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..dc978e3 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F148_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..a5c7c04 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F161_Analysis.cs @@ -0,0 +1,105 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..3a3853d --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F162_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.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_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..7748948 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F163_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.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_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..81cd07f --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F164_Analysis.cs @@ -0,0 +1,104 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..d7a821c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F165_Analysis.cs @@ -0,0 +1,104 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..cce8772 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F166_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.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_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..2f1fc28 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F167_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.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_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..2553c0b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F168_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.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_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..624f2c6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F177_Analysis.cs @@ -0,0 +1,104 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..dc882c4 --- /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.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..07ff2b2 --- /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.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..0fed8cb --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F180_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.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_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..466da30 --- /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.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..0833b9f --- /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.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..fc73291 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F183_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.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_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..103d49c --- /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.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..1fba574 --- /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.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..956eb11 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F190_Analysis.cs @@ -0,0 +1,141 @@ +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.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_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..2e0c48d --- /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.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..c7ffe04 --- /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.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..5cda5b3 --- /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.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..f53b936 --- /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.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..7af6f21 --- /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.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..fd9eaf5 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F81_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.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_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..724cad2 --- /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.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..2ffbd12 --- /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.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..36bc660 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F84_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.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_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..1437d2f --- /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.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..09c5a4a --- /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.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..d2b8dc1 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F87_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.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_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..3eb020c --- /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.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..d9863e4 --- /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.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..a11a586 --- /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.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..740aa7f --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F91_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.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_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..83a1aca --- /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.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..085c209 --- /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.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..b701b5c --- /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.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..1021cf9 --- /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.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..44a27e6 --- /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.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..5fad048 --- /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.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..974740b --- /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.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..7ca9c21 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs @@ -0,0 +1,79 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..ce5a7a3 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs @@ -0,0 +1,55 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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..a0e719d --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs @@ -0,0 +1,104 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +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/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/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs index c6554a4..7e3b620 100644 --- a/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T6452007/T6452007ProtocolPlugin.cs @@ -1,4 +1,5 @@ -using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Common.Models; using JiShe.CollectBus.IotSystems.Protocols; @@ -89,8 +90,8 @@ namespace JiShe.CollectBus.Protocol.T6452007 Telemetry3761PacketResponse builderResponse = null; List dataUnit = new List(); - //数据转发场景 10H_F1_1CH - if (aFNStr == "10" && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false) + //数据转发场景 10H_F1 + if (request.ItemCode == T37612012PacketItemCodeConst.AFN10HFN01H && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false) { var t645PacketHandlerName = $"C{request.SubProtocolRequest.ItemCode}_Send"; Telemetry6452007PacketResponse t645PacketResponse = null; diff --git a/services/JiShe.CollectBus.Application.Contracts/ScheduledMeterReading/IScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application.Contracts/ScheduledMeterReading/IScheduledMeterReadingService.cs index 9d64747..5650a57 100644 --- a/services/JiShe.CollectBus.Application.Contracts/ScheduledMeterReading/IScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application.Contracts/ScheduledMeterReading/IScheduledMeterReadingService.cs @@ -80,8 +80,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading /// Task AmmeterScheduledAutomaticVerificationTime(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps); - #endregion - + #endregion #region 水表采集处理 /// @@ -103,7 +102,30 @@ namespace JiShe.CollectBus.ScheduledMeterReading /// /// Task WatermeterScheduledMeterAutoReading(); - + + #endregion + + #region 集中器处理 + + /// + /// 自动获取终端版 + /// + /// 采集频率 + /// 电表信息 + /// 集中器所在分组 + /// 采集频率对应的时间戳 + /// + Task ConcentratorScheduledAutomaticGetTerminalVersion(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps); + + /// + /// 自动获取远程通信模块(SIM)版本信息 + /// + /// 采集频率 + /// 电表信息 + /// 集中器所在分组 + /// 采集频率对应的时间戳 + /// + Task ConcentratorScheduledAutomaticGetTelematicsModule(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps); #endregion diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs index 4b62649..a159326 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/BasicScheduledMeterReadingService.cs @@ -135,22 +135,45 @@ namespace JiShe.CollectBus.ScheduledMeterReading //电表定时广播校时,一天一次。 string currentTimeStr = $"{currentTime:HH:mm:00}"; - //判断是否是自动校时时间 - if (!string.Equals(currentTimeStr, _applicationOptions.AutomaticVerificationTime, StringComparison.CurrentCultureIgnoreCase)) + if (string.Equals(currentTimeStr, _applicationOptions.AutomaticVerificationTime, StringComparison.CurrentCultureIgnoreCase))//自动校时 { - _logger.LogInformation($"{nameof(AmmeterScheduledAutomaticVerificationTime)} 电表自动校时,非自动校时时间"); - return; + //_logger.LogInformation($"{nameof(AmmeterScheduledAutomaticVerificationTime)} 电表自动校时,非自动校时时间"); + //return; + + _ = CreateMeterPublishTask( + timeDensity: timeDensity, + nextTaskTime: currentTime, + meterType: MeterTypeEnum.Ammeter, + taskCreateAction: async (timeDensity, data, groupIndex, timestamps) => + { + await AmmeterScheduledAutomaticVerificationTime(timeDensity, data, groupIndex, timestamps); + }); + } + else if (string.Equals(currentTimeStr, _applicationOptions.AutomaticGetTerminalVersionTime, StringComparison.CurrentCultureIgnoreCase))//集中器版本号读取 + { + _ = CreateMeterPublishTask( + timeDensity: timeDensity, + nextTaskTime: currentTime, + meterType: MeterTypeEnum.Ammeter, + taskCreateAction: async (timeDensity, data, groupIndex, timestamps) => + { + await ConcentratorScheduledAutomaticGetTerminalVersion(timeDensity, data, groupIndex, timestamps); + }); + } + else if (string.Equals(currentTimeStr, _applicationOptions.AutomaticGetTelematicsModuleTime, StringComparison.CurrentCultureIgnoreCase))//SIM卡读取 + { + _ = CreateMeterPublishTask( + timeDensity: timeDensity, + nextTaskTime: currentTime, + meterType: MeterTypeEnum.Ammeter, + taskCreateAction: async (timeDensity, data, groupIndex, timestamps) => + { + await ConcentratorScheduledAutomaticGetTelematicsModule(timeDensity, data, groupIndex, timestamps); + }); } else { - _ = CreateMeterPublishTask( - timeDensity: timeDensity, - nextTaskTime: currentTime, - meterType: MeterTypeEnum.Ammeter, - taskCreateAction: async (timeDensity, data, groupIndex, timestamps) => - { - await AmmeterScheduledAutomaticVerificationTime(timeDensity, data, groupIndex, timestamps); - }); + _logger.LogInformation($"{nameof(CreateToBeIssueTasks)} 不是自动校时、采集终端信息等时间,继续处理其他"); } //检查任务时间节点,由于定时任务10秒钟运行一次,需要判定当前时间是否在任务时间节点内,不在则跳过 @@ -736,7 +759,8 @@ namespace JiShe.CollectBus.ScheduledMeterReading List taskList = new List(); var metadata = await _dbProvider.GetMetadata(); - var temCode = "10_01"; + var itemCode = T37612012PacketItemCodeConst.AFN10HFN01H; + var subItemCode = T6452007PacketItemCodeConst.C08; //根据电表型号获取协议插件 var protocolPlugin = await _protocolService.GetProtocolServiceAsync(ammeterInfo.BrandType); @@ -750,12 +774,12 @@ namespace JiShe.CollectBus.ScheduledMeterReading { FocusAddress = ammeterInfo.FocusAddress, Pn = ammeterInfo.MeteringCode, - ItemCode = temCode, + ItemCode = itemCode, SubProtocolRequest = new SubProtocolBuildRequest() { MeterAddress = ammeterInfo.AmmerterAddress, Password = ammeterInfo.Password, - ItemCode = T6452007PacketItemCodeConst.C08, + ItemCode = subItemCode, } }); @@ -775,7 +799,8 @@ namespace JiShe.CollectBus.ScheduledMeterReading Fn = builderResponse.Fn, Seq = builderResponse.Seq, MSA = builderResponse.MSA, - ItemCode = temCode, + ItemCode = itemCode, + SubItemCode = subItemCode, TaskMark = taskMark, IsSend = false, ManualOrNot = false, @@ -814,7 +839,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading throw; } } - + #endregion @@ -997,38 +1022,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading List taskList = new List(); - List tempCodes = new List() { "10_1" }; - - //todo 后续从协议池获取 - if (watermeter.MeterTypeName.Equals("水表") && (watermeter.Protocol.Equals((int)MeterLinkProtocol.CJT_188_2018) || watermeter.Protocol.Equals((int)MeterLinkProtocol.DLT_645_1997) || watermeter.Protocol.Equals((int)MeterLinkProtocol.DLT_645_2007)))//水表且(CJT_188_2018或DLT_645_1997)都采用0C_129 - { - if (watermeter.MeterBrand.Contains("炬华有线")) - { - tempCodes = new List() { "0C_188" }; - } - else - { - tempCodes = new List() { "0C_129" }; - } - } - - else if (typeName.Trim().Equals("西恩超声波流量计")) - { - tempCodes = new List() { "10_1" }; - } - else if (typeName.Trim().Equals("江苏华海涡街流量计积算仪")) - { - tempCodes = new List() { "10_1" }; - } - else if (typeName.Trim().Equals("V880BR涡街流量计")) - { - tempCodes = new List() { "10_1" }; - } - else if (typeName.Trim().Equals("拓思特涡街流量计H880BR")) - { - tempCodes = new List() { "10_1" }; - } - + //根据表型号获取协议插件 var protocolPlugin = await _protocolService.GetProtocolServiceAsync(watermeter.Code); if (protocolPlugin == null) @@ -1037,105 +1031,273 @@ namespace JiShe.CollectBus.ScheduledMeterReading //return; } - foreach (var tempItem in tempCodes) + string itemCode = T37612012PacketItemCodeConst.AFN10HFN01H; + string subItemCode = T1882018PacketItemCodeConst.CTR0190; + + ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest() { - //排除已发送日冻结和月冻结采集项配置 - if (DayFreezeCodes.Contains(tempItem)) + FocusAddress = watermeter.FocusAddress, + Pn = watermeter.MeteringCode, + ItemCode = itemCode, + SubProtocolRequest = new SubProtocolBuildRequest() { - continue; - } - - if (MonthFreezeCodes.Contains(tempItem)) - { - continue; - } - - //var itemCodeArr = tempItem.Split('_'); - //var aFNStr = itemCodeArr[0]; - //var aFN = (AFN)aFNStr.HexToDec(); - //var fn = int.Parse(itemCodeArr[1]); - //TelemetryPacketResponse builderResponse = null; - - //string methonCode = $"AFN{aFNStr}_Fn_Send"; - ////特殊表暂不处理 - //if (handlerPacketBuilder != null && handlerPacketBuilder.TryGetValue(methonCode - // , out var handler)) - //{ - // builderResponse = handler(new TelemetryPacketRequest() - // { - // FocusAddress = watermeter.FocusAddress, - // Fn = fn, - // Pn = watermeter.MeteringCode, - // DataUnit = Build188SendData.Build188WaterMeterReadingSendDataUnit(watermeter.Address), - // }); - //} - //else - //{ - // _logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的水表{watermeter.Name}采集项{tempItem}无效编码。"); - // continue; - //} - - ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest() - { - FocusAddress = watermeter.FocusAddress, - Pn = watermeter.MeteringCode, - ItemCode = tempItem, - SubProtocolRequest = new SubProtocolBuildRequest() - { - MeterAddress = watermeter.MeterAddress, - Password = watermeter.Password, - ItemCode = tempItem, - } - }); - if (builderResponse == null || builderResponse.Data.Length <= 0) - { - //_logger.LogWarning($"{nameof(AmmerterCreatePublishTask)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}采集项{tempItem}未能正确获取报文。"); - continue; - } - - if (builderResponse == null || builderResponse.Data.Length <= 0) - { - _logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的水表{watermeter.Name}采集项{tempItem}未能正确获取报文。"); - continue; - } - - - string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, watermeter.MeteringCode, builderResponse.MSA, builderResponse.Seq); - var meterReadingRecords = new MeterReadingTelemetryPacketInfo() - { - SystemName = SystemType, - ProjectId = $"{watermeter.ProjectID}", - DeviceType = $"{MeterTypeEnum.Ammeter}", - DeviceId = $"{watermeter.MeterId}", - Timestamps = DateTimeOffset.Now.ToUnixTimeNanoseconds(), - DatabaseBusiID = watermeter.DatabaseBusiID, - PendingCopyReadTime = timestamps, - CreationTime = currentTime, MeterAddress = watermeter.MeterAddress, - AFN = builderResponse.AFn, - Fn = builderResponse.Fn, - Seq = builderResponse.Seq, - MSA = builderResponse.MSA, - ItemCode = tempItem, - TaskMark = taskMark, - IsSend = false, - ManualOrNot = false, - Pn = watermeter.MeteringCode, - IssuedMessageId = GuidGenerator.Create().ToString(), - IssuedMessageHexString = Convert.ToHexString(builderResponse.Data), - IsReceived = false, - ScoreValue = $"{watermeter.FocusAddress}.{taskMark}".Md5Fun(), - }; - - taskList.Add(meterReadingRecords); + Password = watermeter.Password, + ItemCode = subItemCode, + } + }); + if (builderResponse == null || builderResponse.Data.Length <= 0) + { + //_logger.LogWarning($"{nameof(AmmerterCreatePublishTask)} 集中器{ammeterInfo.FocusAddress}的电表{ammeterInfo.Name}采集项{tempItem}未能正确获取报文。"); + return null; } + if (builderResponse == null || builderResponse.Data.Length <= 0) + { + _logger.LogWarning($"{nameof(WatermeterCreatePublishTaskAction)} 集中器{watermeter.FocusAddress}的水表{watermeter.Name}采集项{itemCode}未能正确获取报文。"); + return null; + } + + + string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, watermeter.MeteringCode, builderResponse.MSA, builderResponse.Seq); + var meterReadingRecords = new MeterReadingTelemetryPacketInfo() + { + SystemName = SystemType, + ProjectId = $"{watermeter.ProjectID}", + DeviceType = $"{MeterTypeEnum.Ammeter}", + DeviceId = $"{watermeter.MeterId}", + Timestamps = DateTimeOffset.Now.ToUnixTimeNanoseconds(), + DatabaseBusiID = watermeter.DatabaseBusiID, + PendingCopyReadTime = timestamps, + CreationTime = currentTime, + MeterAddress = watermeter.MeterAddress, + AFN = builderResponse.AFn, + Fn = builderResponse.Fn, + Seq = builderResponse.Seq, + MSA = builderResponse.MSA, + ItemCode = itemCode, + SubItemCode = subItemCode, + TaskMark = taskMark, + IsSend = false, + ManualOrNot = false, + Pn = watermeter.MeteringCode, + IssuedMessageId = GuidGenerator.Create().ToString(), + IssuedMessageHexString = Convert.ToHexString(builderResponse.Data), + IsReceived = false, + ScoreValue = $"{watermeter.FocusAddress}.{taskMark}".Md5Fun(), + }; + + taskList.Add(meterReadingRecords); + return taskList; } #endregion + #region 集中器处理 + /// + /// 自动获取终端版 + /// + /// 采集频率 + /// 电表信息 + /// 集中器所在分组 + /// 采集频率对应的时间戳 + /// + public virtual async Task ConcentratorScheduledAutomaticGetTerminalVersion(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps) + { + var currentTime = DateTime.Now; + string currentTimeStr = $"{currentTime:HH:mm:00}"; + + try + { + //判断是否是自动获取版本号时间 + if (!string.Equals(currentTimeStr, _applicationOptions.AutomaticGetTerminalVersionTime, StringComparison.CurrentCultureIgnoreCase)) + { + _logger.LogInformation($"{nameof(ConcentratorScheduledAutomaticGetTerminalVersion)} 集中器自动获取版本号,非自动处理时间"); + return; + } + + List taskList = new List(); + var metadata = await _dbProvider.GetMetadata(); + + var itemCode = T37612012PacketItemCodeConst.AFN09HFN01H; + //var subItemCode = T6452007PacketItemCodeConst.C08; + + //根据电表型号获取协议插件 + var protocolPlugin = await _protocolService.GetProtocolServiceAsync(ammeterInfo.BrandType); + if (protocolPlugin == null) + { + _logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 集中器自动获取版本号{currentTime}没有找到对应的协议组件,-105"); + return; + } + + ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest() + { + FocusAddress = ammeterInfo.FocusAddress, + Pn = ammeterInfo.MeteringCode, + ItemCode = itemCode, + //SubProtocolRequest = new SubProtocolBuildRequest() + //{ + // MeterAddress = ammeterInfo.AmmerterAddress, + // Password = ammeterInfo.Password, + // ItemCode = subItemCode, + //} + }); + + string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, ammeterInfo.MeteringCode, builderResponse.MSA, builderResponse.Seq); + var meterReadingRecords = new MeterReadingTelemetryPacketInfo() + { + SystemName = SystemType, + ProjectId = $"{ammeterInfo.ProjectID}", + DeviceType = $"{MeterTypeEnum.Ammeter}", + DeviceId = $"{ammeterInfo.MeterId}", + Timestamps = currentTime.GetDateTimeOffset().ToUnixTimeNanoseconds(), + DatabaseBusiID = ammeterInfo.DatabaseBusiID, + PendingCopyReadTime = currentTime, + CreationTime = currentTime, + MeterAddress = ammeterInfo.AmmerterAddress, + AFN = builderResponse.AFn, + Fn = builderResponse.Fn, + Seq = builderResponse.Seq, + MSA = builderResponse.MSA, + ItemCode = itemCode, + //SubItemCode = subItemCode, + TaskMark = taskMark, + IsSend = false, + ManualOrNot = false, + Pn = ammeterInfo.MeteringCode, + IssuedMessageId = GuidGenerator.Create().ToString(), + IssuedMessageHexString = Convert.ToHexString(builderResponse.Data), + IsReceived = false, + ScoreValue = $"{ammeterInfo.FocusAddress}.{taskMark}".Md5Fun(), + }; + taskList.Add(meterReadingRecords); + + if (taskList == null || taskList.Count <= 0) + { + _logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有自动阀控任务生成,-106"); + return; + } + + //任务记录入库 + await _dbProvider.BatchInsertAsync(metadata, taskList); + + //任务信息推送Kafka + _ = DeviceGroupBalanceControl.ProcessWithThrottleAsync( + items: taskList, + deviceIdSelector: data => data.DeviceId, + processor: (data, groupIndex) => + { + _ = KafkaProducerIssuedMessageAction(ProtocolConst.AmmeterSubscriberWorkerOtherIssuedEventName, data, groupIndex); + } + ); + } + catch (Exception) + { + + throw; + } + } + + /// + /// 自动获取远程通信模块(SIM)版本信息 + /// + /// 采集频率 + /// 电表信息 + /// 集中器所在分组 + /// 采集频率对应的时间戳 + /// + public virtual async Task ConcentratorScheduledAutomaticGetTelematicsModule(int timeDensity, AmmeterInfo ammeterInfo, int groupIndex, DateTime timestamps) + { + var currentTime = DateTime.Now; + string currentTimeStr = $"{currentTime:HH:mm:00}"; + + try + { + //判断是否是自动获取版本号时间 + if (!string.Equals(currentTimeStr, _applicationOptions.AutomaticGetTerminalVersionTime, StringComparison.CurrentCultureIgnoreCase)) + { + _logger.LogInformation($"{nameof(ConcentratorScheduledAutomaticGetTelematicsModule)} 自动获取远程通信模块(SIM)版本信息,非自动处理时间"); + return; + } + + List taskList = new List(); + var metadata = await _dbProvider.GetMetadata(); + + var itemCode = T37612012PacketItemCodeConst.AFN09HFN09H; + + //根据电表型号获取协议插件 + var protocolPlugin = await _protocolService.GetProtocolServiceAsync(ammeterInfo.BrandType); + if (protocolPlugin == null) + { + _logger.LogError($"{nameof(ConcentratorScheduledAutomaticGetTelematicsModule)} 自动获取远程通信模块(SIM)版本信息{currentTime}没有找到对应的协议组件,-105"); + return; + } + + ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest() + { + FocusAddress = ammeterInfo.FocusAddress, + Pn = ammeterInfo.MeteringCode, + ItemCode = itemCode, + }); + + string taskMark = CommonHelper.GetTaskMark(builderResponse.AFn, builderResponse.Fn, ammeterInfo.MeteringCode, builderResponse.MSA, builderResponse.Seq); + var meterReadingRecords = new MeterReadingTelemetryPacketInfo() + { + SystemName = SystemType, + ProjectId = $"{ammeterInfo.ProjectID}", + DeviceType = $"{MeterTypeEnum.Ammeter}", + DeviceId = $"{ammeterInfo.MeterId}", + Timestamps = currentTime.GetDateTimeOffset().ToUnixTimeNanoseconds(), + DatabaseBusiID = ammeterInfo.DatabaseBusiID, + PendingCopyReadTime = currentTime, + CreationTime = currentTime, + MeterAddress = ammeterInfo.AmmerterAddress, + AFN = builderResponse.AFn, + Fn = builderResponse.Fn, + Seq = builderResponse.Seq, + MSA = builderResponse.MSA, + ItemCode = itemCode, + //SubItemCode = subItemCode, + TaskMark = taskMark, + IsSend = false, + ManualOrNot = false, + Pn = ammeterInfo.MeteringCode, + IssuedMessageId = GuidGenerator.Create().ToString(), + IssuedMessageHexString = Convert.ToHexString(builderResponse.Data), + IsReceived = false, + ScoreValue = $"{ammeterInfo.FocusAddress}.{taskMark}".Md5Fun(), + }; + taskList.Add(meterReadingRecords); + + if (taskList == null || taskList.Count <= 0) + { + _logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有自动阀控任务生成,-106"); + return; + } + + //任务记录入库 + await _dbProvider.BatchInsertAsync(metadata, taskList); + + //任务信息推送Kafka + _ = DeviceGroupBalanceControl.ProcessWithThrottleAsync( + items: taskList, + deviceIdSelector: data => data.DeviceId, + processor: (data, groupIndex) => + { + _ = KafkaProducerIssuedMessageAction(ProtocolConst.AmmeterSubscriberWorkerOtherIssuedEventName, data, groupIndex); + } + ); + } + catch (Exception) + { + + throw; + } + } + #endregion + #region 公共处理方法 diff --git a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs index 99880af..9dc2fc3 100644 --- a/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs +++ b/services/JiShe.CollectBus.Application/ScheduledMeterReading/EnergySystemScheduledMeterReadingService.cs @@ -227,6 +227,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading //获取对应的缓存电表信息 var ammeterInfo = ammeterInfos.First(); bool tripStateResult = false; + string itemCode = T37612012PacketItemCodeConst.AFN10HFN01H; string subItemCode = string.Empty; if (settingInfo.TripType.Equals("on")) { @@ -250,7 +251,6 @@ namespace JiShe.CollectBus.ScheduledMeterReading continue; } - var temCode = "10_01_"; //根据电表型号获取协议插件 var protocolPlugin = await _protocolService.GetProtocolServiceAsync(ammeterInfo.BrandType); @@ -264,7 +264,7 @@ namespace JiShe.CollectBus.ScheduledMeterReading { FocusAddress = ammeterInfo.FocusAddress, Pn = ammeterInfo.MeteringCode, - ItemCode = temCode, + ItemCode = itemCode, SubProtocolRequest = new SubProtocolBuildRequest() { MeterAddress = ammeterInfo.AmmerterAddress, @@ -289,7 +289,8 @@ namespace JiShe.CollectBus.ScheduledMeterReading Fn = builderResponse.Fn, Seq = builderResponse.Seq, MSA = builderResponse.MSA, - ItemCode = temCode, + ItemCode = itemCode, + SubItemCode = subItemCode, TaskMark = taskMark, IsSend = false, ManualOrNot = false, diff --git a/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs b/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs index e39b2bd..e35d245 100644 --- a/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs +++ b/services/JiShe.CollectBus.Domain/IotSystems/MeterReadingRecords/MeterReadingTelemetryPacketInfo.cs @@ -104,6 +104,13 @@ namespace JiShe.CollectBus.IotSystems.MeterReadingRecords [FIELDColumn] public string ItemCode { get; set; } + + /// + /// 子项编码,一般用于透明转发的编码 + /// + [FIELDColumn] + public string SubItemCode { get; set; } + /// /// 帧序列域 SEQ /// 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/Consts/T1882018PacketItemCodeConst.cs b/shared/JiShe.CollectBus.Common/Consts/T1882018PacketItemCodeConst.cs index a51f77f..585d3df 100644 --- a/shared/JiShe.CollectBus.Common/Consts/T1882018PacketItemCodeConst.cs +++ b/shared/JiShe.CollectBus.Common/Consts/T1882018PacketItemCodeConst.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace JiShe.CollectBus.Common.Consts { /// - /// T188报文项编码 + /// T188-2018报文项编码 /// public class T1882018PacketItemCodeConst { diff --git a/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs b/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs new file mode 100644 index 0000000..6d15e19 --- /dev/null +++ b/shared/JiShe.CollectBus.Common/Consts/T37612012PacketItemCodeConst.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JiShe.CollectBus.Common.Consts +{ + /// + /// T376.1-2012报文项编码 + /// + public class T37612012PacketItemCodeConst + { + #region 非可配置的,下行报文编码管理,主要是数据库没有配置,但是需要读取的采集项 + + #region 读数据 + /// + /// 透明转发 + /// + public const string AFN10HFN01H = $"10_01"; + + /// + /// 读取终端信息 + /// + public const string AFN09HFN01H = $"09_01"; + + /// + /// 远程通信模块版本信息 + /// + public const string AFN09HFN09H = $"09_09"; + + #endregion + + #region 写数据 + + #endregion + + #endregion + } +} diff --git a/shared/JiShe.CollectBus.Common/Consts/T6452007PacketItemCodeConst.cs b/shared/JiShe.CollectBus.Common/Consts/T6452007PacketItemCodeConst.cs index 8a0834a..92da5ba 100644 --- a/shared/JiShe.CollectBus.Common/Consts/T6452007PacketItemCodeConst.cs +++ b/shared/JiShe.CollectBus.Common/Consts/T6452007PacketItemCodeConst.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace JiShe.CollectBus.Common.Consts { /// - /// T6452007报文项编码 + /// T645-2007报文项编码 /// public class T6452007PacketItemCodeConst { 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/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs b/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs index 6ed9e4a..8aed32b 100644 --- a/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs +++ b/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs @@ -10,6 +10,11 @@ /// public required string ServerTagName { get; set; } + /// + /// 系统类型 + /// + public required string SystemType { get; set; } + /// /// 首次采集时间 /// @@ -19,5 +24,15 @@ /// 自动验证时间 /// public required string AutomaticVerificationTime { get; set;} + + /// + /// 自动获取终端版时间 + /// + public required string AutomaticGetTerminalVersionTime { get; set; } + + /// + /// 自动获取远程通信模块(SIM)版本时间 + /// + public required string AutomaticGetTelematicsModuleTime { get; set; } } } diff --git a/web/JiShe.CollectBus.Host/appsettings.json b/web/JiShe.CollectBus.Host/appsettings.json index e5fe35d..5abdef7 100644 --- a/web/JiShe.CollectBus.Host/appsettings.json +++ b/web/JiShe.CollectBus.Host/appsettings.json @@ -141,5 +141,14 @@ "DefaultIdempotence": true } }, + "PlugInFolder": "C:\\Users\\Dai Zan\\Desktop\\Plugins", + "ServerApplicationOptions": { + "ServerTagName": "JiSheCollectBus100", + "SystemType": null, + "FirstCollectionTime": "2025-04-22 16:07:00", + "AutomaticVerificationTime": "16:07:00", + "AutomaticGetTerminalVersionTime": "17:07:00", + "AutomaticGetTelematicsModuleTime": "17:30:00" + } "PlugInFolder": "" } \ No newline at end of file