using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using SqlSugar; namespace IStation.DAL { /// /// 监测报警记录 /// public partial class MonitorAlarmRecord : CorpDAL { /// /// /// public override ConnectionConfig ConnectionConfig { get { return ConfigHelper.MonitorRecordConnectionConfig; } } /// /// 通过 ConfigureID 获取 /// public List GetByConfigureID(long CorpID, long ConfigureID) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID && x.ConfigureID == ConfigureID) .OrderBy(x => x.AlarmTime,OrderByType.Asc).ToList(); } } /// /// 通过 ConfigureID 获取某天的报警数据 /// public List GetByConfigureIDOfDay(long CorpID, long ConfigureID, DateTime Day) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .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(); } } /// /// 通过 MonitorPointID 获取 /// public List GetByMonitorPointID(long CorpID, long MonitorPointID) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID) .OrderBy(x => x.AlarmTime, OrderByType.Asc).ToList(); } } /// /// 通过 MonitorPointID 获取某天的数据 /// public List GetByMonitorPointIDOfDay(long CorpID, long MonitorPointID, DateTime Day) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .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(); } } /// /// 通过 CorpID 获取最后几条数据 /// public List GetLastByCorpID(long CorpID, int Number) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID) .OrderBy(x => x.AlarmTime, OrderByType.Desc).Take(Number).ToList(); } } /// /// 通过 MonitorPointID 获取最后几条数据 /// public List GetLastByMonitorPointID(long CorpID, long MonitorPointID, int Number) { using (var db = new SqlSugarClient(ConnectionConfig)) { return db.Queryable() .Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID) .OrderBy(x => x.AlarmTime, OrderByType.Desc).Take(Number).ToList(); } } /// /// 获取数量 /// public int GetCount (long CorpID, List MonitorPointIds, string AlarmType, int? AlarmLevel, int? HandleStatus, DateTime? StartTime, DateTime? EndTime) { var exp = Expressionable.Create(); 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().Where(exp.ToExpression()).Count(); } } /// /// 更新处理状态 /// public bool UpdateHandleStatus(long CorpID, long ID, int HandleStatus) { using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig)) { return db.Updateable() .SetColumns(x => x.HandleStatus == HandleStatus) .Where(x => x.CorpID == CorpID && x.ID == ID) .ExecuteCommand() > 0; } } /// /// 获取模糊列表 /// public List GetFluzzyList (long CorpID,long? MonitorPointID,string AlarmType,int? AlarmLevel,int? HandleStatus,DateTime? StartTime,DateTime? EndTime) { var exp = Expressionable.Create(); 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().Where(exp.ToExpression()).ToList(); } } /// /// 获取模糊分页列表 /// public List GetFluzzyPageList (long CorpID, List 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(); 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() .Where(exp.ToExpression()) .OrderBy(x => x.AlarmTime, OrderByType.Desc) .ToPageList(PageIndex, PageSize, ref Total); ; } } /// /// 通过 CorpID 获取分页列表 /// public List 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() .Where(x => x.CorpID == CorpID && x.AlarmTime >= StartTime && x.AlarmTime <= EndTime) .OrderBy(x => x.AlarmTime, OrderByType.Desc) .ToPageList(PageIndex, PageSize, ref Total); } } /// /// 通过 MonitorPointID 获取分页列表 /// public List 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() .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); } } /// /// 通过 MonitorPointIds 获取分页列表 /// public List GetPageListByMonitorPointIds (long CorpID, List 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() .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); } } } }