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 MonitorMonthRecord
|
{
|
|
|
#region 最近一条记录
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public Model.MonitorMonthRecordPure GetLastRecord(long CorpID, long MonitorPointID, long SignalID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var record = redisHelper.GetLastMonthRecord(CorpID, MonitorPointID, SignalID);
|
return record;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorMonthRecordPure> GetLastRecord(long CorpID, long MonitorPointID, IEnumerable<long> SignalIds)
|
{
|
if (SignalIds == null || SignalIds.Count() < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastMonthRecord(CorpID, MonitorPointID, SignalIds);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorMonthRecordPure> GetLastRecord(long CorpID, Dictionary<long, long> dict)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastMonthRecord(CorpID, dict);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorMonthRecordPure> GetLastRecord(long CorpID, long MonitorPointID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastMonthRecord(CorpID, MonitorPointID);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条记录
|
/// </summary>
|
public List<Model.MonitorMonthRecordPure> GetLastRecord(long CorpID, IEnumerable<long> MonitorPointIds)
|
{
|
if (MonitorPointIds == null || MonitorPointIds.Count() < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastMonthRecord(CorpID, MonitorPointIds);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public Model.MonitorMonthRecordPure GetLastNormalRecord(long CorpID, long MonitorPointID, long SignalID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var record = redisHelper.GetLastNormalMonthRecord(CorpID, MonitorPointID, SignalID);
|
return record;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public List<Model.MonitorMonthRecordPure> GetLastNormalRecord(long CorpID, Dictionary<long, long> dict)
|
{
|
if (dict == null || dict.Count < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastNormalMonthRecord(CorpID, dict);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public List<Model.MonitorMonthRecordPure> GetLastNormalRecord(long CorpID, long MonitorPointID)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastNormalMonthRecord(CorpID, MonitorPointID);
|
return records;
|
}
|
|
/// <summary>
|
/// 获取最近一条正常记录
|
/// </summary>
|
public List<Model.MonitorMonthRecordPure> GetLastNormalRecord(long CorpID, IEnumerable<long> MonitorPointIds)
|
{
|
if (MonitorPointIds == null || MonitorPointIds.Count() < 1)
|
return default;
|
var redisHelper = new MonitorRecordCacheHelper();
|
var records = redisHelper.GetLastNormalMonthRecord(CorpID, MonitorPointIds);
|
return records;
|
}
|
#endregion
|
|
#region 历史记录
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取
|
/// </summary>
|
public List<Model.MonitorMonthRecord> GetByMonitorPointID(long CorpID, long MonitorPointID)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = dal.GetByMonitorPointID(CorpID,MonitorPointID);
|
var model_list = Entity2Models(entity_list);
|
return model_list?.OrderBy(x => x.DataYear).ThenBy(x => x.DataMonth).ThenBy(x => x.DataTime).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取某年的数据
|
/// </summary>
|
public List<Model.MonitorMonthRecord> GetByMonitorPointIDOfYear(long CorpID, long MonitorPointID, int Year)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = dal.GetByMonitorPointIDOfYear(CorpID, MonitorPointID, Year);
|
var model_list = Entity2Models(entity_list);
|
return model_list?.OrderBy(x=>x.DataYear).ThenBy(x=>x.DataMonth).ThenBy(x=>x.DataTime).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取某月的数据
|
/// </summary>
|
public List<Model.MonitorMonthRecord> GetByMonitorPointIDOfMonth(long CorpID, long MonitorPointID, int Year, int Month)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = dal.GetByMonitorPointIDOfMonth(CorpID, MonitorPointID, Year, Month);
|
var model_list = Entity2Models(entity_list);
|
return model_list?.OrderBy(x => x.DataYear).ThenBy(x => x.DataMonth).ThenBy(x => x.DataTime).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取年区间内的数据
|
/// </summary>
|
public List<Model.MonitorMonthRecord> GetByMonitorPointIDOfYearRange(long CorpID, long MonitorPointID, int StartYear, int EndYear)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = dal.GetByMonitorPointIDOfYearRange(CorpID, MonitorPointID, StartYear, EndYear);
|
var model_list = Entity2Models(entity_list);
|
return model_list?.OrderBy(x => x.DataYear).ThenBy(x => x.DataMonth).ThenBy(x => x.DataTime).ToList();
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取月区间内的数据
|
/// </summary>
|
public List<Model.MonitorMonthRecord> GetByMonitorPointIDOfMonthRange(long CorpID, long MonitorPointID, int StartYear, int StartMonth, int EndYear, int EndMonth)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = dal.GetByMonitorPointIDOfMonthRange(CorpID, MonitorPointID, StartYear, StartMonth, EndYear, EndMonth);
|
var model_list = Entity2Models(entity_list);
|
return model_list?.OrderBy(x => x.DataYear).ThenBy(x => x.DataMonth).ThenBy(x => x.DataTime).ToList();
|
}
|
|
/// <summary>
|
/// 通过 SignalID 获取某月的数据
|
/// </summary>
|
public Model.MonitorMonthRecord GetBySignalIDOfMonth(long CorpID, long MonitorPointID, long SignalID, int DataYear, int DataMonth)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entity = dal.GetBySignalIDOfMonth(CorpID, MonitorPointID, SignalID, DataYear, DataMonth);
|
var model = Entity2Model(entity);
|
return model;
|
}
|
|
/// <summary>
|
/// 通过 SignalID 获取月区间内的数据
|
/// </summary>
|
public List<Model.MonitorMonthRecord> GetBySignalIDOfMonthRange(long CorpID, long MonitorPointID, long SignalID, int StartYear, int StartMonth, int EndYear, int EndMonth)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entityList = dal.GetBySignalIDOfMonthRange(CorpID, MonitorPointID, SignalID, StartYear, StartMonth, EndYear, EndMonth);
|
var modelList = Entity2Models(entityList);
|
return modelList;
|
}
|
|
|
/// <summary>
|
/// 通过 SignalID 获取月区间内的基础内容数据
|
/// </summary>
|
public List<Model.MonitorBasicRecordContent> GetBasicContentBySignalIDOfMonthRange(long CorpID, long MonitorPointID,long SignalID, int StartYear, int StartMonth, int EndYear, int EndMonth)
|
{
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = dal.GetBySignalIDOfMonthRange(CorpID, MonitorPointID, SignalID, StartYear, StartMonth, EndYear, EndMonth);
|
var model_list = Entity2BasicContents(entity_list);
|
return model_list;
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
public bool Insert(Model.MonitorMonthRecordPure model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entity = Model2Entity(new Model.MonitorMonthRecord(model));
|
var id = dal.Insert(entity);
|
return id > 0;
|
}
|
|
/// <summary>
|
/// 插入多条
|
/// </summary>
|
public bool Inserts(List<Model.MonitorMonthRecordPure> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = Model2Entities(list.Select(x => new Model.MonitorMonthRecord(x)).ToList()).ToList();
|
var bol = dal.Inserts(entity_list);
|
return bol;
|
}
|
|
/// <summary>
|
/// 插入最近一条记录
|
/// </summary>
|
public bool InsertLastRecord(Model.MonitorMonthRecordPure model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entity = Model2Entity(new Model.MonitorMonthRecord(model));
|
var bol = dal.Insert(entity) > 0;
|
if (bol)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
redisHelper.SetLastMonthRecord(model);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 插入最近多条记录
|
/// </summary>
|
public bool InsertsLastRecord(List<Model.MonitorMonthRecordPure> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = Model2Entities(list.Select(x => new Model.MonitorMonthRecord(x)).ToList());
|
var bol = dal.Inserts(entity_list);
|
if (bol)
|
{
|
var redisHelper = new MonitorRecordCacheHelper();
|
redisHelper.SetLastMonthRecord(list);
|
}
|
return bol;
|
}
|
|
/// <summary>
|
/// 补录一条
|
/// </summary>
|
public bool InsertSupplement(Model.MonitorMonthRecordPure model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entity = Model2Entity(new Model.MonitorMonthRecord(model));
|
var id = dal.Insert(entity);
|
return id>0;
|
}
|
|
/// <summary>
|
/// 补录多条
|
/// </summary>
|
public bool InsertsSupplement(List<Model.MonitorMonthRecordPure> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entity_list = Model2Entities(list.Select(x=>new Model.MonitorMonthRecord(x)).ToList()).ToList();
|
var bol = dal.Inserts(entity_list);
|
return bol;
|
}
|
|
/// <summary>
|
/// 重录一条
|
/// </summary>
|
public bool InsertAgain(Model.MonitorMonthRecordPure model)
|
{
|
if (model == null)
|
return false;
|
var dal = new DAL.MonitorMonthRecord();
|
var result = dal.DeleteBySignalIDOfMonth(model.CorpID, model.MonitorPointID, model.SignalID, model.DataYear,model.DataMonth);
|
if (!result)
|
{
|
LogHelper.Info($"重录一条监测月记录中,CorpID:{model.CorpID},MonitorPointID:{model.MonitorPointID},SignalID:{model.SignalID},DataYear:{model.DataYear},DataMonth:{model.DataMonth},未检索到已存在记录!");
|
}
|
var entity = Model2Entity(new Model.MonitorMonthRecord(model));
|
var id = dal.Insert(entity);
|
return id > 0;
|
}
|
|
/// <summary>
|
/// 重录多条
|
/// </summary>
|
public bool InsertsAgain(List<Model.MonitorMonthRecordPure> 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.MonitorMonthRecord();
|
foreach (var group in groupList)
|
{
|
var orderList = group.OrderBy(x => x.DataYear).ThenBy(x => x.DataMonth).ToList();
|
var first = orderList.First();
|
var startYear = first.DataYear;
|
var startMonth=first.DataMonth;
|
var last = orderList.Last();
|
var endYear = last.DataYear;
|
var endMonth=last.DataMonth;
|
var result = dal.DeleteBySignalIDOfMonthRange(group.Key.CorpID, group.Key.MonitorPointID, group.Key.SignalID, startYear,startMonth,endYear,endMonth);
|
if (!result)
|
{
|
LogHelper.Info($"重录多条监测月记录中,CorpID:{group.Key.CorpID},MonitorPointID:{group.Key.MonitorPointID},SignalID:{group.Key.SignalID},StartYear:{startYear},StartMonth:{startMonth},EndYear:{endYear},EndMonth:{endMonth},未检索到已存在记录!");
|
}
|
}
|
var entityList = Model2Entities(list.Select(x => new Model.MonitorMonthRecord(x)).ToList());
|
var bol = dal.Inserts(entityList);
|
return bol;
|
}
|
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public bool Update(Model.MonitorMonthRecord model)
|
{
|
if (model == null)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entity = Model2Entity(model);
|
var bol = dal.Update(entity);
|
return bol;
|
}
|
|
/// <summary>
|
/// 批量更新
|
/// </summary>
|
public bool Updates(List<Model.MonitorMonthRecord> list)
|
{
|
if (list == null || list.Count < 1)
|
return default;
|
var dal = new DAL.MonitorMonthRecord();
|
var entityList = Model2Entities(list);
|
var bol = dal.Updates(entityList);
|
return bol;
|
}
|
|
|
#endregion
|
}
|
}
|