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);
|
}
|
}
|
|
|
|
}
|
}
|