tangxu
2022-11-02 05f522e321a742f03bf1e3e26edaeb5147da42f4
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
 
namespace IStation.DAL
{
    /// <summary>
    /// 监测报警记录 
    /// </summary>
    public partial class MonitorAlarmRecord : CorpDAL<Entity.MonitorAlarmRecord>
    {
        /// <summary>
        /// 
        /// </summary>
        public override ConnectionConfig ConnectionConfig
        {
            get { return ConfigHelper.MonitorRecordConnectionConfig; }
        }
 
        /// <summary>
        /// 通过 ConfigureID 获取
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetByConfigureID(long CorpID, long ConfigureID)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && x.ConfigureID == ConfigureID)
                    .OrderBy(x => x.AlarmTime,OrderByType.Asc).ToList();
            }
        }
 
        /// <summary>
        /// 通过 ConfigureID 获取某天的报警数据
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetByConfigureIDOfDay(long CorpID, long ConfigureID, DateTime Day)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && x.ConfigureID == ConfigureID && x.AlarmTime >= Day.Date && x.AlarmTime < Day.AddDays(1).Date)
                    .OrderBy(x => x.AlarmTime, OrderByType.Asc).ToList();
            }
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetByMonitorPointID(long CorpID, long MonitorPointID)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID)
                    .OrderBy(x => x.AlarmTime, OrderByType.Asc).ToList();
            }
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取某天的数据
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetByMonitorPointIDOfDay(long CorpID, long MonitorPointID, DateTime Day)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID && x.AlarmTime >= Day.Date && x.AlarmTime < Day.AddDays(1).Date)
                    .OrderBy(x => x.AlarmTime, OrderByType.Asc).ToList();
            }
        }
 
        /// <summary>
        /// 通过 CorpID 获取最后几条数据
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetLastByCorpID(long CorpID, int Number)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID)
                    .OrderBy(x => x.AlarmTime, OrderByType.Desc).Take(Number).ToList();
            }
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取最后几条数据
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetLastByMonitorPointID(long CorpID, long MonitorPointID, int Number)
        {
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID)
                    .OrderBy(x => x.AlarmTime, OrderByType.Desc).Take(Number).ToList();
            }
        }
 
        /// <summary>
        /// 获取数量
        /// </summary>
        public int GetCount
            (long CorpID, List<long> MonitorPointIds, string AlarmType, int? AlarmLevel, int? HandleStatus, DateTime? StartTime, DateTime? EndTime)
        {
            var exp = Expressionable.Create<Entity.MonitorAlarmRecord>();
            exp.And(x => x.CorpID == CorpID);
            exp.AndIF(MonitorPointIds!=null&&MonitorPointIds.Count>0,x=>MonitorPointIds.Contains(x.MonitorPointID));
            exp.AndIF(!string.IsNullOrEmpty(AlarmType), x => x.AlarmType == AlarmType);
            exp.AndIF(AlarmLevel.HasValue, x => x.AlarmLevel == AlarmLevel.Value);
            exp.AndIF(HandleStatus.HasValue, x => x.HandleStatus == HandleStatus);
            exp.AndIF(StartTime.HasValue, x => x.AlarmTime >= StartTime.Value);
            exp.AndIF(EndTime.HasValue, x => x.AlarmTime <= EndTime.Value);
 
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>().Where(exp.ToExpression()).Count();
            }
        }
 
        /// <summary>
        /// 更新处理状态
        /// </summary>
        public bool UpdateHandleStatus(long CorpID, long ID, int HandleStatus)
        {
            using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Updateable<Entity.MonitorAlarmRecord>()
                    .SetColumns(x => x.HandleStatus == HandleStatus)
                    .Where(x => x.CorpID == CorpID && x.ID == ID)
                    .ExecuteCommand() > 0;
            }
        }
 
        /// <summary>
        /// 获取模糊列表
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetFluzzyList
            (long CorpID,long? MonitorPointID,string AlarmType,int? AlarmLevel,int? HandleStatus,DateTime? StartTime,DateTime? EndTime)
        {
            var exp = Expressionable.Create<Entity.MonitorAlarmRecord>();
            exp.And(x => x.CorpID == CorpID);
            exp.AndIF(MonitorPointID.HasValue, x => x.MonitorPointID==MonitorPointID.Value);
            exp.AndIF(!string.IsNullOrEmpty(AlarmType), x => x.AlarmType == AlarmType);
            exp.AndIF(AlarmLevel.HasValue, x => x.AlarmLevel == AlarmLevel.Value);
            exp.AndIF(HandleStatus.HasValue, x => x.HandleStatus == HandleStatus);
            exp.AndIF(StartTime.HasValue, x => x.AlarmTime >= StartTime.Value);
            exp.AndIF(EndTime.HasValue, x => x.AlarmTime <= EndTime.Value);
            
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>().Where(exp.ToExpression()).ToList();
            }
        }
 
        /// <summary>
        /// 获取模糊分页列表
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetFluzzyPageList
              (long CorpID, List<long> MonitorPointIds, string AlarmType, int? AlarmLevel, int? HandleStatus, DateTime? StartTime, DateTime? EndTime,int PageIndex,int PageSize,ref int Total)
        {
            if (PageIndex < 1)
                PageIndex = 1;
            if (PageSize < 1)
                PageSize = 1;
            var exp = Expressionable.Create<Entity.MonitorAlarmRecord>();
            exp.And(x => x.CorpID == CorpID);
            exp.AndIF(MonitorPointIds!=null&&MonitorPointIds.Count>0, x => MonitorPointIds.Contains(x.MonitorPointID));
            exp.AndIF(!string.IsNullOrEmpty(AlarmType), x => x.AlarmType == AlarmType);
            exp.AndIF(AlarmLevel.HasValue, x => x.AlarmLevel == AlarmLevel.Value);
            exp.AndIF(HandleStatus.HasValue, x => x.HandleStatus == HandleStatus);
            exp.AndIF(StartTime.HasValue, x => x.AlarmTime >= StartTime.Value);
            exp.AndIF(EndTime.HasValue, x => x.AlarmTime <= EndTime.Value);
 
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(exp.ToExpression())
                    .OrderBy(x => x.AlarmTime, OrderByType.Desc)
                    .ToPageList(PageIndex, PageSize, ref Total); ;
            }
        }
 
 
        /// <summary>
        /// 通过 CorpID 获取分页列表
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetPageListByCorpID
            (long CorpID, DateTime StartTime, DateTime EndTime, int PageIndex, int PageSize, ref int Total)
        {
            if (EndTime < StartTime)
            {
                return default;
            }
            if (PageIndex < 1)
                PageIndex = 1;
            if (PageSize < 1)
                PageSize = 1;
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && x.AlarmTime >= StartTime && x.AlarmTime <= EndTime)
                    .OrderBy(x => x.AlarmTime, OrderByType.Desc)
                    .ToPageList(PageIndex, PageSize, ref Total);
            }
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取分页列表
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetPageListByMonitorPointID
            (long CorpID, long MonitorPointID, DateTime StartTime, DateTime EndTime, int PageIndex, int PageSize, ref int Total)
        {
            if (EndTime < StartTime)
            {
                return default;
            }
            if (PageIndex < 1)
                PageIndex = 1;
            if (PageSize < 1)
                PageSize = 1;
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID && x.AlarmTime >= StartTime && x.AlarmTime <= EndTime)
                    .OrderBy(x => x.AlarmTime, OrderByType.Desc)
                    .ToPageList(PageIndex, PageSize, ref Total);
            }
        }
 
        /// <summary>
        /// 通过 MonitorPointIds 获取分页列表
        /// </summary>
        public List<Entity.MonitorAlarmRecord> GetPageListByMonitorPointIds
             (long CorpID, List<long> MonitorPointIds, DateTime StartTime, DateTime EndTime, int PageIndex, int PageSize, ref int Total)
        {
            if (MonitorPointIds == null || MonitorPointIds.Count() < 1)
            {
                return default;
            }
            if (EndTime < StartTime)
            {
                return default;
            }
            if (PageIndex < 1)
                PageIndex = 1;
            if (PageSize < 1)
                PageSize = 1;
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.MonitorAlarmRecord>()
                    .Where(x => x.CorpID == CorpID && MonitorPointIds.Contains(x.MonitorPointID) && x.AlarmTime >= StartTime && x.AlarmTime <= EndTime)
                    .OrderBy(x => x.AlarmTime, OrderByType.Desc)
                    .ToPageList(PageIndex, PageSize, ref Total);
            }
        }
 
 
 
    }
}