change - 修改本地缓存并发异常问题

master
wenjy 8 months ago
parent af9c465360
commit 2ebb5b9222

@ -7,6 +7,7 @@ using NetTaste;
using NLog; using NLog;
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SqlTypes; using System.Data.SqlTypes;
using System.Linq; using System.Linq;
@ -552,10 +553,13 @@ namespace Ems.CollectService.Analysis
{ {
if (recordDnbInstant.zxyg != appConfig.virtualValue) if (recordDnbInstant.zxyg != appConfig.virtualValue)
{ {
var info = SqlSugarHelper.Db.Insertable<RecordDnbInstant>(recordDnbInstant).ExecuteCommand(); if (FIlterDnbInstant(recordDnbInstant))
if (info > 0)
{ {
logger.Info($"仪表:{recordDnbInstant.monitorId}数据保存成功"); var info = SqlSugarHelper.Db.Insertable<RecordDnbInstant>(recordDnbInstant).ExecuteCommand();
if (info > 0)
{
logger.Info($"仪表:{recordDnbInstant.monitorId}数据保存成功");
}
} }
} }
else else
@ -583,7 +587,7 @@ namespace Ems.CollectService.Analysis
} }
} }
private Dictionary<string, decimal> monitorInstant = new Dictionary<string, decimal>(); private ConcurrentDictionary<string, decimal> monitorInstant = new ConcurrentDictionary<string, decimal>();
/// <summary> /// <summary>
/// 过滤数据与前一条相差超过4000不进行保存 /// 过滤数据与前一条相差超过4000不进行保存
@ -608,14 +612,14 @@ namespace Ems.CollectService.Analysis
if (!monitorInstant.ContainsKey(dnbInstant.monitorId)) if (!monitorInstant.ContainsKey(dnbInstant.monitorId))
{ {
logger.Info($"本地未获取到{dnbInstant.monitorId};"); logger.Info($"本地未获取到{dnbInstant.monitorId};");
monitorInstant.Add(dnbInstant.monitorId,(decimal)dnbInstant.zxyg); monitorInstant.TryAdd(dnbInstant.monitorId,(decimal)dnbInstant.zxyg);
logger.Info($"本地缓存{dnbInstant.monitorId};数据:{dnbInstant.zxyg}"); logger.Info($"本地缓存{dnbInstant.monitorId};数据:{dnbInstant.zxyg}");
break; break;
} }
logger.Info($"校验判断{dnbInstant.monitorId};"); logger.Info($"校验判断{dnbInstant.monitorId};");
var lastDnbInstant = monitorInstant[dnbInstant.monitorId]; var lastDnbInstant = monitorInstant[dnbInstant.monitorId];
logger.Info($"本地缓存{dnbInstant.monitorId};前一条数据:{dnbInstant.zxyg}"); logger.Info($"本地缓存{dnbInstant.monitorId};前一条数据:{lastDnbInstant}");
/*RecordDnbInstant lastDnbInstant = SqlSugarHelper.Db.Queryable<RecordDnbInstant>() /*RecordDnbInstant lastDnbInstant = SqlSugarHelper.Db.Queryable<RecordDnbInstant>()
.OrderByDescending(x => x.collectTime) .OrderByDescending(x => x.collectTime)
.First(x => x.monitorId == dnbInstant.monitorId); .First(x => x.monitorId == dnbInstant.monitorId);
@ -655,6 +659,12 @@ namespace Ems.CollectService.Analysis
monitorInstant[dnbInstant.monitorId] = (decimal)dnbInstant.zxyg; monitorInstant[dnbInstant.monitorId] = (decimal)dnbInstant.zxyg;
logger.Info($"更新本地缓存{dnbInstant.monitorId};数据:{dnbInstant.zxyg}"); logger.Info($"更新本地缓存{dnbInstant.monitorId};数据:{dnbInstant.zxyg}");
if (zxygRes < 0)
{
logger.Info($"仪表:{dnbInstant.monitorId};与前一条数据相差:{zxygRes};小于0不进行保存");
result = false;
}
if (zxygRes >= appConfigDifferenceValue) if (zxygRes >= appConfigDifferenceValue)
{ {
logger.Info($"仪表:{dnbInstant.monitorId};与前一条数据相差:{zxygRes};超过4000不进行保存"); logger.Info($"仪表:{dnbInstant.monitorId};与前一条数据相差:{zxygRes};超过4000不进行保存");

@ -60,21 +60,7 @@ namespace Ems.CollectService.Entity
///</summary> ///</summary>
[SugarColumn(ColumnName="grade" )] [SugarColumn(ColumnName="grade" )]
public int? Grade { get; set; } public int? Grade { get; set; }
/// <summary>
/// 建筑类型
///</summary>
[SugarColumn(ColumnName="build_id" )]
public string BuildId { get; set; }
/// <summary>
/// 分项类型
///</summary>
[SugarColumn(ColumnName="subentry_id" )]
public string SubentryId { get; set; }
/// <summary>
/// 业态类型
///</summary>
[SugarColumn(ColumnName="business_id" )]
public string BusinessId { get; set; }
/// <summary> /// <summary>
/// 传感器仪表 /// 传感器仪表
///</summary> ///</summary>

Loading…
Cancel
Save