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