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,out bool redis)
|
{
|
redis = false;
|
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, out redis);
|
}
|
|
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
|
|
|
}
|
}
|