using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Server
|
{
|
public class RecordCacheHelper
|
{
|
private static Dictionary<long, List<Model.MonitorBasicRecord>> _dict = new Dictionary<long, List<Model.MonitorBasicRecord>>();
|
|
|
/// <summary>
|
/// 设置缓存
|
/// </summary>
|
public static void Set(long CorpID, IEnumerable<Model.MonitorBasicRecord> list)
|
{
|
if (list == null)
|
list = new List<Model.MonitorBasicRecord>();
|
if (_dict.ContainsKey(CorpID))
|
{
|
if (_dict[CorpID] == null)
|
{
|
_dict[CorpID] = new List<Model.MonitorBasicRecord>();
|
}
|
var cache = _dict[CorpID];
|
list.ToList().ForEach(x =>
|
{
|
cache.RemoveAll(t => t.MonitorPointID == x.MonitorPointID && t.SignalID == x.SignalID);
|
cache.Add(x);
|
});
|
}
|
else
|
{
|
_dict.Add(CorpID, list.ToList());
|
}
|
}
|
|
/// <summary>
|
/// 获取缓存
|
/// </summary>
|
public static List<Model.MonitorBasicRecord> Get(long CorpID, IEnumerable<long> MonitorPointIds)
|
{
|
if (MonitorPointIds == null || MonitorPointIds.Count() < 1)
|
return default;
|
if (!_dict.ContainsKey(CorpID))
|
{
|
return default;
|
}
|
if (_dict[CorpID] == null)
|
_dict[CorpID] = new List<Model.MonitorBasicRecord>();
|
var cache = _dict[CorpID];
|
return cache.Where(x => MonitorPointIds.Contains(x.MonitorPointID)).ToList();
|
}
|
|
|
}
|
}
|