using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
/// 监测月数据集
|
/// </summary>
|
public partial class StationMonthSignalRecordPacket
|
{
|
#region Path
|
|
/// <summary>
|
/// 查询监测数据集文件夹
|
/// </summary>
|
public string GetRootFolder(long monitorDataSourcesId)
|
{
|
var monitorDataSourcesFolder = FileHelper.GetMonitorDataSourcesFolder(Settings.Project.ID, monitorDataSourcesId);
|
if (!Directory.Exists(monitorDataSourcesFolder))
|
Directory.CreateDirectory(monitorDataSourcesFolder);
|
var stationMonthDataFolder = Path.Combine(monitorDataSourcesFolder, Settings.File.StationMonthDataFolder);
|
if (!Directory.Exists(stationMonthDataFolder))
|
Directory.CreateDirectory(stationMonthDataFolder);
|
return stationMonthDataFolder;
|
}
|
|
/// <summary>
|
/// 查询日期文件夹
|
/// </summary>
|
public string GetYearMonthFolder(long monitorDataSourcesId, int year, int month)
|
{
|
var monitorDataSetFolder = GetRootFolder(monitorDataSourcesId);
|
var timeFolderName = "";
|
if (month < 10)
|
{
|
timeFolderName = $"{year}{Settings.File.FileNameSpacer}0{month}";
|
}
|
else
|
{
|
timeFolderName = $"{year}{Settings.File.FileNameSpacer}{month}";
|
}
|
var timeFolderPath = Path.Combine(monitorDataSetFolder, timeFolderName);
|
if (!Directory.Exists(timeFolderPath))
|
Directory.CreateDirectory(timeFolderPath);
|
return timeFolderPath;
|
}
|
|
/// <summary>
|
/// 查询泵站月记录文件路径
|
/// </summary>
|
public bool GetStationMonthSignalRecordPacketFile(long monitorDataSourcesId, long stationId, int year, int month, out string filePath)
|
{
|
var timeFolder = GetYearMonthFolder(monitorDataSourcesId, year, month);
|
var stationFolderPath = Path.Combine(timeFolder, stationId.ToString());
|
if (!Directory.Exists(stationFolderPath))
|
Directory.CreateDirectory(stationFolderPath);
|
filePath = Path.Combine(stationFolderPath, stationId.ToString() + Settings.File.SignalRecordFileExtension);
|
return File.Exists(filePath);
|
}
|
|
#endregion
|
|
#region Path
|
|
/// <summary>
|
/// 查询泵站月信号记录文件夹
|
/// </summary>
|
public string GetRootFolder(long monitorDataSourcesId, long stationId)
|
{
|
|
var monitorDataSetFolder = Path.Combine(monitorDataSourcesFolder, Settings.File.StationMonthDataFolder, stationId.ToString());
|
if (!Directory.Exists(monitorDataSetFolder))
|
Directory.CreateDirectory(monitorDataSetFolder);
|
return monitorDataSetFolder;
|
}
|
|
/// <summary>
|
/// 查询泵站月信号记录文件路径
|
/// </summary>
|
public string GetStationMonthSignalRecordFile(long monitorDataSourcesId, long stationId, int year, int month, int recordCount)
|
{
|
var monitorPointFolder = GetRootFolder(monitorDataSourcesId, stationId);
|
var timeFolderName = "";
|
if (month < 10)
|
{
|
timeFolderName = $"{year}{Settings.File.FileNameSpacer}0{month}{Settings.File.FileNameSpacer}{recordCount}";
|
}
|
else
|
{
|
timeFolderName = $"{year}{Settings.File.FileNameSpacer}{month}{Settings.File.FileNameSpacer}{recordCount}";
|
}
|
var fileName = Path.Combine(monitorPointFolder, timeFolderName + Settings.File.FileExtension);
|
return fileName;
|
}
|
|
|
#endregion
|
|
#region Get
|
|
/// <summary>
|
/// 查询监测数据集列表
|
/// </summary>
|
public List<Model.StationMonthSignalRecordPacket> Get(long monitorDataSourcesId, long stationId)
|
{
|
var rootFolder = this.GetRootFolder(monitorDataSourcesId, stationId);
|
var fileInfoList = this.GetMonthSignalRecordFileInfoList(rootFolder);
|
if (fileInfoList == null || fileInfoList.Count() < 1)
|
return default;
|
|
var monthSignalRecordPackets = new List<Model.StationMonthSignalRecordPacket>(fileInfoList.Count);
|
foreach (var fileInfo in fileInfoList)
|
{
|
var packet = Get(monitorDataSourcesId, stationId, fileInfo.Year, fileInfo.Month, fileInfo.RecordCount);
|
if (packet == null)
|
continue;
|
monthSignalRecordPackets.Add(packet);
|
}
|
return monthSignalRecordPackets;
|
}
|
|
|
/// <summary>
|
/// 查询监测数据集
|
/// </summary>
|
public Model.StationMonthSignalRecordPacket Get(long monitorDataSourcesId, long stationId, int year, int month, int recordCount)
|
{
|
var filePath = this.GetStationMonthSignalRecordFile(monitorDataSourcesId, stationId, year, month, recordCount);
|
if (!File.Exists(filePath))
|
return default;
|
var json = File.ReadAllText(filePath);
|
var monthSignalRecordPacket = JsonHelper.Json2Object<Model.StationMonthSignalRecordPacket>(json);
|
return monthSignalRecordPacket;
|
}
|
|
|
#endregion
|
|
#region Save
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
public bool Save(long monitorDataSourcesId, long stationId, IEnumerable<Model.StationMonthSignalRecordPacket> list)
|
{
|
if (list == null || list.Count() < 1)
|
return default;
|
for (int i = 0; i < list.Count(); i++)
|
{
|
var dataSet = list.ElementAt(i);
|
if (!Save(monitorDataSourcesId, stationId, dataSet))
|
{
|
//未做判断
|
}
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
public bool Save(long monitorDataSourcesId, long stationId, Model.StationMonthSignalRecordPacket rhs)
|
{
|
if (rhs == null)
|
return default;
|
if (rhs.StationSignalRecords == null || rhs.StationSignalRecords.Count < 1)
|
return default;
|
var filePath = GetStationMonthSignalRecordFile(monitorDataSourcesId, stationId, rhs.Year, rhs.Month, rhs.StationSignalRecords.Count);
|
var json = JsonHelper.Object2Json(rhs);
|
File.WriteAllText(filePath, json);
|
return true;
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
public void Clear(long monitorDataSourcesId, long stationId)
|
{
|
var folder = GetRootFolder(monitorDataSourcesId, stationId);
|
if (Directory.Exists(folder))
|
{
|
Directory.Delete(folder, true);
|
}
|
}
|
|
}
|
}
|