diff --git a/Ems.CollectService.Analysis/BufferAnalysis.cs b/Ems.CollectService.Analysis/BufferAnalysis.cs index 8aae9eb..7d14cf0 100644 --- a/Ems.CollectService.Analysis/BufferAnalysis.cs +++ b/Ems.CollectService.Analysis/BufferAnalysis.cs @@ -565,10 +565,13 @@ namespace Ems.CollectService.Analysis recordDnbInstant.zxyg = recordDnbInstant.zxyg == appConfig.virtualValue ? 0 : recordDnbInstant.zxyg; - var info = SqlSugarHelper.Db.Insertable(recordDnbInstant).ExecuteCommand(); - if (info > 0) + if (FIlterDnbInstant(recordDnbInstant)) { - logger.Info($"仪表:{recordDnbInstant.monitorId}数据保存成功"); + var info = SqlSugarHelper.Db.Insertable(recordDnbInstant).ExecuteCommand(); + if (info > 0) + { + logger.Info($"仪表:{recordDnbInstant.monitorId}数据保存成功"); + } } } }catch(Exception ex) @@ -577,6 +580,60 @@ namespace Ems.CollectService.Analysis } } + /// + /// 过滤数据,与前一条相差超过4000不进行保存 + /// + /// + /// + private bool FIlterDnbInstant(RecordDnbInstant dnbInstant) + { + bool result = true; + + do + { + RecordDnbInstant lastDnbInstant = SqlSugarHelper.Db.Queryable() + .First(x => x.monitorId == dnbInstant.monitorId); + + if (lastDnbInstant == null) + { + break; + } + + BaseMonitorInfo monitorInfo = SqlSugarHelper.Db.Queryable() + .First(x => x.MonitorId == dnbInstant.monitorId); + + if (monitorInfo == null) + { + result = false; + break; + } + + if (monitorInfo.Pt == 0 || monitorInfo.Pt == null) + { + monitorInfo.Pt = 1; + } + + if (monitorInfo.Ct == 0 || monitorInfo.Ct == null) + { + monitorInfo.Ct = 1; + } + + decimal? lastZxyg = lastDnbInstant.zxyg * monitorInfo.Pt * monitorInfo.Ct; + + decimal? dnbInstantZxyg = dnbInstant.zxyg * monitorInfo.Pt * monitorInfo.Ct; + + decimal? zxygRes = dnbInstantZxyg - lastZxyg; + var appConfigDifferenceValue = appConfig.differenceValue == 0 ? 4000 : appConfig.differenceValue; + if ( zxygRes >= appConfigDifferenceValue) + { + logger.Info($"仪表:{dnbInstant.monitorId}与上一条数据相差超过4000,不进行保存"); + result = false; + } + } while (false); + + return result; + } + /// /// 水表数据 /// diff --git a/Ems.CollectService.Entity/config/AppConfig.cs b/Ems.CollectService.Entity/config/AppConfig.cs index f8c0170..cbe4431 100644 --- a/Ems.CollectService.Entity/config/AppConfig.cs +++ b/Ems.CollectService.Entity/config/AppConfig.cs @@ -58,6 +58,14 @@ namespace Ems.CollectService.Entity.config get { return _configuration.GetValue("SystemConfig:virtualFlag") == "是" ? true : false;} } + /// + /// 是否启用点抄功能 + /// + public bool readMeterFlag + { + get { return _configuration.GetValue("SystemConfig:readMeterFlag") == "是" ? true : false;} + } + /// /// 日志文件路径 /// @@ -73,5 +81,10 @@ namespace Ems.CollectService.Entity.config { get { return _configuration.GetValue("SystemConfig:deleteLogTimer"); } } + + public int differenceValue + { + get { return _configuration.GetValue("SystemConfig:differenceValue"); } + } } } diff --git a/Ems.CollectService.TouchSocket/TcpServer.cs b/Ems.CollectService.TouchSocket/TcpServer.cs index 013c811..d5c5dae 100644 --- a/Ems.CollectService.TouchSocket/TcpServer.cs +++ b/Ems.CollectService.TouchSocket/TcpServer.cs @@ -86,7 +86,6 @@ namespace Ems.CollectService.TouchSocket })) .Start();//启动 - ReadMeterTask(); //点抄指令下发 logger.Info($"采集服务启动成功,监听端口:{serverPort}"); } catch(Exception ex) @@ -172,8 +171,13 @@ namespace Ems.CollectService.TouchSocket /// /// 点抄指令下发 /// - private void ReadMeterTask() + public void ReadMeterTask(bool isFlag = false) { + if (isFlag == false) + { + logger.Info($"未启用点抄仪表功能"); + return; + } try { var t = Task.Run(async delegate diff --git a/Ems.CollectService/Program.cs b/Ems.CollectService/Program.cs index 926b22c..da9bcbb 100644 --- a/Ems.CollectService/Program.cs +++ b/Ems.CollectService/Program.cs @@ -23,6 +23,7 @@ namespace Ems.CollectService try { service.Init(appConfig.listenerPort); + service.ReadMeterTask(appConfig.readMeterFlag); //定时删除日志文件夹 deleteLogFile.DeleteLogFileTimer(); }