lixiaojun
2022-09-05 b29e9fbda8096ce7255864cd2d63122cca60b952
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IStation.RedisCache;
 
namespace IStation.Service
{
    /// <summary>
    /// 实时监测记录
    /// </summary>
    public partial class MonitorRecord
    {
        #region 最近一条记录
 
        /// <summary>
        /// 获取最近一条记录
        /// </summary>
        public Model.MonitorRecord GetLastRecord(long monitorPointId)
        {
            var redisHelper = new MonitorRecordCacheHelper();
            var record = redisHelper.GetLastRecord(monitorPointId);
            return record;
        }
 
        /// <summary>
        /// 获取最近一条记录
        /// </summary>
        public List<Model.MonitorRecord> GetLastRecord(IEnumerable<long> monitorPointIds)
        {
            if (monitorPointIds == null || monitorPointIds.Count() < 1)
                return default;
            var redisHelper = new MonitorRecordCacheHelper();
            var record = redisHelper.GetLastRecord(monitorPointIds);
            return record;
        } 
 
        #endregion
 
        #region Query
 
        /// <summary>
        /// 获取所有
        /// </summary>
        public List<Model.MonitorRecord> GetAll()
        {
            var dal = new DAL.MonitorRecord();
            var all = dal.GetAll();
            return Entity2Models(all);
        }
 
 
        #endregion
 
        #region 通过 MonitorPointID 获取
 
        /// <summary>
        /// 通过 MonitorPointID 获取某一天的数据
        /// </summary>
        public List<Model.MonitorRecord> GetByMonitorPointIDOfDay( long MonitorPointID, DateTime Day)
        {
            var dal = new DAL.MonitorRecord();
            var entity_list = dal.GetByMonitorPointIDOfDay( MonitorPointID, Day);
            return Entity2Models(entity_list);
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取日期区间内的数据
        /// </summary>
        public List<Model.MonitorRecord> GetByMonitorPointIDOfDayRange(long MonitorPointID, DateTime StartDay, DateTime EndDay)
        {
            if (StartDay.Date > EndDay.Date)
                return default;
            var dal = new DAL.MonitorRecord();
            var entity_list = dal.GetByMonitorPointIDOfDayRange(MonitorPointID, StartDay, EndDay);
            return Entity2Models(entity_list);
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取时间区间内的数据
        /// </summary>
        public List<Model.MonitorRecord> GetByMonitorPointIDOfTimeRange( long MonitorPointID, DateTime StartTime, DateTime EndTime)
        {
            if (StartTime > EndTime)
                return default;
            var dal = new DAL.MonitorRecord();
            var entity_list = dal.GetByMonitorPointIDOfTimeRange( MonitorPointID, StartTime, EndTime);
            return Entity2Models(entity_list);
        }
 
        #endregion
 
        #region Insert
 
        /// <summary>
        /// 插入一条
        /// </summary>
        public long Insert(Model.MonitorRecord model)
        {
            if (model == null)
                return default;
            var dal = new DAL.MonitorRecord();
            var entity = Model2Entity(model);
            var id = dal.Insert(entity);
            return id;
        }
 
        /// <summary>
        /// 插入多条
        /// </summary>
        public bool Inserts(List<Model.MonitorRecord> list)
        {
            if (list == null || list.Count < 1)
                return false;
            var dal = new DAL.MonitorRecord();
            var entity_list = Model2Entities(list);
            var bol = dal.Inserts(entity_list);
            return bol;
        }
 
 
        /// <summary>
        /// 插入最近一条记录
        /// </summary>
        public bool InsertLastRecord(Model.MonitorRecord model)
        {
            if (model == null)
                return default;
            var queueHelper = new RabbitMqQueueHelper();
            var bol = queueHelper.Push(ConfigHelper.StoreQueueName, new List<Model.MonitorRecord> { model });
            if (bol)
            {
                var redisHelper = new MonitorRecordCacheHelper();
                redisHelper.SetLastRecord(model);
            }
 
            return bol;
        }
 
        /// <summary>
        /// 插入最近多条记录
        /// </summary>
        public bool InsertsLastRecord(List<Model.MonitorRecord> list)
        {
            if (list == null || list.Count() < 1)
                return default;
            var queueHelper = new RabbitMqQueueHelper();
            var bol = queueHelper.Push(ConfigHelper.StoreQueueName, list);
            if (bol)
            {
                var redisHelper = new MonitorRecordCacheHelper();
                redisHelper.SetLastRecord(list);
            }
            return bol;
        }
 
        
      
        #endregion
 
 
    }
}