From 46e98339480d853fc78a014c34d7ff9fcaf13890 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 05 十二月 2024 14:09:02 +0800
Subject: [PATCH] 产线协议

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/DB/BaseDBConfig.cs |  121 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 121 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/DB/BaseDBConfig.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/DB/BaseDBConfig.cs"
new file mode 100644
index 0000000..ed0e254
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/DB/BaseDBConfig.cs"
@@ -0,0 +1,121 @@
+锘縰sing SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Dynamic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core.Const;
+using WIDESEA_Core.Helper;
+using WIDESEA_Core.Tenants;
+
+namespace WIDESEA_Core.DB
+{
+    public class BaseDBConfig
+    {
+        /* 涔嬪墠鐨勫崟搴撴搷浣滃凡缁忓垹闄わ紝濡傛灉鎯宠涔嬪墠鐨勪唬鐮侊紝鍙互鏌ョ湅鎴戠殑GitHub鐨勫巻鍙茶褰�
+         * 鐩墠鏄搴撴搷浣滐紝榛樿鍔犺浇鐨勬槸appsettings.json璁剧疆涓簍rue鐨勭涓�涓猟b杩炴帴銆�
+         */
+        public static List<MutiDBOperate> MutiConnectionString => MutiInitConn();
+
+        private static string DifDBConnOfSecurity(params string[] conn)
+        {
+            foreach (var item in conn)
+            {
+                try
+                {
+                    if (File.Exists(item))
+                    {
+                        return File.ReadAllText(item).Trim();
+                    }
+                }
+                catch (System.Exception)
+                {
+                }
+            }
+
+            return conn[conn.Length - 1];
+        }
+
+        public static List<MutiDBOperate> MutiInitConn()
+        {
+            SqlSugarClient sqlSugarClient = new SqlSugarClient(new ConnectionConfig
+            {
+                ConfigId = MainDb.CurrentDbConnId,
+                ConnectionString = AppSettings.app(MainDb.ConnectionString).DecryptDES(AppSecret.DB),
+                IsAutoCloseConnection = true,
+                DbType = MainDb.DbType,
+                AopEvents = new AopEvents
+                {
+                    OnError = x =>
+                    {
+                        Console.WriteLine(x.Sql);
+                    }
+                }
+            });
+
+            List<ExpandoObject> list = sqlSugarClient.Queryable(MainDb.TenantTableName, "x").Where(MainDb.TenantStatus, "=", TenantStatus.Enable).Select(TenantUtil.GetTenantSelectModels()).ToList();
+            List<MutiDBOperate> listdatabaseSlaveDB = new List<MutiDBOperate>();
+            MutiDBOperate mainDb = new MutiDBOperate()
+            {
+                Connection = AppSettings.app(MainDb.ConnectionString).DecryptDES(AppSecret.DB),
+                ConnId = MainDb.CurrentDbConnId,
+                DbType = DataBaseType.SqlServer
+            };
+            listdatabaseSlaveDB.Add(mainDb);
+            for (int i = 0; i < list.Count; i++)
+            {
+                dynamic data = list[i];
+                MutiDBOperate mutiDBOperate = new MutiDBOperate()
+                {
+                    Connection = data.ConnectionString,
+                    ConnId = data.TenantId + "",
+                    DbType = (DataBaseType)data.DbType,
+                };
+                mutiDBOperate.Connection = mutiDBOperate.Connection.DecryptDES(AppSecret.DB);
+                listdatabaseSlaveDB.Add(mutiDBOperate);
+            }
+
+            return listdatabaseSlaveDB;
+        }
+    }
+
+    public enum DataBaseType
+    {
+        MySql = 0,
+        SqlServer = 1,
+        Sqlite = 2,
+        Oracle = 3,
+        PostgreSQL = 4,
+        Dm = 5,
+        Kdbndp = 6,
+    }
+
+    public class MutiDBOperate
+    {
+        /// <summary>
+        /// 杩炴帴鍚敤寮�鍏�
+        /// </summary>
+        public bool Enabled { get; set; }
+
+        /// <summary>
+        /// 杩炴帴ID
+        /// </summary>
+        public string ConnId { get; set; }
+
+        /// <summary>
+        /// 浠庡簱鎵ц绾у埆锛岃秺澶ц秺鍏堟墽琛�
+        /// </summary>
+        public int HitRate { get; set; }
+
+        /// <summary>
+        /// 杩炴帴瀛楃涓�
+        /// </summary>
+        public string Connection { get; set; }
+
+        /// <summary>
+        /// 鏁版嵁搴撶被鍨�
+        /// </summary>
+        public DataBaseType DbType { get; set; }
+    }
+}

--
Gitblit v1.9.3