lixiaojun
2022-08-09 c7c696753fbe0b8ebf56eb6cfe584601a36c5fb2
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.Server
{
    /// <summary>
    /// 报警监测记录缓存辅助类
    /// </summary>
    public class MonitorRecord4AlarmCacheHelper 
    {
        //记录列表
        private static readonly List<Model.MonitorBasicRecord> _recordList = new List<Model.MonitorBasicRecord>();
        //数据不变记录列表
        private static readonly List<Model.MonitorBasicRecord> _unChangedRecordList = new List<Model.MonitorBasicRecord>();
 
        /// <summary>
        /// 设置
        /// </summary>
        public static void Set(List<Model.MonitorBasicRecord> list)
        {
            if (list == null || list.Count < 1)
                return;
            list.ForEach(x => {
                _recordList.RemoveAll(t=>t.CorpID==x.CorpID&&t.MonitorPointID==x.MonitorPointID&&t.SignalID==x.SignalID);
                _recordList.Add(x);
                var lastUnChangedRecord = _unChangedRecordList.Find(t => t.CorpID == x.CorpID && t.MonitorPointID == x.MonitorPointID && t.SignalID == x.SignalID);
                if (lastUnChangedRecord == null)
                {
                    _unChangedRecordList.Add(x);
                }
                else
                {
                    if (lastUnChangedRecord.DataValue != x.DataValue)
                    {
                        _unChangedRecordList.RemoveAll(t => t.CorpID == x.CorpID && t.MonitorPointID == x.MonitorPointID && t.SignalID == x.SignalID);
                        _unChangedRecordList.Add(x);
                    }
                }
            });
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取
        /// </summary>
        public static List<Model.MonitorBasicRecord> GetByMonitorPointID(long CorpID, long MonitorPointID)
        {
            return _recordList.Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID).ToList();
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取第一条
        /// </summary>
        public static Model.MonitorBasicRecord GetFirstByMonitorPointID(long CorpID, long MonitorPointID)
        {
            return _recordList.FirstOrDefault(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID);
        }
 
        /// <summary>
        /// 通过 SignalID 获取
        /// </summary> 
        public static Model.MonitorBasicRecord GetBySignalID(long CorpID, long MonitorPointID, long SignalID) 
        {
            return _recordList.Find(x=>x.CorpID==CorpID&&x.MonitorPointID==MonitorPointID&&x.SignalID==SignalID);
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取不变的
        /// </summary>
        public static List<Model.MonitorBasicRecord> GetUnChangedByMonitorPointID(long CorpID, long MonitorPointID)
        {
            return _unChangedRecordList.Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID).ToList();
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取不变的第一条
        /// </summary>
        public static Model.MonitorBasicRecord GetFirstUnChangedByMonitorPointID(long CorpID, long MonitorPointID)
        {
            return _unChangedRecordList.FirstOrDefault(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID);
        }
 
        /// <summary>
        /// 通过 SignalID 获取不变的
        /// </summary> 
        public static Model.MonitorBasicRecord GetUnChangedBySignalID(long CorpID, long MonitorPointID, long SignalID) 
        {
            return _unChangedRecordList.Find(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID && x.SignalID == SignalID);
        }
 
 
 
    }
}