lixiaojun
2023-04-12 fc6b7c9852f18e42fb9bccaf0cc22fbe5389d179
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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();
        }
 
 
    }
}