using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace IStation.DAL
{
///
/// 监测数据集概要
///
public class MonitorDataSetSummary
{
#region Path
///
/// 查询文件路径
///
private string GetFolderPath()
{
return LocalFileConfig.GetMonitorDataFolder();
}
#endregion
#region Get
///
/// 查询全部
///
public List GetAll()
{
var path = GetFolderPath();
var all = MonitorDataSetSummaryHelper.GetAll(path);
var models = all?.ToList();
return models;
}
///
/// 根据 日期查询全部
///
public List GetAllByDate(int year, int month)
{
var all = GetAll();
var models = all?.Where(x => x.Year == year && x.Month == month).ToList();
return models;
}
///
/// 根据 Id查询
///
public Model.MonitorDataSetSummary GetById(long Id)
{
if (Id < 1)
return default;
var all = GetAll();
var models = all?.ToList();
return models?.Find(t => t.Id == Id);
}
///
/// 根据 Id集合查询
///
public List GetByIds(IEnumerable Ids)
{
if (Ids == null || Ids.Count() < 1)
return default;
var all = GetAll();
var models = all?.Where(x => Ids.Contains(x.Id)).ToList();
return models;
}
///
/// 根据 监测点信息查询
///
public List GetByMonitor(long monitorPointId)
{
if (monitorPointId < 0)
return default;
var all = GetAll();
if (all == null || all.Count < 1)
return default;
var models = all.FindAll(t => t.MonitorPointID == monitorPointId);
return models;
}
///
/// 根据 监测点信息查询
///
public List GetByMonitor(long monitorPointId, long signalId)
{
if (monitorPointId < 0)
return default;
var all = GetByMonitor(monitorPointId);
if (all == null || all.Count < 1)
return default;
var models = all.FindAll(t => t.SignalID == signalId);
return models;
}
///
/// 根据 监测点信息查询
///
public List GetByMonitor(long monitorPointId, int year, int month)
{
if (monitorPointId < 0)
return default;
var all = GetAllByDate(year, month);
if (all == null || all.Count < 1)
return default;
var models = all.FindAll(t => t.MonitorPointID == monitorPointId);
return models;
}
///
/// 根据 监测点信息查询
///
public Model.MonitorDataSetSummary GetByMonitor(long monitorPointId, long signalId, int year, int month)
{
if (monitorPointId < 0)
return default;
var all = GetByMonitor(monitorPointId, year, month);
if (all == null || all.Count < 1)
return default;
if (all == null || all.Count < 1)
return default;
var model = all.Find(t => t.SignalID == signalId);
return model;
}
///
/// 根据 监测点信息查询
///
public List GetByMonitor(List monitorPointIds, int year, int month)
{
if (monitorPointIds == null || monitorPointIds.Count < 1)
return default;
var all = GetAllByDate(year, month);
if (all == null || all.Count < 1)
return default;
var models = all.FindAll(t => monitorPointIds.Contains(t.MonitorPointID));
return models;
}
#endregion
#region Get - Count
///
/// 查询监测数据集数量
///
public int GetMonitorDataSetCount()
{
var all = GetAll();
if (all == null || all.Count < 1)
return default;
var count = all.GroupBy(x => new { x.MonitorPointID, x.Year, x.Month }).Count();
return count;
}
///
/// 查询信号记录包数量
///
public int GetSignalRecordPacketCount(long monitorPointId)
{
var all = GetByMonitor(monitorPointId);
if (all == null || all.Count < 1)
return default;
var count = all.GroupBy(x => x.SignalID).Count();
return count;
}
///
/// 查询信号记录包数量
///
public int GetSignalRecordPacketCount(long monitorPointId, int year, int month)
{
var all = GetByMonitor(monitorPointId, year, month);
if (all == null || all.Count < 1)
return default;
var count = all.GroupBy(x => x.SignalID).Count();
return count;
}
///
/// 查询某个信号记录数量
///
public int GetSignalRecordCount(long monitorPointId, long signalId)
{
var all = GetByMonitor(monitorPointId, signalId);
if (all == null || all.Count < 1)
return default;
var count = all.Sum(x => x.Count);
return count;
}
///
/// 查询某个信号记录数量
///
public int GetSignalRecordCount(long monitorPointId, long signalId, int year, int month)
{
var model = GetByMonitor(monitorPointId, signalId, year, month);
if (model == null)
return default;
var count = model.Count;
return count;
}
#endregion
#region Get - YearMonth
///
/// 查询年月记录
///
public List GetYearMonth()
{
var all = GetAll();
if (all == null || all.Count < 1)
return default;
var group = all.GroupBy(x => new { x.Year, x.Month });
var models = group.Select(x => new Model.YearMonth() { Year = x.Key.Year, Month = x.Key.Month }).ToList();
return models;
}
#endregion
#region Insert
///
/// 插入
///
public long Insert(Model.MonitorDataSetSummary rhs)
{
if (rhs == null)
return default;
var path = GetFolderPath();
return MonitorDataSetSummaryHelper.Insert(path, rhs);
}
///
/// 批量插入
///
public bool Inserts(IEnumerable list)
{
if (list == null || list.Count() < 1)
return default;
var path = GetFolderPath();
return MonitorDataSetSummaryHelper.Inserts(path, list);
}
///
/// 插入并返回
///
public Model.MonitorDataSetSummary InsertR(Model.MonitorDataSetSummary rhs)
{
if (rhs == null)
return default;
var path = GetFolderPath();
var entities = MonitorDataSetSummaryHelper.InsertR(path, rhs);
return entities;
}
///
/// 批量插入并返回
///
public List InsertRs(IEnumerable list)
{
if (list == null || list.Count() < 1)
return default;
var path = GetFolderPath();
var models = MonitorDataSetSummaryHelper.InsertRs(path, list);
return models;
}
#endregion
#region Update
///
/// 更新
///
public bool Update(Model.MonitorDataSetSummary rhs)
{
if (rhs == null)
return default;
var path = GetFolderPath();
return MonitorDataSetSummaryHelper.Update(path, rhs);
}
///
/// 批量更新
///
public bool Updates(IEnumerable list)
{
if (list == null || list.Count() < 1)
return default;
var path = GetFolderPath();
return MonitorDataSetSummaryHelper.Updates(path, list);
}
#endregion
#region Set
///
/// 设置
///
public bool Set(Model.MonitorDataSetSummary monthSummary, int year, int month)
{
var path = GetFolderPath();
var monitorRecordMonthSummary = GetByMonitor(monthSummary.MonitorPointID, monthSummary.SignalID, year, month);
if (monitorRecordMonthSummary == null)
{
return MonitorDataSetSummaryHelper.Insert(path, monthSummary) > 0;
}
else
{
return MonitorDataSetSummaryHelper.Update(path, monitorRecordMonthSummary);
}
}
#endregion
#region Delete
///
/// 根据 Id删除
///
public bool DeleteById(long Id)
{
if (Id < 0)
return default;
var path = GetFolderPath();
var bol = MonitorDataSetSummaryHelper.DeleteById(path, Id);
return bol;
}
///
/// 根据 Id集合删除
///
public bool DeleteByIds(IEnumerable Ids)
{
if (Ids == null || Ids.Count() < 1)
return default;
var path = GetFolderPath();
var bol = MonitorDataSetSummaryHelper.DeleteByIds(path, Ids);
return bol;
}
///
/// 删除
///
public bool Delete(Model.MonitorDataSetSummary rhs)
{
if (rhs == null)
return default;
var path = GetFolderPath();
var bol = MonitorDataSetSummaryHelper.DeleteById(path, rhs.Id);
return bol;
}
///
/// 批量删除
///
public bool Deletes(IEnumerable list)
{
if (list == null || list.Count() < 1)
return default;
var path = GetFolderPath();
var Ids = list.Select(x => x.Id).ToList();
var bol = MonitorDataSetSummaryHelper.DeleteByIds(path, Ids);
return bol;
}
///
/// 删除全部
///
public bool DeleteAll()
{
var path = GetFolderPath();
var bol = MonitorDataSetSummaryHelper.DeleteAll(path);
return bol;
}
#endregion
#region Exist
///
/// 是否存在
///
public bool IsExist()
{
var path = GetFolderPath();
return MonitorDataSetSummaryHelper.IsExist(path);
}
#endregion
}
}