From 3805d90be3760e4881e30f28c22018f0e04b0eb2 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期二, 28 五月 2024 11:38:04 +0800
Subject: [PATCH] 基础计算 恢复

---
 IStation.Service/00-core/ConfigHelper.cs |   84 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/IStation.Service/00-core/ConfigHelper.cs b/IStation.Service/00-core/ConfigHelper.cs
index 2ece0a3..3a60b18 100644
--- a/IStation.Service/00-core/ConfigHelper.cs
+++ b/IStation.Service/00-core/ConfigHelper.cs
@@ -1,6 +1,9 @@
 锘縩amespace IStation
 {
-    internal class ConfigHelper
+    /// <summary>
+    /// 
+    /// </summary>
+    public class ConfigHelper
     {
 
         #region PostgreSql-ConnectionConfig
@@ -69,6 +72,33 @@
         #region SQLite-ConnectionConfig
 
         /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="dbFile"></param> 
+        /// <returns></returns>
+        private static string GetConnectionString(string dbFile)
+        {
+            var filePath = Settings.ParasHelper.LocalFile.DataFolderDirectory + "\\" + dbFile;
+            return $"DataSource={filePath}";
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="dbFile"></param>
+        /// <returns></returns>
+        public static string DeleteDataBase(string dbFile)
+        {
+            var filePath = Settings.ParasHelper.LocalFile.DataFolderDirectory + "\\" + dbFile;
+            if (File.Exists(filePath))
+                File.Delete(filePath);
+            return filePath;
+        }
+
+
+
+
+        /// <summary>
         /// Analysis SQLite杩炴帴閰嶇疆
         /// </summary>
         internal static ConnectionConfig AnalysisConnectionConfig
@@ -79,7 +109,7 @@
                 return new ConnectionConfig()
                 {
                     DbType = SqlSugar.DbType.Sqlite,//鏁版嵁搴撶被鍨�
-                    ConnectionString = Settings.ParasHelper.DataBase.SQLite.AnalysisConnectString,
+                    ConnectionString = GetConnectionString(Settings.ParasHelper.DataBase.SQLite.AnalysisConnectString),
                     IsAutoCloseConnection = true,//鏄惁鑷姩鍏抽棴
                     MoreSettings = new ConnMoreSettings()
                     {
@@ -109,7 +139,7 @@
                 return new ConnectionConfig()
                 {
                     DbType = SqlSugar.DbType.Sqlite,//鏁版嵁搴撶被鍨�
-                    ConnectionString = Settings.ParasHelper.DataBase.SQLite.ScheduleConnectString,
+                    ConnectionString = GetConnectionString(Settings.ParasHelper.DataBase.SQLite.ScheduleConnectString),
                     IsAutoCloseConnection = true,//鏄惁鑷姩鍏抽棴
                     MoreSettings = new ConnMoreSettings()
                     {
@@ -128,6 +158,54 @@
             }
         }
 
+        /// <summary>
+        /// 鍒濆鍖� Analysis 鏁版嵁搴�
+        /// </summary>   
+        public static void InitAnalysisDB(bool backup = false)
+        {
+            DeleteDataBase(Settings.ParasHelper.DataBase.SQLite.AnalysisConnectString);
+            var sqlSugarClient = new SqlSugarClient(AnalysisConnectionConfig);
+            Type[] types = new Type[] {
+                       typeof(Entity.AnalysisLog),
+                       //typeof(Entity.AnalysisCombine),
+                       //typeof(Entity.AnalysisConclusion),
+                   };
+            sqlSugarClient.DbMaintenance.CreateDatabase();
+            if (backup)
+            {
+                sqlSugarClient.CodeFirst.BackupTable().InitTables(types);
+            }
+            else
+            {
+                sqlSugarClient.CodeFirst.InitTables(types);
+            }
+        }
+
+
+        /// <summary>
+        /// 鍒濆鍖� Schedule 鏁版嵁搴�
+        /// </summary>   
+        public static void InitScheduleDB(bool backup = false)
+        {
+            var sqlSugarClient = new SqlSugarClient(ScheduleConnectionConfig);
+            Type[] types = new Type[] {
+                       typeof(Entity.ScheduleRequest),
+                       typeof(Entity.ScheduleScada),
+                       typeof(Entity.ScheduleRule),
+                       typeof(Entity.SchedulePump),
+                       typeof(Entity.ScheduleConclusion),
+                   };
+            sqlSugarClient.DbMaintenance.CreateDatabase();
+            if (backup)
+            {
+                sqlSugarClient.CodeFirst.BackupTable().InitTables(types);
+            }
+            else
+            {
+                sqlSugarClient.CodeFirst.InitTables(types);
+            }
+        }
+
         #endregion
 
         #region SQLite-Sql

--
Gitblit v1.9.3