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 MonitorWeekRecord
|
{
|
#region 最后一条记录
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public Model.MonitorWeekRecordPure GetLastRecord(long CorpID, long MonitorPointID, long SignalID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var record = redisHelper.GetLastWeekRecord(CorpID, MonitorPointID, SignalID);
|
return record;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorWeekRecordPure> GetLastRecord(long CorpID, long MonitorPointID, IEnumerable<long> SignalIds)
|
{
|
if (SignalIds == null || SignalIds.Count() < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastWeekRecord(CorpID, MonitorPointID, SignalIds);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorWeekRecordPure> GetLastRecord(long CorpID, Dictionary<long, long> dict)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastWeekRecord(CorpID, dict);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorWeekRecordPure> GetLastRecord(long CorpID, long MonitorPointID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastWeekRecord(CorpID, MonitorPointID);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorWeekRecordPure> GetLastRecord(long CorpID, IEnumerable<long> MonitorPointIds)
|
{
|
if (MonitorPointIds == null || MonitorPointIds.Count() < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastWeekRecord(CorpID, MonitorPointIds);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public Model.MonitorWeekRecordPure GetLastNormalRecord(long CorpID, long MonitorPointID, long SignalID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var record = redisHelper.GetLastNormalWeekRecord(CorpID, MonitorPointID, SignalID);
|
return record;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public List<Model.MonitorWeekRecordPure> GetLastNormalRecord(long CorpID, Dictionary<long, long> dict)
|
{
|
if (dict == null || dict.Count < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastNormalWeekRecord(CorpID, dict);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public List<Model.MonitorWeekRecordPure> GetLastNormalRecord(long CorpID, long MonitorPointID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastNormalWeekRecord(CorpID, MonitorPointID);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public List<Model.MonitorWeekRecordPure> GetLastNormalRecord(long CorpID, IEnumerable<long> MonitorPointIds)
|
{
|
if (MonitorPointIds == null || MonitorPointIds.Count() < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastNormalWeekRecord(CorpID, MonitorPointIds);
|
return records;
|
}
|
|
#endregion
|
|
#region 历史记录
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取
|
/// </summary>
|
public List<Model.MonitorWeekRecord> GetByMonitorPointID(long CorpID, long MonitorPointID)
|
{
|
var dal = new DAL.MonitorWeekRecord();
|
var entity_list = dal.GetByMonitorPointID(CorpID, MonitorPointID);
|
var model_list = Entity2Models(entity_list);
|
return model_list?.OrderBy(x=>x.StartDay).ToList();
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
public bool Insert(Model.MonitorWeekRecordPure model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entity = Model2Entity(new Model.MonitorWeekRecord(model));
|
var id = dal.Insert(entity);
|
return id > 0;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
public bool Inserts(List<Model.MonitorWeekRecordPure> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entity_list = Model2Entities(list.Select(x => new Model.MonitorWeekRecord(x)).ToList());
|
var bol = dal.Inserts(entity_list);
|
return bol;
|
}
|
|
/// <summary>
|
/// 插入最近一条记录
|
/// </summary>
|
public bool InsertLastRecord(Model.MonitorWeekRecordPure model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entity = Model2Entity(new Model.MonitorWeekRecord(model));
|
var bol = dal.Insert(entity) > 0;
|
if (bol)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
redisHelper.SetLastWeekRecord(model);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 插入最近多条记录
|
/// </summary>
|
public bool InsertsLastRecord(List<Model.MonitorWeekRecordPure> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entity_list = Model2Entities(list.Select(x => new Model.MonitorWeekRecord(x)).ToList());
|
var bol = dal.Inserts(entity_list);
|
if (bol)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
redisHelper.SetLastWeekRecord(list);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 补录一条
|
/// </summary>
|
public bool InsertSupplement(Model.MonitorWeekRecordPure model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entity = Model2Entity(new Model.MonitorWeekRecord(model));
|
var id = dal.Insert(entity);
|
return id>0;
|
}
|
|
/// <summary>
|
/// 补录多条
|
/// </summary>
|
public bool InsertsSupplement(List<Model.MonitorWeekRecordPure> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entity_list = Model2Entities(list.Select(x=>new Model.MonitorWeekRecord(x)).ToList());
|
var bol = dal.Inserts(entity_list);
|
return bol;
|
}
|
|
/// <summary>
|
/// 重录一条
|
/// </summary>
|
public bool InsertAgain(Model.MonitorWeekRecordPure model)
|
{
|
if (model == null)
|
return false;
|
var dal = new DAL.MonitorWeekRecord();
|
var result = dal.DeleteBySignalIDOfWeek(model.CorpID, model.MonitorPointID, model.SignalID, model.StartDay,model.EndDay);
|
if (!result)
|
{
|
LogHelper.Info($"重录一条监测周记录中,CorpID:{model.CorpID},MonitorPointID:{model.MonitorPointID},SignalID:{model.SignalID},StartDay:{model.StartDay:yyyy-MM-dd},EndDay:{model.EndDay:yyyy-MM-dd},未检索到已存在记录!");
|
}
|
var entity = Model2Entity(new Model.MonitorWeekRecord(model));
|
var id = dal.Insert(entity);
|
return id > 0;
|
}
|
|
/// <summary>
|
/// 重录多条
|
/// </summary>
|
public bool InsertsAgain(List<Model.MonitorWeekRecordPure> list)
|
{
|
if (list == null || list.Count < 1)
|
return false;
|
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
|
if (corpIds.Count > 1)
|
{
|
return default;
|
}
|
var groupList = list.GroupBy(x => new { x.CorpID, x.MonitorPointID, x.SignalID }).ToList();
|
var dal = new DAL.MonitorWeekRecord();
|
foreach (var group in groupList)
|
{
|
var startDay = group.Min(x => x.StartDay);
|
var endDay = group.Max(x => x.EndDay);
|
var result = dal.DeleteBySignalIDOfWeekRange(group.Key.CorpID, group.Key.MonitorPointID, group.Key.SignalID, startDay, endDay);
|
if (!result)
|
{
|
LogHelper.Info($"重录多条监测周记录中,CorpID:{group.Key.CorpID},MonitorPointID:{group.Key.MonitorPointID},SignalID:{group.Key.SignalID},StartDay:{startDay:yyyy-MM-dd}, EndDay:{endDay:yyyy-MM-dd},未检索到已存在记录!");
|
}
|
}
|
var entityList = Model2Entities(list.Select(x => new Model.MonitorWeekRecord(x)).ToList());
|
var bol = dal.Inserts(entityList);
|
return bol;
|
}
|
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public bool Update(Model.MonitorWeekRecord model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entity = Model2Entity(model);
|
var bol = dal.Update(entity);
|
return bol;
|
}
|
|
/// <summary>
|
/// 批量更新
|
/// </summary>
|
public bool Updates(List<Model.MonitorWeekRecord> list)
|
{
|
if (list == null || list.Count < 1)
|
return default;
|
var dal = new DAL.MonitorWeekRecord();
|
var entityList = Model2Entities(list);
|
var bol = dal.Updates(entityList);
|
return bol;
|
}
|
|
|
#endregion
|
|
|
}
|
}
|