using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace IStation.DAL
{
///
///
///
public class MonitorRecord : BaseDAL
{
///
///
///
public override ConnectionConfig ConnectionConfig
{
get { return ConfigHelper.DefaultConnectionConfig; }
}
#region 通过 MonitorPointID 获取
///
/// 通过 MonitorPointID 获取某天的全部数据
///
public List GetByMonitorPointIDOfDay( long MonitorPointID, DateTime Day)
{
if (MonitorPointID < 1)
return default;
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => x.MonitorPointID == MonitorPointID && x.DataTime >= Day.Date && x.DataTime < Day.Date.AddDays(1))
.OrderBy(x => x.DataTime, OrderByType.Asc).ToList();
}
}
///
/// 通过 MonitorPointID 获取日期区间内的数据
///
public List GetByMonitorPointIDOfDayRange( long MonitorPointID, DateTime StartDay, DateTime EndDay)
{
if (StartDay.Date > EndDay.Date)
return default;
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => x.MonitorPointID == MonitorPointID && x.DataTime >= StartDay.Date && x.DataTime < EndDay.Date.AddDays(1))
.OrderBy(x => x.DataTime, OrderByType.Asc).ToList();
}
}
///
/// 通过 MonitorPointID 获取时间区间内的数据
///
public List GetByMonitorPointIDOfTimeRange( long MonitorPointID, DateTime StartTime, DateTime EndTime)
{
if (StartTime > EndTime)
return default;
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => x.MonitorPointID == MonitorPointID && x.DataTime >= StartTime && x.DataTime <= EndTime)
.OrderBy(x => x.DataTime, OrderByType.Asc).ToList();
}
}
#endregion
#region Update
///
/// 更新
///
public override bool Update(Entity.MonitorRecord entity)
{
if (entity == null)
return false;
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
return db.Updateable(entity).IgnoreColumns(x => x.DataTime).Where(x => x.ID == entity.ID).ExecuteCommand() > 0;
}
}
///
/// 批量更新
///
public override bool Updates(List list)
{
if (list == null || list.Count < 1)
return false;
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
return db.Updateable(list).IgnoreColumns(x => x.DataTime).WhereColumns(it => new { it.ID }).ExecuteCommand() > 0;
}
}
#endregion
}
}