From 314d96dd59de47904fc1be3e0b2648fcb94cc959 Mon Sep 17 00:00:00 2001 From: zenghongyao <873884283@qq.com> Date: Sat, 26 Apr 2025 19:04:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=97OCH?= =?UTF-8?q?=E3=80=81ODH=E3=80=8110H=E7=AD=89=E6=95=B0=E6=8D=AE=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisData/AFN_00H/AFN0_F1_Analysis.cs | 2 +- .../AnalysisData/AFN_00H/AFN0_F2_Analysis.cs | 2 +- .../AnalysisData/AFN_09H/AFN9_F1_Analysis.cs | 2 +- .../AnalysisData/AFN_09H/AFN9_F9_Analysis.cs | 2 +- .../AFN_0AH/AFN10_F10_Analysis.cs | 2 +- .../AFN_0AH/AFN10_F66_Analysis.cs | 2 +- .../AFN_0AH/AFN10_F68_Analysis.cs | 2 +- .../AFN_0CH/AFN12_F129_Analysis.cs | 13 +- .../AFN_0CH/AFN12_F130_Analysis.cs | 4 +- .../AFN_0CH/AFN12_F131_Analysis.cs | 4 +- .../AFN_0CH/AFN12_F132_Analysis.cs | 4 +- .../AFN_0CH/AFN12_F145_Analysis.cs | 4 +- .../AFN_0CH/AFN12_F149_Analysis.cs | 81 ++++-- .../AFN_0CH/AFN12_F188_Analysis.cs | 2 +- .../AFN_0CH/AFN12_F25_Analysis.cs | 4 +- .../AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs | 4 +- .../AFN_0CH/AFN12_F33_Analysis.cs | 4 +- .../AFN_0CH/AFN12_F49_Analysis.cs | 4 +- .../AFN_0DH/AFN13_F100_Analysis.cs | 101 ++++++++ .../AFN_0DH/AFN13_F101_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F102_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F103_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F104_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F105_Analysis.cs | 97 +++++++ .../AFN_0DH/AFN13_F106_Analysis.cs | 98 +++++++ .../AFN_0DH/AFN13_F107_Analysis.cs | 95 +++++++ .../AFN_0DH/AFN13_F108_Analysis.cs | 95 +++++++ .../AFN_0DH/AFN13_F11_Analysis.cs | 149 +++++++++++ .../AFN_0DH/AFN13_F145_Analysis.cs | 95 +++++++ .../AFN_0DH/AFN13_F146_Analysis.cs | 95 +++++++ .../AFN_0DH/AFN13_F147_Analysis.cs | 95 +++++++ .../AFN_0DH/AFN13_F148_Analysis.cs | 94 +++++++ .../AFN_0DH/AFN13_F161_Analysis.cs | 100 ++++++++ .../AFN_0DH/AFN13_F162_Analysis.cs | 97 +++++++ .../AFN_0DH/AFN13_F163_Analysis.cs | 97 +++++++ .../AFN_0DH/AFN13_F164_Analysis.cs | 99 ++++++++ .../AFN_0DH/AFN13_F165_Analysis.cs | 99 ++++++++ .../AFN_0DH/AFN13_F166_Analysis.cs | 98 +++++++ .../AFN_0DH/AFN13_F167_Analysis.cs | 98 +++++++ .../AFN_0DH/AFN13_F168_Analysis.cs | 98 +++++++ .../AFN_0DH/AFN13_F177_Analysis.cs | 99 ++++++++ .../AFN_0DH/AFN13_F178_Analysis.cs | 99 ++++++++ .../AFN_0DH/AFN13_F179_Analysis.cs | 98 +++++++ .../AFN_0DH/AFN13_F180_Analysis.cs | 98 +++++++ .../AFN_0DH/AFN13_F181_Analysis.cs | 98 +++++++ .../AFN_0DH/AFN13_F182_Analysis.cs | 97 +++++++ .../AFN_0DH/AFN13_F183_Analysis.cs | 97 +++++++ .../AFN_0DH/AFN13_F184_Analysis.cs | 97 +++++++ .../AFN_0DH/AFN13_F189_Analysis.cs | 107 ++++++++ .../AFN_0DH/AFN13_F190_Analysis.cs | 139 ++++++++++ .../AFN_0DH/AFN13_F193_Analysis.cs | 128 ++++++++++ .../AFN_0DH/AFN13_F195_Analysis.cs | 128 ++++++++++ .../AFN_0DH/AFN13_F19_Analysis.cs | 144 +++++++++++ .../AnalysisData/AFN_0DH/AFN13_F3_Analysis.cs | 171 +++++++++++++ .../AnalysisData/AFN_0DH/AFN13_F4_Analysis.cs | 172 +++++++++++++ .../AFN_0DH/AFN13_F81_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F82_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F83_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F84_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F85_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F86_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F87_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F88_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F89_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F90_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F91_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F92_Analysis.cs | 95 +++++++ .../AFN_0DH/AFN13_F93_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F94_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F95_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F97_Analysis.cs | 96 +++++++ .../AFN_0DH/AFN13_F98_Analysis.cs | 95 +++++++ .../AFN_0DH/AFN13_F99_Analysis.cs | 96 +++++++ .../AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs | 81 ++++++ .../AFN_10H/AFN16_F101_Analysis.cs | 58 +++++ .../AFN_10H/AFN16_F98_Analysis.cs | 107 ++++++++ .../AnalysisData/DataStorage.cs | 145 ++++++++++- .../Appendix/Appendix_02800002.cs | 2 +- .../Appendix/Appendix_04000201.cs | 2 +- .../Appendix/Appendix_04000202.cs | 2 +- .../Appendix/Appendix_04000203.cs | 2 +- .../Appendix/Appendix_04000204.cs | 2 +- .../Appendix/Appendix_04010000.cs | 2 +- .../Appendix/Appendix_04010001.cs | 2 +- .../Appendix/Appendix_04010002.cs | 2 +- .../Appendix/Appendix_04010003.cs | 2 +- .../Appendix/Appendix_04010004.cs | 2 +- .../Appendix/Appendix_04010005.cs | 2 +- .../Appendix/Appendix_04010006.cs | 2 +- .../Appendix/Appendix_04010007.cs | 2 +- .../Appendix/Appendix_04010008.cs | 2 +- .../Appendix/Appendix_A1.cs | 2 +- .../Appendix/Appendix_A11.cs | 2 +- .../Appendix/Appendix_A13.cs | 2 +- .../Appendix/Appendix_A14.cs | 2 +- .../Appendix/Appendix_A15.cs | 2 +- .../Appendix/Appendix_A17.cs | 2 +- .../Appendix/Appendix_A23.cs | 2 +- .../Appendix/Appendix_A25.cs | 2 +- .../Appendix/Appendix_A5.cs | 2 +- .../Appendix/Appendix_A7.cs | 2 +- .../Appendix/Appendix_A9.cs | 2 +- .../CollectBusProtocolT37612012Module.cs | 2 +- .../Protocol3761Extensions.cs | 240 +++++++++++++++++- .../T37612012ProtocolPlugin.cs | 6 +- .../Protocol3761/Dto/AnalysisBaseDto.cs | 47 +++- .../Protocol3761/Dto/UnitDataAnalysis.cs | 24 +- .../Protocol3761/TB3761.cs | 5 + .../JiShe.CollectBus.Common/Enums/376Enums.cs | 46 ++++ .../Models/ServerApplicationOptions.cs | 5 + web/JiShe.CollectBus.Host/appsettings.json | 1 + 111 files changed, 6530 insertions(+), 111 deletions(-) create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F100_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F101_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F102_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F103_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F104_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F105_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F106_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F107_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F108_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F11_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F145_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F146_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F147_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F148_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F161_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F162_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F163_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F164_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F165_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F166_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F167_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F168_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F177_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F178_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F179_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F180_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F181_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F182_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F183_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F184_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F189_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F190_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F193_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F195_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F19_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F3_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F4_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F81_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F82_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F83_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F84_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F85_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F86_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F87_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F88_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F89_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F90_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F91_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F92_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F93_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F94_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F95_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F97_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F98_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F99_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs create mode 100644 protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs index 406beb9..59aa10b 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F1_Analysis.cs @@ -3,7 +3,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H +namespace JiShe.CollectBus.Protocol.T37612012.AFN_00H { /// /// 5.1.3.1 F1:全部确认:对收到报文中的全部数据单元标识进行确认 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs index 0871607..146c4b1 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_00H/AFN0_F2_Analysis.cs @@ -3,7 +3,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_00H +namespace JiShe.CollectBus.Protocol.T37612012.AFN_00H { /// /// 5.1.3.2 F2:全部否认 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 60ededf..1245d98 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.Protocol3761; using Microsoft.Extensions.Logging; using System.Text; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_09H +namespace JiShe.CollectBus.Protocol.T37612012.AFN_09H { /// /// 5.9.1.2 F1:终端版本信息 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs index ca64928..1ee40ff 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_09H/AFN9_F9_Analysis.cs @@ -5,7 +5,7 @@ using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; using System.Text; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_09H +namespace JiShe.CollectBus.Protocol.T37612012.AFN_09H { /// /// 5.9.2.4.9 F9:远程通信模块版本信息(只读解析SIM卡号) diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs index b410abe..70eefcf 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F10_Analysis.cs @@ -5,7 +5,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0AH { /// /// 5.10.1.3.1 F10:终端电能表/交流采样装置配置参数 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs index ced9573..7e4ab2f 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F66_Analysis.cs @@ -7,7 +7,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0AH { /// /// 5.5.1.3.53 F66:定时上报 2 类数据任务设置 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs index f87aaf3..8ef5af2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0AH/AFN10_F68_Analysis.cs @@ -3,7 +3,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0AH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0AH { /// /// 5.5.1.3.55 F68:定时上报 2 类数据任务启动/停止设置 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 2568aab..10cdd8d 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 @@ -4,7 +4,7 @@ using JiShe.CollectBus.IoTDB.Interface; using JiShe.CollectBus.IoTDB.Options; using JiShe.CollectBus.IoTDB.Provider; using JiShe.CollectBus.IotSystems.MeterReadingRecords; -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -12,7 +12,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.85 F129:当前正向有功电能示值(总、费率1~M) @@ -122,14 +122,5 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH } return list; } - - ///// - ///// 生成最终结果 - ///// - ///// - //public Task SaveIotDbAsync() - //{ - - //} } } diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs index a7c65a9..46ce427 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F130_Analysis.cs @@ -1,4 +1,4 @@ -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -6,7 +6,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.86 F130:当前正向无功(组合无功 1)电能示值(总、费率 1~M) diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs index 977b8f0..a537325 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F131_Analysis.cs @@ -1,4 +1,4 @@ -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -6,7 +6,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.87 F131:当前反向有功电能示值(总、费率 1~M) diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs index c6a0fc7..565fcb5 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F132_Analysis.cs @@ -1,4 +1,4 @@ -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -6,7 +6,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.88 F132:当前反向无功(组合无功 2)电能示值(总、费率 1~M) diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs index a718674..2f1c515 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F145_Analysis.cs @@ -1,5 +1,5 @@ using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -7,7 +7,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH +namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.101 F145:当月正向有功最大需量及发生时间(总、费率 1~M) 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 a79ed99..7280de5 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,48 +1,70 @@ -using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.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, "上月(上一结算日)正向有功最大需量及发生时间"); + AnalysisBaseDto data = GenerateFinalResult(2, datas, "上月(上一结算日)正向有功最大需量及发生时间"); data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; - UnitDataAnalysis unitDataAnalysis = new UnitDataAnalysis + data.FiledDesc = "上月(上一结算日)正向有功最大需量及发生时间"; + data.FiledName = data.DataType.GetDataFieldByGatherDataType() ?? string.Empty; + // 查询电表信息 + AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15"); + if (ammeterInfo != null) { - Code = input.A?.Code, - AFN = input.AFN_FC?.AFN ?? 0, - Fn = input.DT?.Fn ?? 0, - Pn = input.DA?.Pn ?? 0, - Data = data + 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) @@ -83,33 +105,38 @@ namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH } return values; } - public AFN12_F149_AnalysisDto GenerateFinalResult(int index, List data, string remark = "") + public AnalysisBaseDto GenerateFinalResult(int index, List data, string remark = "") { - 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; 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; } + 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 2d2b0c8..972bc9d 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 @@ -6,7 +6,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.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 94b1085..2f797e2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F25_Analysis.cs @@ -1,5 +1,5 @@ using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -7,7 +7,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.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 f636e92..e65fcef 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F2_Analysis.cs @@ -1,5 +1,5 @@ using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -7,7 +7,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.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 054c2c2..97dccff 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F33_Analysis.cs @@ -1,4 +1,4 @@ -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -6,7 +6,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.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 e6e42ec..39e9f49 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0CH/AFN12_F49_Analysis.cs @@ -1,5 +1,5 @@ using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Protocol.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; @@ -7,7 +7,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.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..94dc329 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F100_Analysis.cs @@ -0,0 +1,101 @@ +using IdentityModel; +using JiShe.CollectBus.Common.Consts; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using Volo.Abp.Domain.Entities; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.78 F100:测量点反向无功总电能量曲线 + /// + public class AFN13_F100_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F100_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "反向无功总电能量"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..937256e --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F101_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.79 F101:测量点正向有功总电能示值曲线 + /// + public class AFN13_F101_Analysis : IAnalysisStrategy>>> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F101_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "正向有功总电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..31d9b36 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F102_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.80 F102:测量点正向无功总电能示值曲线 + /// + public class AFN13_F102_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F102_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "正向无功总电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..d5e7c94 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F103_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.81 F103:测量点反向有功总电能示值曲线 + /// + public class AFN13_F103_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F103_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "反向有功总电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..f71dc85 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F104_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.82 F104:测量点反向无功总电能示值曲线 + /// + public class AFN13_F104_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F104_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "反向无功总电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..5856943 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F105_Analysis.cs @@ -0,0 +1,97 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "功率因数"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..87540e6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F106_Analysis.cs @@ -0,0 +1,98 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相功率因数"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..80d76ec --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F107_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.84 F107:测量点 B相功率因数曲线 + /// + public class AFN13_F107_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F107_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "B相功率因数"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..8bca6e2 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F108_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.84 F108:测量点 C相功率因数曲线 + /// + public class AFN13_F108_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F108_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + int density = Convert.ToInt32(Enum.GetName(typeof(DensityEnums), Convert.ToInt32(datas[1]))!.Split('_')[1]);//密度-间隔分钟数, + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + + List> data = datas.GenerateFinalResultTd_c(3, density, dataType, "C相功率因数"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..1f92932 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F11_Analysis.cs @@ -0,0 +1,149 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using System.Data; +using System.Diagnostics.Metrics; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH +{ + /// + /// 5.13.2.4.11 F11:抄表日冻结电能表正向有/无功最大需量及发生时间(总、费率 1~M,1≤M≤12) + /// + public class AFN13_F11_Analysis : IAnalysisStrategy>>> + { + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN13_F11_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task>>> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = await AnalysisDataUnitAsync(input.UnitData.HexMessageList); + string dataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"; + List> data = GenerateFinalResult(datas,3, dataType, "抄表日冻结电能表正向有功最大需量及发生时间"); + + // 查询电表信息 + //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_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 remark = "") + { + 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}"; + remark = i == 1 ? remark : remark.Replace("有功", "无功"); + 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..710cfe5 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F145_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "一象限无功电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..1cd7cc1 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F146_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "四象限无功电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..a52cc9a --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F147_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "二象限无功电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..a5e8c78 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F148_Analysis.cs @@ -0,0 +1,94 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "三象限无功电能示值"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..d3915c2 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F161_Analysis.cs @@ -0,0 +1,100 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Common.Extensions; +using System; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; + +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" }); + + // 查询电表信息 + //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_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..7621c18 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F162_Analysis.cs @@ -0,0 +1,97 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..30ac332 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F163_Analysis.cs @@ -0,0 +1,97 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..415dd32 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F164_Analysis.cs @@ -0,0 +1,99 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..a264b8f --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F165_Analysis.cs @@ -0,0 +1,99 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..73c29c0 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F166_Analysis.cs @@ -0,0 +1,98 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; + +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" }); + + // 查询电表信息 + //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_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..1ced283 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F167_Analysis.cs @@ -0,0 +1,98 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..c3f91aa --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F168_Analysis.cs @@ -0,0 +1,98 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..482cff8 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F177_Analysis.cs @@ -0,0 +1,99 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..50d29bc --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F178_Analysis.cs @@ -0,0 +1,99 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..9fa354f --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F179_Analysis.cs @@ -0,0 +1,98 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..450fe42 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F180_Analysis.cs @@ -0,0 +1,98 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..86ce0bb --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F181_Analysis.cs @@ -0,0 +1,98 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..058be3a --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F182_Analysis.cs @@ -0,0 +1,97 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..ee47b3c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F183_Analysis.cs @@ -0,0 +1,97 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..9e479f0 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F184_Analysis.cs @@ -0,0 +1,97 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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" }); + + // 查询电表信息 + //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_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..43e9b9b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F189_Analysis.cs @@ -0,0 +1,107 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "抄表日冻结正向有功最大需量及发生时间"); + + // 查询电表信息 + //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_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..bff2c25 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F190_Analysis.cs @@ -0,0 +1,139 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using System.Data; +using JiShe.CollectBus.Common.Extensions; + +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 remark = "") + { + 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; + } + 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..4e1bf70 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F193_Analysis.cs @@ -0,0 +1,128 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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 remark = "") + { + 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; + } + 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..43046e9 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F195_Analysis.cs @@ -0,0 +1,128 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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 remark = "") + { + 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; + } + 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..9baf7d4 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F19_Analysis.cs @@ -0,0 +1,144 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using System.Data; +using JiShe.CollectBus.Common.Extensions; + +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, "月冻结电能表正向有功最大需量及发生时间"); + + // 查询电表信息 + //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_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 remark = "") + { + 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}"; + + remark = i == 1 ? remark : remark.Replace("有功", "无功"); + 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..f2cf076 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F3_Analysis.cs @@ -0,0 +1,171 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using System.Data; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using Volo.Abp.Domain.Entities; + +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, "日冻结正向有/无功最大需量及发生时间"); + + // 查询电表信息 + //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_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 remark = "") + { + 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}"; + remark = i == 1 ? remark : remark.Replace("有功", "无功"); + 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..746bc5b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F4_Analysis.cs @@ -0,0 +1,172 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; +using AutoMapper.Internal.Mappers; + +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, "日冻结反向有/无功最大需量及发生时间"); + + // 查询电表信息 + //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_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 remark = "") + { + 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; + 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}"; + remark = i == 1 ? remark : remark.Replace("有功", "无功"); + 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_F81_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F81_Analysis.cs new file mode 100644 index 0000000..4fdb33c --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F81_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "有功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..f05e568 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F82_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相有功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..f145687 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F83_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相有功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..6a81677 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F84_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相有功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..9e9f6ca --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F85_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "无功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..ff89d97 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F86_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; + +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相无功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..2087066 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F87_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相无功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..c7378d0 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F88_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相无功功率曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..62c26f6 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F89_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相电压曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..95e0ef9 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F90_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相电压曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..bce14a8 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F91_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相电压曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..be935d7 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F92_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相电流曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..f0b52da --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F93_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相电流曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..dd5352b --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F94_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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相电流曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..a2de4f9 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F95_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "测量点零序电流曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..d496af4 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F97_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "正向有功总电能量曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..e65cbcc --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F98_Analysis.cs @@ -0,0 +1,95 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "正向无功总电能量曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(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..77deb95 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0DH/AFN13_F99_Analysis.cs @@ -0,0 +1,96 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; +using JiShe.CollectBus.Common.Extensions; + +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, "反向有功总电能量曲线"); + + // 查询电表信息 + //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 = density,//密度-间隔分钟数, + DensityUnit = DensityUnit.Minute + }; + //await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0D_99解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private async Task> AnalysisDataUnitAsync(List hexMessageList) + { + List values = new List(); + values.AddRange(hexMessageList.GetReadTimeTd_c(4, 7)); + int.TryParse(values[values.Count - 1], out int n); + + for (int i = 0; i < n; i++) + { + var arr = hexMessageList.GetRange(11 + (i * 4), 4); + var errorCode = arr.CheckErrorCode(); + if (errorCode != null) + values.Add(errorCode.Item1); + else + { + var value = await _analysisStrategyContext.ExecuteAsync, decimal>(nameof(Appendix_A13), arr); + values.Add(value.ToString()); + } + } + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs new file mode 100644 index 0000000..ecb3a3e --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_0EH/AFN14_F1_Analysis.cs @@ -0,0 +1,81 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AFN_00H; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0EH +{ + /// + /// 请求重要事件 + /// Item1=停电事件 + /// Item2=上电事件 + /// + public class AFN14_F1_Analysis : IAnalysisStrategy>> + { + private readonly ILogger _logger; + + public AFN14_F1_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task>> ExecuteAsync(TB3761 tB3761) + { + try + { + ArgumentNullException.ThrowIfNull(nameof(tB3761)); + ArgumentNullException.ThrowIfNull(nameof(tB3761.UnitData.HexMessageList)); + int erc = tB3761.UnitData.HexMessageList![8].HexToDec(); + bool isOnOffPower = erc.Equals(14) ? true : false; + if (!isOnOffPower) + { + throw new Exception($"ERC{erc}非上掉电事件"); + } + UnitDataAnalysis> dto = new UnitDataAnalysis> + { + Code = tB3761.A.Code!, + AFN = tB3761.AFN_FC.AFN, + Fn = tB3761.DT.Fn, + Pn = tB3761.DA.Pn, + Data = AnalysisDataUnit(tB3761.UnitData.HexMessageList) + }; + // meterData.DataType = "0E_1"; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"0E_1解析失败:{tB3761.A.Code}-{tB3761.DT.Fn}-{tB3761.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private Tuple AnalysisDataUnit(List hexMessageList) + { + /// Item1=停电事件 + /// Item2=上电事件 + return Tuple.Create(HandlerTime(hexMessageList.GetRange(10, 5)), HandlerTime(hexMessageList.GetRange(15, 5))); + } + /// + /// /解析时间 + /// + /// + /// 时间验证失败是否默认为当前时间 + /// + private string HandlerTime(List times) + { + var time = string.Empty; + try + { + times.Reverse(); + time = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{times[0]}-{times[1]}-{times[2]} {times[3]}:{times[4]}:00"; + + } + catch { } + return time; + } + } +} + diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs new file mode 100644 index 0000000..2f091c2 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F101_Analysis.cs @@ -0,0 +1,58 @@ +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AFN_09H; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using System.Text; + +namespace GatherService.WattMeter.AnalysisData.AFN_10H +{ + /// + /// 5.16.1.2.1 F1:透明转发 读取SIM卡信息 + /// + public class AFN16_F101_Analysis : IAnalysisStrategy> + { + private readonly ILogger _logger; + + public AFN16_F101_Analysis(ILogger logger) + { + _logger = logger; + } + + public Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList); + UnitDataAnalysis dto = new UnitDataAnalysis + { + Code = input.A.Code, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + Data = AnalysisDataUnit(input.UnitData.HexMessageList) //SIM卡 + }; + return Task.FromResult(dto); + } + catch (Exception ex) + { + _logger.LogError(ex, $"10_101解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); + return null; + } + } + private string AnalysisDataUnit(List hexMessageList) + { + //TODO:转发内容 + var dataArray = hexMessageList.Skip(18).ToList(); + var contentLengthArr = dataArray.Skip(1).Take(2).ToList(); + contentLengthArr.Reverse(); + int contentLength = string.Join("", contentLengthArr).HexToDec(); + var dataField = dataArray.Skip(3).Take(contentLength).ToList(); + var sim = string.Join("", dataField).TrimStart('0'); + return sim.Length != 20 ? "" : sim; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs new file mode 100644 index 0000000..d919425 --- /dev/null +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/AFN_10H/AFN16_F98_Analysis.cs @@ -0,0 +1,107 @@ +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; +using JiShe.CollectBus.Protocol.Contracts; +using JiShe.CollectBus.Protocol.Dto; +using JiShe.CollectBus.Protocol.Interfaces; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0DH; +using JiShe.CollectBus.Protocol.T37612012.AnalysisData; +using JiShe.CollectBus.Protocol.T37612012; +using JiShe.CollectBus.Protocol3761; +using Microsoft.Extensions.Logging; +using JiShe.CollectBus.Common.Extensions; + +namespace GatherService.WattMeter.AnalysisData.AFN_10H +{ + /// + /// 透明转发---跳合闸 + /// + public class AFN16_F98_Analysis : IAnalysisStrategy> + { + + private readonly ILogger _logger; + private readonly AnalysisStrategyContext _analysisStrategyContext; + private readonly DataStorage _dataStorage; + public AFN16_F98_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage) + { + _logger = logger; + _analysisStrategyContext = analysisStrategyContext; + _dataStorage = dataStorage; + } + + public async Task> ExecuteAsync(TB3761 input) + { + try + { + ArgumentNullException.ThrowIfNull(input); + ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList); + + List datas = AnalysisDataUnit(input.UnitData.HexMessageList); + + // 查询电表信息 + //AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(data.MeterType.ToString(), "15"); + //if (ammeterInfo != null) + //{ + // data.ProjectId = ammeterInfo.ProjectID; + // data.MeterId = ammeterInfo.MeterId; + // data.DatabaseBusiID = ammeterInfo.DatabaseBusiID; + // data.MeterAddress = ammeterInfo.AmmerterAddress; + //} + UnitDataAnalysis unitDataAnalysis = new UnitDataAnalysis + { + Code = input.A.Code!, + AFN = input.AFN_FC.AFN, + Fn = input.DT.Fn, + Pn = input.DA.Pn, + MSA = input.A.A3!.D1_D7!, + PSEQ = input.SEQ.PSEQ, + Data = (datas[2].Equals("9C") || datas[2].Equals("94")) ? true : false, + HexMessage = input.BaseHexMessage.HexMessageString, + MessageId = input.MessageId, + TimeDensity = 1,//密度-间隔分钟数, + DensityUnit = DensityUnit.Second + }; + //await _dataStorage.SaveDataToIotDbAsync(unitDataAnalysis); + return await Task.FromResult(unitDataAnalysis); + } + catch (Exception ex) + { + _logger.LogError(ex, $"10_98跳合闸解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage.HexMessageString},{ex.Message}"); + return null; + } + } + + private List AnalysisDataUnit(List hexMessageList) + { + List values = new List(); + values.Add(hexMessageList.GetRange(4, 1)[0].HexToDec().ToString());//端口号 + var contentLengthArr = hexMessageList.GetRange(5, 2); + contentLengthArr.Reverse(); + int contentLength = string.Join("", contentLengthArr).HexToDec(); + //TODO:转发内容 + List contentArr = hexMessageList.GetRange(7, contentLength); + //TODO:表地址 + var addressList = contentArr.GetRange(1, 6); + addressList.Reverse(); + var address = string.Join("", addressList); + values.Add(address); + //TODO:控制码 + var controlCode = contentArr.GetRange(8, 1)[0]; + values.Add(controlCode); + //TODO:长度 + //var len = contentArr.GetRange(9, 1)[0].DataConvert(16); + //values.Add(len.ToString()); + //TODO:数据域 + //var dataField = contentArr.GetRange(10, len); + //if (dataField.Count > 0) + //{ + // string dataMark = string.Join("", CalculateErrControl(dataField.GetRange(0, 4))); + // values.Add(dataMark);//数据标识 + // var readValue = CalculateErrControl(dataField.GetRange(4, len - 4));//值 + // var valueData = GetValue>(readValue, (AppendixEnums)Enum.Parse(typeof(AppendixEnums), dataMark)); + // values.AddRange(valueData); + //} + + return values; + } + } +} diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs index 574a207..94a4d3f 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/AnalysisData/DataStorage.cs @@ -1,17 +1,146 @@ -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); + } + } } diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs index 1c6372b..ae83974 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_02800002.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 2 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs index c56d7fc..5b48334 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000201.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 年时区数 p≤14 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs index 465d461..a9af412 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000202.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 日时段表数 q≤8 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs index f35f34f..206078f 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000203.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 日时段数(每日切换数) m≤14 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs index ee012f0..3e8b64d 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04000204.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 费率数 k≤63 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs index cbbb021..0d3fbe2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010000.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套时区表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs index 4e3ecd4..4983fe2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010001.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 1 日时段表数据: diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs index 31a5f45..9d8fbd4 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010002.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 2 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs index d4588d7..6417681 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010003.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 3 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs index f16bf26..5eb42be 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010004.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 4 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs index ebeb20e..d6272c2 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010005.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 5 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs index 6660605..97e1fab 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010006.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 6 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs index 50220f9..31dd6c0 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010007.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 7 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs index c6da235..23984fd 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_04010008.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 第一套第 8 日时段表数据 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs index 22127e3..f0ea795 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A1.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A1 : IAnalysisStrategy, string> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs index 16655ec..40d9580 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A11.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 附录A.11数据格式 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs index 47d8413..9c0cb36 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A13.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 附录A.13数据格式 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs index 4ffb948..8d67953 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A14.cs @@ -2,7 +2,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { /// /// 附录A.14数据格式 diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs index c8049cd..8b2a4d5 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A15.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.Logging; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A15 : IAnalysisStrategy, string> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs index e2b40e6..93e1939 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A17.cs @@ -1,6 +1,6 @@ using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A17 : IAnalysisStrategy, string> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs index f63bb10..7a10686 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A23.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A23 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs index 38b39ae..094e468 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A25.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A25 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs index 05847d1..31fb8f1 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A5.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A5 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs index 9e7a8ad..63dcd65 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A7.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A7 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs index 9f99a80..f6845c9 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Appendix/Appendix_A9.cs @@ -1,7 +1,7 @@ using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Interfaces; -namespace JiShe.CollectBus.Protocol.AnalysisData.Appendix +namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix { public class Appendix_A9 : IAnalysisStrategy, decimal> { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/CollectBusProtocolT37612012Module.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/CollectBusProtocolT37612012Module.cs index a53107c..33c1be3 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/CollectBusProtocolT37612012Module.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/CollectBusProtocolT37612012Module.cs @@ -5,7 +5,7 @@ using System.Reflection; using Volo.Abp; using Volo.Abp.Modularity; -namespace JiShe.CollectBus.Protocol.Contracts +namespace JiShe.CollectBus.Protocol.T37612012 { public class CollectBusProtocolT37612012Module : AbpModule { diff --git a/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs b/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs index 6f8985a..5a04d38 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/Protocol3761Extensions.cs @@ -1,12 +1,11 @@ -using JiShe.CollectBus.Common.Extensions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +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; -using System.Threading.Tasks; -namespace JiShe.CollectBus.Protocol +namespace JiShe.CollectBus.Protocol.T37612012 { public static class Protocol3761Extensions { @@ -125,5 +124,232 @@ namespace JiShe.CollectBus.Protocol } + /// + /// 判断当前时间所在时标(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 remark = "") + { + 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 = remark; + 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 remark = "") + { + 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}"; + + list.Add(meter); + } + return list; + } + + /// + /// 日冻结 + /// + /// + /// + /// + /// + public static List> GenerateFinalResultTd_d(this List data, int index,string dataType, string timeSpan, string remark = "") + { + 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}"; + 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 7c6175f..69e024c 100644 --- a/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T37612012/T37612012ProtocolPlugin.cs @@ -18,7 +18,7 @@ using Microsoft.Extensions.Logging; using TouchSocket.Sockets; using Volo.Abp.Domain.Repositories; -namespace JiShe.CollectBus.Protocol +namespace JiShe.CollectBus.Protocol.T37612012 { public class T37612012ProtocolPlugin : ProtocolPlugin { @@ -113,7 +113,7 @@ namespace JiShe.CollectBus.Protocol 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, @@ -121,7 +121,7 @@ namespace JiShe.CollectBus.Protocol ClientPort = tcpSessionClient.Port, MessageHexString = tB3761.BaseHexMessage.HexMessageString!, DeviceNo = tB3761.A.Code!, - MessageId = Guid.NewGuid().ToString(), + MessageId = tB3761.MessageId, ReceivedTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Data = tB3761 }; diff --git a/services/JiShe.CollectBus.Domain/Protocol3761/Dto/AnalysisBaseDto.cs b/services/JiShe.CollectBus.Domain/Protocol3761/Dto/AnalysisBaseDto.cs index 49f9054..a18294c 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; @@ -22,17 +24,54 @@ namespace JiShe.CollectBus.Protocol.Contracts.Protocol.Dto /// /// 错误码信息 /// - 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/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..1ee07a4 100644 --- a/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs +++ b/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs @@ -19,5 +19,10 @@ /// 自动验证时间 /// public required string AutomaticVerificationTime { get; set;} + + /// + /// 系统类型 + /// + public required string SystemType { get; set;} } } diff --git a/web/JiShe.CollectBus.Host/appsettings.json b/web/JiShe.CollectBus.Host/appsettings.json index 4bd24be..a16c67f 100644 --- a/web/JiShe.CollectBus.Host/appsettings.json +++ b/web/JiShe.CollectBus.Host/appsettings.json @@ -142,6 +142,7 @@ "PlugInFolder": "", "ServerApplicationOptions": { "ServerTagName": "JiSheCollectBus100", + "SystemType": null, "FirstCollectionTime": "2025-04-22 16:07:00", "AutomaticVerificationTime": "16:07:00" }