duheng
2024-12-24 6936ebf1dfbd0025d3e86ae7dde316b6a6e43b9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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);
        }
 
 
    }
}