using Npgsql.TypeHandlers;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Yw;
|
|
namespace HStation.BLL
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class XhsHydroInfo
|
{
|
private const string _folderPath = "hydro-info";
|
|
//获取本地缓存文件夹
|
private static string GetLocalCacheFolderPath()
|
{
|
string dataPath = ConfigHelper.DataPath;
|
if (string.IsNullOrEmpty(_folderPath))
|
{
|
return dataPath;
|
}
|
|
string path = Path.Combine(dataPath, _folderPath);
|
if (!Directory.Exists(path))
|
{
|
Directory.CreateDirectory(path);
|
}
|
|
return path;
|
}
|
|
//获取本地缓存文件路径
|
private static string GetLocalCacheFilePath(long id)
|
{
|
var fileName = $"{id}.json";
|
return Path.Combine(GetLocalCacheFolderPath(), fileName);
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public static async Task<Yw.Model.HydroModelInfo> GetByID(long ID)
|
{
|
var filePath = GetLocalCacheFilePath(ID);
|
if (File.Exists(filePath))
|
{
|
var json = File.ReadAllText(filePath);
|
var model = Yw.JsonHelper.Json2Object<Yw.Model.HydroModelInfo>(json);
|
return model;
|
}
|
var hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(ID);
|
var hydroInfoJson = JsonHelper.Object2Json(hydroInfo);
|
File.WriteAllText(filePath, hydroInfoJson);
|
return hydroInfo;
|
}
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
public static async Task<long> Save(Yw.Model.HydroModelInfo hydroInfo)
|
{
|
if (hydroInfo == null)
|
{
|
return default;
|
}
|
var filePath = GetLocalCacheFilePath(hydroInfo.ID);
|
var json = Yw.JsonHelper.Object2Json(hydroInfo);
|
File.WriteAllText(filePath, json);
|
return await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(hydroInfo);
|
}
|
|
|
}
|
}
|