/// <summary>
        /// 设置组织的数据库
        /// </summary>
        /// <param name="organizationId"></param>
        public static void SetOrganizationStorageRelation(string organizationId)
        {
            var storageMaxOrganiztonCount = ConfigurationManager.AppSetting("StorageMaxOrganiztonCount");

            if (string.IsNullOrWhiteSpace(storageMaxOrganiztonCount))
            {
                throw new Exception("没有找到配置项StorageMaxOrganiztonCount");
            }

            int maxConfiguration = 0;

            if (!int.TryParse(storageMaxOrganiztonCount, out maxConfiguration))
            {
                throw new Exception("配置项StorageMaxOrganiztonCount只能是整形数字");
            }

            var storages = GetStorages();

            if (storages == null || storages.Count == 0)
            {
                throw new Exception("没有找到任何的storeage");
            }

            var storage = storages.FirstOrDefault(x => x.MOrgCount < maxConfiguration);

            if (storage == null)
            {
                throw new Exception("没有找到合适的数据库,请确认数据库是否已满");
            }

            OrganizaitonStoreRelationDAO organizaitonStore = new OrganizaitonStoreRelationDAO()
            {
                MItemID    = GuidUtility.GetGuid(),
                MOrgID     = organizationId,
                MStorageID = storage.MItemID,
                MIsActive  = true,
                MIsDelete  = false
            };

            string connectionString = ConfigurationManager.AppSetting("ConnectionString");

            IORM _orm = new SugarORM(connectionString);

            var client = _orm.GetSqlClient <SqlSugarClient>();

            client.Insertable <OrganizaitonStoreRelationDAO>(organizaitonStore).ExecuteCommand();
        }
        /// <summary>
        /// 根据组织获取连接字符串
        /// </summary>
        /// <param name="organizationId"></param>
        /// <returns></returns>
        public static string GetConnectionString(string organizationId)
        {
            string connectionString = ConfigurationManager.AppSetting("ConnectionString");

            IORM _orm = new SugarORM(connectionString);

            var client = _orm.GetSqlClient <SqlSugarClient>();

            string sql = GetQuerySql(organizationId);

            OrganizaitonStoreRelationDAO dbStore = client.SqlQueryable <OrganizaitonStoreRelationDAO>(sql).First();

            if (dbStore == null)
            {
                throw new Exception($"找不到组织{organizationId}对应的业务数据库");
            }

            return(GetConnectionString(dbStore));
        }
 /// <summary>
 /// 获取连接字符串
 /// </summary>
 /// <param name="dbStore"></param>
 /// <returns></returns>
 private static string GetConnectionString(OrganizaitonStoreRelationDAO dbStore)
 {
     return($"server={dbStore.MDBServerName};database={dbStore.MDBName};uid={dbStore.MUserName};pwd={dbStore.MPassword};" +
            $"Allow Zero Datetime=True;Port={dbStore.MDBServerPort};charset=utf8;pooling=true;Max Pool Size=100");
 }