diff --git a/Ems.CollectService.Analysis/BufferAnalysis.cs b/Ems.CollectService.Analysis/BufferAnalysis.cs index 7d14cf0..9a4aa7b 100644 --- a/Ems.CollectService.Analysis/BufferAnalysis.cs +++ b/Ems.CollectService.Analysis/BufferAnalysis.cs @@ -7,6 +7,7 @@ using NetTaste; using NLog; using SqlSugar; using System; +using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Net.Sockets; @@ -24,6 +25,8 @@ namespace Ems.CollectService.Analysis private MsgUtil msgUtil = MsgUtil.Instance; private AppConfig appConfig = AppConfig.Instance; + + private JsonChange jsonChange = JsonChange.Instance; //private SqlSugarClient baseService = SqlGenerator.GetMySqlInstance(); @@ -576,10 +579,12 @@ namespace Ems.CollectService.Analysis } }catch(Exception ex) { - logger.Error($"仪表:{recordDnbInstant.monitorId}数据保存异常:{ex.Message}"); + logger.Info($"仪表:{recordDnbInstant.monitorId}数据保存异常:{ex.Message}"); } } + private Dictionary monitorInstant = new Dictionary(); + /// /// 过滤数据,与前一条相差超过4000不进行保存 /// @@ -589,47 +594,84 @@ namespace Ems.CollectService.Analysis { bool result = true; - do + try { - RecordDnbInstant lastDnbInstant = SqlSugarHelper.Db.Queryable() - .First(x => x.monitorId == dnbInstant.monitorId); - - if (lastDnbInstant == null) + do { - break; - } + + List filterMonitorId = new List(){ "E0076_0100", "E0076_0200", "E0076_0300", "E0076_0400" }; + if (!filterMonitorId.Contains(dnbInstant.monitorId)) + { + break; + } + + if (!monitorInstant.ContainsKey(dnbInstant.monitorId)) + { + logger.Info($"本地未获取到{dnbInstant.monitorId};"); + monitorInstant.Add(dnbInstant.monitorId,(decimal)dnbInstant.zxyg); + logger.Info($"本地缓存{dnbInstant.monitorId};数据:{dnbInstant.zxyg}"); + break; + } - BaseMonitorInfo monitorInfo = SqlSugarHelper.Db.Queryable() - .First(x => x.MonitorId == dnbInstant.monitorId); + logger.Info($"校验判断{dnbInstant.monitorId};"); + var lastDnbInstant = monitorInstant[dnbInstant.monitorId]; + logger.Info($"本地缓存{dnbInstant.monitorId};前一条数据:{dnbInstant.zxyg}"); + /*RecordDnbInstant lastDnbInstant = SqlSugarHelper.Db.Queryable() + .OrderByDescending(x => x.collectTime) + .First(x => x.monitorId == dnbInstant.monitorId); - if (monitorInfo == null) - { - result = false; - break; - } + if (lastDnbInstant == null) + { + break; + }*/ - if (monitorInfo.Pt == 0 || monitorInfo.Pt == null) - { - monitorInfo.Pt = 1; - } - - if (monitorInfo.Ct == 0 || monitorInfo.Ct == null) - { - monitorInfo.Ct = 1; - } + BaseMonitorInfo monitorInfo = SqlSugarHelper.Db.Queryable() + .First(x => x.MonitorId == dnbInstant.monitorId); - decimal? lastZxyg = lastDnbInstant.zxyg * monitorInfo.Pt * monitorInfo.Ct; + if (monitorInfo == null) + { + result = false; + break; + } - decimal? dnbInstantZxyg = dnbInstant.zxyg * monitorInfo.Pt * monitorInfo.Ct; + if (monitorInfo.Pt == 0 || monitorInfo.Pt == null) + { + monitorInfo.Pt = 1; + } - decimal? zxygRes = dnbInstantZxyg - lastZxyg; - var appConfigDifferenceValue = appConfig.differenceValue == 0 ? 4000 : appConfig.differenceValue; - if ( zxygRes >= appConfigDifferenceValue) - { - logger.Info($"仪表:{dnbInstant.monitorId}与上一条数据相差超过4000,不进行保存"); - result = false; - } - } while (false); + if (monitorInfo.Ct == 0 || monitorInfo.Ct == null) + { + monitorInfo.Ct = 1; + } + + decimal? lastZxyg = lastDnbInstant * monitorInfo.Pt * monitorInfo.Ct; + + decimal? dnbInstantZxyg = dnbInstant.zxyg * monitorInfo.Pt * monitorInfo.Ct; + + decimal? zxygRes = dnbInstantZxyg - lastZxyg; + var appConfigDifferenceValue = appConfig.differenceValue == 0 ? 4000 : appConfig.differenceValue; + logger.Info($"仪表:{dnbInstant.monitorId};PT:{monitorInfo.Pt};CT:{monitorInfo.Ct};当前数据:{dnbInstant.zxyg};上一条数据:{lastDnbInstant}"); + + monitorInstant[dnbInstant.monitorId] = (decimal)dnbInstant.zxyg; + logger.Info($"更新本地缓存{dnbInstant.monitorId};数据:{dnbInstant.zxyg}"); + + if (zxygRes >= appConfigDifferenceValue) + { + logger.Info($"仪表:{dnbInstant.monitorId};与前一条数据相差:{zxygRes};超过4000,不进行保存"); + result = false; + } + + /*if (dnbInstant.zxyg == 0) + { + logger.Info($"仪表:{dnbInstant.monitorId}数据为0,不进行保存"); + result = false; + }*/ + } while (false); + } + catch (Exception e) + { + logger.Info($"仪表:{dnbInstant.monitorId}数据过滤异常:{e.Message}"); + } return result; }