diff --git a/Lib/Tiobon.Core.Base.dll b/Lib/Tiobon.Core.Base.dll index 191125fc..a7526e1d 100644 Binary files a/Lib/Tiobon.Core.Base.dll and b/Lib/Tiobon.Core.Base.dll differ diff --git a/Lib/Tiobon.Core.dll b/Lib/Tiobon.Core.dll index d8fad807..630019ab 100644 Binary files a/Lib/Tiobon.Core.dll and b/Lib/Tiobon.Core.dll differ diff --git a/Lib/Tiobon.Core.xml b/Lib/Tiobon.Core.xml index b7329e44..76878d99 100644 --- a/Lib/Tiobon.Core.xml +++ b/Lib/Tiobon.Core.xml @@ -1077,6 +1077,17 @@ 以嵌套事务方式执行 + + + 配置实体软删除过滤器
+ 统一过滤 软删除 无需自己写条件 +
+
+ + + 配置租户 + + Sql插入类 @@ -1258,6 +1269,26 @@ S盒 + + + 租户隔离方案 + + + + + Id隔离 + + + + + 库隔离 + + + + + 表隔离 + + 组合继承属性选择表达式树,无拓展参数 @@ -3082,6 +3113,60 @@ Body参数 + + + 状态
+ 中立字段,某些表可使用某些表不使用 +
+
+ + + 中立字段,某些表可使用某些表不使用
+ 逻辑上的删除,非物理删除
+ 例如:单据删除并非直接删除 +
+
+ + + 中立字段
+ 是否内置数据 +
+
+ + + 创建ID + + + + + 创建者 + + + + + 创建时间 + + + + + 修改ID + + + + + 更新者 + + + + + 修改日期 + + + + + 数据版本 + + 表主键 @@ -3301,6 +3386,86 @@ 返回信息 + + + ID + 泛型主键Tkey + + + + + 租户模型接口 + + + + + 租户Id + + + + + 标识 多租户 的业务表
+ 默认设置是多库
+ 公共表无需区分 直接使用主库 各自业务在各自库中
+
+
+ + + 系统租户表
+ 根据TenantType 分为两种方案:
+ 1.按租户字段区分
+ 2.按租户分库
+ +
+ + 注意:
+ 使用租户Id方案,无需配置分库的连接 +
+
+ + + 名称 + + + + + 租户类型 + + + + + 数据库/租户标识 不可重复
+ 使用Id方案,可无需配置 +
+
+ + + 主机
+ 使用Id方案,可无需配置 +
+
+ + + 数据库类型
+ 使用Id方案,可无需配置 +
+
+ + + 数据库连接
+ 使用Id方案,可无需配置 +
+
+ + + 状态 + + + + + 备注 + + 添加选项配置 选项类型 diff --git a/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs b/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs index 0b687812..e4fab457 100644 --- a/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs +++ b/Tiobon.Core.Api/Controllers/Systems/DynamicCodeFirstController.cs @@ -1,6 +1,5 @@ using SqlSugar; using Tiobon.Core.Common.DB.Extension; -using Tiobon.Core.Model.Models.RootTkey; namespace Tiobon.Core.Api.Controllers.Systems; diff --git a/Tiobon.Core.Common/DB/Aop/SqlSugarReuse.cs b/Tiobon.Core.Common/DB/Aop/SqlSugarReuse.cs deleted file mode 100644 index f7ffa8a0..00000000 --- a/Tiobon.Core.Common/DB/Aop/SqlSugarReuse.cs +++ /dev/null @@ -1,23 +0,0 @@ -using SqlSugar; -using Tiobon.Core.DB; - -namespace Tiobon.Core.Common.DB.Aop; - -public class SqlSugarReuse -{ - public static void AutoChangeAvailableConnect(SqlSugarClient db) - { - if (db == null) return; - if (db.Ado.IsValidConnection()) return; - if (!BaseDBConfig.ReuseConfigs.Any()) return; - - foreach (var connectionConfig in BaseDBConfig.ReuseConfigs) - { - var config = db.CurrentConnectionConfig.ConfigId; - db.ChangeDatabase(connectionConfig.ConfigId); - //移除旧的连接,只会在本次上下文移除,因为主库已经故障会导致多库事务无法使用 - db.RemoveConnection(config); - if (db.Ado.IsValidConnection()) return; - } - } -} \ No newline at end of file diff --git a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs b/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs deleted file mode 100644 index f63d7e7e..00000000 --- a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs +++ /dev/null @@ -1,180 +0,0 @@ -using Serilog; -using SqlSugar; -using StackExchange.Profiling; -using Tiobon.Core.LogHelper; -using Tiobon.Core.Model.Entity; -using Tiobon.Core.Model.Models.RootTkey; -using Tiobon.Core.Model.Tenants; - -namespace Tiobon.Core.Common.DB.Aop; - -public static class SqlSugarAop -{ - public static void OnLogExecuting(ISqlSugarClient sqlSugarScopeProvider, string user, string table, string operate, string sql, SugarParameter[] p, ConnectionConfig config) - { - try - { - MiniProfiler.Current.CustomTiming($"ConnId:[{config.ConfigId}] SQL:", GetParas(p) + "【SQL语句】:" + sql); - - if (!AppSettings.app(new string[] { "AppSettings", "SqlAOP", "Enabled" }).ObjToBool()) return; - - if (AppSettings.app(new string[] { "AppSettings", "SqlAOP", "LogToConsole", "Enabled" }).ObjToBool() || - AppSettings.app(new string[] { "AppSettings", "SqlAOP", "LogToFile", "Enabled" }).ObjToBool() || - AppSettings.app(new string[] { "AppSettings", "SqlAOP", "LogToDB", "Enabled" }).ObjToBool()) - { - using (LogContextExtension.Create.SqlAopPushProperty(sqlSugarScopeProvider)) - { - Log.Information("------------------ \r\n User:[{User}] Table:[{Table}] Operate:[{Operate}] ConnId:[{ConnId}]【SQL语句】: \r\n {Sql}", - user, table, operate, config.ConfigId, UtilMethods.GetNativeSql(sql, p)); - } - } - } - catch (Exception e) - { - Log.Error("Error occured OnLogExcuting:" + e); - } - } - - public static void DataExecuting(object oldValue, DataFilterModel entityInfo) - { - if (entityInfo.EntityValue is BasePoco rootEntity) - if (rootEntity.Id == 0) - rootEntity.Id = SnowFlakeSingle.Instance.NextId(); - - if (entityInfo.EntityValue is BaseEntity baseEntity) - { - // 新增操作 - if (entityInfo.OperationType == DataFilterType.InsertByObject) - if (baseEntity.CreateTime == DateTime.MinValue) - baseEntity.CreateTime = DateTime.Now; - - if (entityInfo.OperationType == DataFilterType.UpdateByObject) - baseEntity.ModifyTime = DateTime.Now; - - if (App.User?.ID > 0) - { - if (baseEntity is ITenantEntity tenant && App.User.TenantId > 0) - { - if (tenant.TenantId == 0) - tenant.TenantId = App.User.TenantId; - } - - switch (entityInfo.OperationType) - { - case DataFilterType.UpdateByObject: - baseEntity.ModifyId = App.User.ID; - baseEntity.ModifyBy = App.User.Name; - break; - case DataFilterType.InsertByObject: - if (baseEntity.CreateBy.IsNullOrEmpty() || baseEntity.CreateId is null or <= 0) - { - baseEntity.CreateId = App.User.ID; - baseEntity.CreateBy = App.User.Name; - } - - break; - } - } - } - else - { - //兼容以前的表 - //这里要小心 在AOP里用反射 数据量多性能就会有问题 - //要么都统一使用基类 - //要么考虑老的表没必要兼容老的表 - // - - var getType = entityInfo.EntityValue.GetType(); - int userId = Convert.ToInt32(App.User.ID); - switch (entityInfo.OperationType) - { - case DataFilterType.InsertByObject: - var dyCreateBy = getType.GetProperty("CreateBy"); - var dyCreateTime = getType.GetProperty("CreateTime"); - BasePoco ent = entityInfo.EntityValue as BasePoco; - if (ent != null && ent.Id == 0) - ent.Id = SnowFlakeSingle.Instance.NextId(); - if (App.User?.ID > 0 && dyCreateBy != null && dyCreateBy.GetValue(entityInfo.EntityValue) == null) - { - try - { - dyCreateBy.SetValue(entityInfo.EntityValue, Convert.ToInt32(App.User.ID)); - - } - catch (Exception) - { - dyCreateBy.SetValue(entityInfo.EntityValue, App.User.ID); - - } - } - - if ((dyCreateTime != null && dyCreateTime.GetValue(entityInfo.EntityValue) is null) || (dyCreateTime != null && dyCreateTime.GetValue(entityInfo.EntityValue) != null && (DateTime)dyCreateTime.GetValue(entityInfo.EntityValue) == DateTime.MinValue)) - dyCreateTime.SetValue(entityInfo.EntityValue, DateTime.Now); - - break; - case DataFilterType.UpdateByObject: - if (entityInfo.PropertyName == "UpdateBy") - { - var UpdateBy = getType.GetProperty("UpdateBy"); - if (App.User?.ID > 0 && UpdateBy != null) - { - try - { - UpdateBy.SetValue(entityInfo.EntityValue, Convert.ToInt32(App.User.ID)); - - } - catch (Exception) - { - UpdateBy.SetValue(entityInfo.EntityValue, App.User.ID); - - } - } - } - else if (entityInfo.PropertyName == "UpdateTime") - { - - var dyModifyTime = getType.GetProperty("UpdateTime"); - - if (dyModifyTime != null) - dyModifyTime.SetValue(entityInfo.EntityValue, DateTime.Now); - } - //else if (entityInfo.PropertyName == "UpdateTime") - //{ - - // HttpRequest request = UserContext.Context.Request; - // var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - //} - //else if (entityInfo.PropertyName == "UpdateTime") - //{ - - // var dyModifyTime = getType.GetProperty("UpdateTime"); - - // if (dyModifyTime != null) - // dyModifyTime.SetValue(entityInfo.EntityValue, DateTime.Now); - //} - break; - } - } - } - - private static string GetWholeSql(SugarParameter[] paramArr, string sql) - { - foreach (var param in paramArr) - { - sql = sql.Replace(param.ParameterName, $@"'{param.Value.ObjToString()}'"); - } - - return sql; - } - - private static string GetParas(SugarParameter[] pars) - { - string key = "【SQL参数】:"; - foreach (var param in pars) - { - key += $"{param.ParameterName}:{param.Value}\n"; - } - - return key; - } -} diff --git a/Tiobon.Core.Common/DB/AppSecretConfig.cs b/Tiobon.Core.Common/DB/AppSecretConfig.cs deleted file mode 100644 index 00660835..00000000 --- a/Tiobon.Core.Common/DB/AppSecretConfig.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Tiobon.Core.Common.AppConfig; - -public class AppSecretConfig -{ - private static string Audience_Secret = AppSettings.app(new string[] { "Audience", "Secret" }); - private static string Audience_Secret_File = AppSettings.app(new string[] { "Audience", "SecretFile" }); - - - public static string Audience_Secret_String => InitAudience_Secret(); - - - private static string InitAudience_Secret() - { - var securityString = DifDBConnOfSecurity(Audience_Secret_File); - if (!string.IsNullOrEmpty(Audience_Secret_File)&& !string.IsNullOrEmpty(securityString)) - { - return securityString; - } - else - { - return Audience_Secret; - } - - } - - 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 ""; - } - -} diff --git a/Tiobon.Core.Common/DB/EntityUtility.cs b/Tiobon.Core.Common/DB/EntityUtility.cs deleted file mode 100644 index 755ff4b2..00000000 --- a/Tiobon.Core.Common/DB/EntityUtility.cs +++ /dev/null @@ -1,51 +0,0 @@ -using SqlSugar; -using System.Diagnostics; -using System.Reflection; -using Tiobon.Core.Extensions; -using Tiobon.Core.DB; -using Tiobon.Core.Model; - -namespace Tiobon.Core.Common.DB; - -public class EntityUtility -{ - private static readonly Lazy>> _tenantEntitys = new(() => - { - Dictionary> dic = new Dictionary>(); - var assembly = Assembly.Load("Tiobon.Core.Model"); - //扫描 实体 - foreach (var type in assembly.GetTypes().Where(s => s.IsClass && !s.IsAbstract)) - { - var tenant = type.GetCustomAttribute(); - if (tenant != null) - { - dic.TryAdd(tenant.configId.ToString(), type); - continue; - } - - if (type.IsSubclassOf(typeof(RootEntityTkey<>))) - { - dic.TryAdd(MainDb.CurrentDbConnId, type); - continue; - } - - var table = type.GetCustomAttribute(); - if (table != null) - { - dic.TryAdd(MainDb.CurrentDbConnId, type); - continue; - } - - Debug.Assert(type.Namespace != null, "type.Namespace != null"); - if (type.Namespace.StartsWith("Tiobon.Core.Model.Models")) - { - dic.TryAdd(MainDb.CurrentDbConnId, type); - continue; - } - } - - return dic; - }); - - public static Dictionary> TenantEntitys => _tenantEntitys.Value; -} \ No newline at end of file diff --git a/Tiobon.Core.Common/DB/Extension/DbEntityException.cs b/Tiobon.Core.Common/DB/Extension/DbEntityException.cs deleted file mode 100644 index ff76ebac..00000000 --- a/Tiobon.Core.Common/DB/Extension/DbEntityException.cs +++ /dev/null @@ -1,13 +0,0 @@ -using SqlSugar; -using System.Reflection; - -namespace Tiobon.Core.Common.DB.Extension; - -public static class DbEntityException -{ - public static object GetEntityTenant(this Type type) - { - var tenant = type.GetCustomAttribute(); - return tenant?.configId; - } -} \ No newline at end of file diff --git a/Tiobon.Core.Common/DB/Extension/DynamicBuildException.cs b/Tiobon.Core.Common/DB/Extension/DynamicBuildException.cs deleted file mode 100644 index 15a768cf..00000000 --- a/Tiobon.Core.Common/DB/Extension/DynamicBuildException.cs +++ /dev/null @@ -1,44 +0,0 @@ -using SqlSugar; -using System.Reflection; -using System.Reflection.Emit; - -namespace Tiobon.Core.Common.DB.Extension; - -public static class DynamicBuildException -{ - private static List GetEntityAttr(this DynamicBuilder builder) - { - FieldInfo fieldInfo = builder.GetType().GetField("entityAttr", BindingFlags.Instance | BindingFlags.NonPublic); - List entityAttr = (List) fieldInfo.GetValue(builder); - return entityAttr; - } - - private static CustomAttributeBuilder CreateIndex(SugarIndexAttribute indexAttribute) - { - Type type = typeof(SugarIndexAttribute); - var constructorTypes = new List() {typeof(string)}; - for (int i = 0; i < indexAttribute.IndexFields.Count; i++) - { - constructorTypes.AddRange(new[] {typeof(string), typeof(OrderByType)}); - } - - constructorTypes.Add(typeof(bool)); - - var values = new List() {indexAttribute.IndexName}; - foreach (var indexField in indexAttribute.IndexFields) - { - values.AddRange(new object[] {indexField.Key, indexField.Value}); - } - - values.Add(indexAttribute.IsUnique); - return new CustomAttributeBuilder(type.GetConstructor(constructorTypes.ToArray())!, values.ToArray()); - } - - public static DynamicProperyBuilder CreateIndex(this DynamicProperyBuilder builder, SugarIndexAttribute indexAttribute) - { - var classBuilder = builder.baseBuilder; - var entityAttr = classBuilder.GetEntityAttr(); - entityAttr.Add(CreateIndex(indexAttribute)); - return builder; - } -} \ No newline at end of file diff --git a/Tiobon.Core.Common/DB/RepositorySetting.cs b/Tiobon.Core.Common/DB/RepositorySetting.cs deleted file mode 100644 index 5a583256..00000000 --- a/Tiobon.Core.Common/DB/RepositorySetting.cs +++ /dev/null @@ -1,46 +0,0 @@ -using SqlSugar; -using Tiobon.Core.Model.Entity; -using Tiobon.Core.Model.Models.RootTkey; -using Tiobon.Core.Model.Tenants; - -namespace Tiobon.Core.Common.DB; - -public class RepositorySetting -{ - private static readonly Lazy> AllEntitys = new(() => - { - return typeof(BaseEntity).Assembly - .GetTypes() - .Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(BaseEntity))) - .Where(it => it.FullName != null && it.FullName.StartsWith("Tiobon.Core.Model.Models")); - }); - - public static IEnumerable Entitys => AllEntitys.Value; - - /// - /// 配置实体软删除过滤器
- /// 统一过滤 软删除 无需自己写条件 - ///
- public static void SetDeletedEntityFilter(SqlSugarScopeProvider db) - { - db.QueryFilter.AddTableFilter(it => it.IsDeleted == false); - db.QueryFilter.AddTableFilter(it => it.IsEnable == 1); - } - - /// - /// 配置租户 - /// - public static void SetTenantEntityFilter(SqlSugarScopeProvider db) - { - if (App.User is not { ID: > 0, TenantId: > 0 }) - { - return; - } - - //多租户 单表 - db.QueryFilter.AddTableFilter(it => it.TenantId == App.User.TenantId || it.TenantId == 0); - - //多租户 多表 - db.SetTenantTable(App.User.TenantId.ToString()); - } -} \ No newline at end of file diff --git a/Tiobon.Core.Common/DB/TenantUtil.cs b/Tiobon.Core.Common/DB/TenantUtil.cs deleted file mode 100644 index 82b9398e..00000000 --- a/Tiobon.Core.Common/DB/TenantUtil.cs +++ /dev/null @@ -1,99 +0,0 @@ -using SqlSugar; -using System.Reflection; -using Tiobon.Core.Model.Models; -using Tiobon.Core.Model.Tenants; - -namespace Tiobon.Core.Common.DB; - -public static class TenantUtil -{ - public static SysTenant DefaultTenantConfig(this SysTenant tenant) - { - tenant.DbType ??= DbType.Sqlite; - - //如果没有配置连接 - if (tenant.Connection.IsNullOrEmpty()) - { - //此处默认配置 Sqlite 地址 - //实际业务中 也会有运维、系统管理员等来维护 - switch (tenant.DbType.Value) - { - case DbType.Sqlite: - tenant.Connection = $"DataSource={Path.Combine(Environment.CurrentDirectory, tenant.ConfigId)}.db"; - break; - } - } - - return tenant; - } - - public static ConnectionConfig GetConnectionConfig(this SysTenant tenant) - { - if (tenant.DbType is null) - { - throw new ArgumentException("Tenant DbType Must"); - } - - - return new ConnectionConfig() - { - ConfigId = tenant.ConfigId, - DbType = tenant.DbType.Value, - ConnectionString = tenant.Connection, - IsAutoCloseConnection = true, - MoreSettings = new ConnMoreSettings() - { - IsAutoRemoveDataCache = true, - SqlServerCodeFirstNvarchar = true, - }, - }; - } - - public static List GetTenantEntityTypes(TenantTypeEnum? tenantType = null) - { - return RepositorySetting.Entitys - .Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass) - .Where(s => IsTenantEntity(s, tenantType)) - .ToList(); - } - - public static bool IsTenantEntity(this Type u, TenantTypeEnum? tenantType = null) - { - var mta = u.GetCustomAttribute(); - if (mta is null) - { - return false; - } - - if (tenantType != null) - { - if (mta.TenantType != tenantType) - { - return false; - } - } - - return true; - } - - public static string GetTenantTableName(this Type type, ISqlSugarClient db, string id) - { - var entityInfo = db.EntityMaintenance.GetEntityInfo(type); - return $@"{entityInfo.DbTableName}_{id}"; - } - - public static string GetTenantTableName(this Type type, ISqlSugarClient db, SysTenant tenant) - { - return GetTenantTableName(type, db, tenant.Id.ToString()); - } - - public static void SetTenantTable(this ISqlSugarClient db, string id) - { - var types = GetTenantEntityTypes(TenantTypeEnum.Tables); - - foreach (var type in types) - { - db.MappingTables.Add(type.Name, type.GetTenantTableName(db, id)); - } - } -} \ No newline at end of file diff --git a/Tiobon.Core.Common/Seed/DBSeed.cs b/Tiobon.Core.Common/Seed/DBSeed.cs index 5141343d..d201920a 100644 --- a/Tiobon.Core.Common/Seed/DBSeed.cs +++ b/Tiobon.Core.Common/Seed/DBSeed.cs @@ -10,6 +10,7 @@ using Tiobon.Core.DB; using Tiobon.Core.Helper; using Tiobon.Core.Model.Models; using Tiobon.Core.Model.Tenants; +using Tiobon.Core.Model; namespace Tiobon.Core.Common.Seed; diff --git a/Tiobon.Core.Common/Seed/SeedData/TenantSeedData.cs b/Tiobon.Core.Common/Seed/SeedData/TenantSeedData.cs index b125dd49..92d17e9b 100644 --- a/Tiobon.Core.Common/Seed/SeedData/TenantSeedData.cs +++ b/Tiobon.Core.Common/Seed/SeedData/TenantSeedData.cs @@ -1,6 +1,5 @@ using SqlSugar; -using Tiobon.Core.Model.Models; -using Tiobon.Core.Model.Tenants; +using Tiobon.Core.Model; namespace Tiobon.Core.Common.Seed.SeedData; diff --git a/Tiobon.Core.Common/Tiobon.Core.Common.csproj b/Tiobon.Core.Common/Tiobon.Core.Common.csproj index d4ea960f..02d37ae2 100644 --- a/Tiobon.Core.Common/Tiobon.Core.Common.csproj +++ b/Tiobon.Core.Common/Tiobon.Core.Common.csproj @@ -53,10 +53,6 @@ - - - - ..\Lib\Tiobon.Core.dll diff --git a/Tiobon.Core.Extensions/Authorizations/Helpers/JwtHelper.cs b/Tiobon.Core.Extensions/Authorizations/Helpers/JwtHelper.cs index f893bc95..f9fdc3a3 100644 --- a/Tiobon.Core.Extensions/Authorizations/Helpers/JwtHelper.cs +++ b/Tiobon.Core.Extensions/Authorizations/Helpers/JwtHelper.cs @@ -3,7 +3,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Tiobon.Core.Common; -using Tiobon.Core.Common.AppConfig; +using Tiobon.Core.AppConfig; namespace Tiobon.Core.AuthHelper.OverWrite; diff --git a/Tiobon.Core.Extensions/ServiceExtensions/Authentication_JWTSetup.cs b/Tiobon.Core.Extensions/ServiceExtensions/Authentication_JWTSetup.cs index 61745f3c..197d59b1 100644 --- a/Tiobon.Core.Extensions/ServiceExtensions/Authentication_JWTSetup.cs +++ b/Tiobon.Core.Extensions/ServiceExtensions/Authentication_JWTSetup.cs @@ -6,7 +6,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Text; using Tiobon.Core.AuthHelper; using Tiobon.Core.Common; -using Tiobon.Core.Common.AppConfig; +using Tiobon.Core.AppConfig; namespace Tiobon.Core.Extensions; diff --git a/Tiobon.Core.Extensions/ServiceExtensions/AuthorizationSetup.cs b/Tiobon.Core.Extensions/ServiceExtensions/AuthorizationSetup.cs index 36139316..bfdd92e9 100644 --- a/Tiobon.Core.Extensions/ServiceExtensions/AuthorizationSetup.cs +++ b/Tiobon.Core.Extensions/ServiceExtensions/AuthorizationSetup.cs @@ -6,7 +6,7 @@ using System.Security.Claims; using System.Text; using Tiobon.Core.AuthHelper; using Tiobon.Core.Common; -using Tiobon.Core.Common.AppConfig; +using Tiobon.Core.AppConfig; namespace Tiobon.Core.Extensions; diff --git a/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs b/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs index b51dbf6b..76aa9a03 100644 --- a/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs +++ b/Tiobon.Core.Extensions/ServiceExtensions/SqlsugarSetup.cs @@ -3,10 +3,9 @@ using Microsoft.Extensions.DependencyInjection; using SqlSugar; using System.Text.RegularExpressions; using Tiobon.Core.Caches; -using Tiobon.Core.Common.DB; -using Tiobon.Core.Common.DB.Aop; using Tiobon.Core.Const; using Tiobon.Core.DB; +using Tiobon.Core.DB.Aop; namespace Tiobon.Core.Extensions; diff --git a/Tiobon.Core.Model/Models/RootTkey/BaseEntity.cs b/Tiobon.Core.Model/Models/RootTkey/BaseEntity.cs deleted file mode 100644 index 8e2eea8b..00000000 --- a/Tiobon.Core.Model/Models/RootTkey/BaseEntity.cs +++ /dev/null @@ -1,78 +0,0 @@ -namespace Tiobon.Core.Model.Models.RootTkey; - -[SugarIndex("index_{table}_Enabled", nameof(Enabled), OrderByType.Asc)] -[SugarIndex("index_{table}_IsDeleted", nameof(IsDeleted), OrderByType.Asc)] -public class BaseEntity : RootEntityTkey, IDeleteFilter -{ - #region 数据状态管理 - - /// - /// 状态
- /// 中立字段,某些表可使用某些表不使用 - ///
- public bool Enabled { get; set; } = true; - - /// - /// 中立字段,某些表可使用某些表不使用
- /// 逻辑上的删除,非物理删除
- /// 例如:单据删除并非直接删除 - ///
- public bool IsDeleted { get; set; } - - /// - /// 中立字段
- /// 是否内置数据 - ///
- public bool IsInternal { get; set; } - - #endregion - - #region 创建 - - /// - /// 创建ID - /// - [SugarColumn(IsNullable = true, IsOnlyIgnoreUpdate = true)] - public long? CreateId { get; set; } - - /// - /// 创建者 - /// - [SugarColumn(IsNullable = true, IsOnlyIgnoreUpdate = true)] - public string CreateBy { get; set; } - - /// - /// 创建时间 - /// - [SugarColumn(IsOnlyIgnoreUpdate = true)] - public DateTime CreateTime { get; set; } = DateTime.Now; - - #endregion - - #region 修改 - - /// - /// 修改ID - /// - [SugarColumn(IsNullable = true)] - public long? ModifyId { get; set; } - - /// - /// 更新者 - /// - [SugarColumn(IsNullable = true)] - public string ModifyBy { get; set; } - - /// - /// 修改日期 - /// - public DateTime? ModifyTime { get; set; } = DateTime.Now; - - /// - /// 数据版本 - /// - [SugarColumn(DefaultValue = "0", IsEnableUpdateVersionValidation = true)] //标识版本字段 - public long Version { get; set; } - - #endregion -} \ No newline at end of file diff --git a/Tiobon.Core.Model/Models/RootTkey/RootEntityTkey.cs b/Tiobon.Core.Model/Models/RootTkey/RootEntityTkey.cs deleted file mode 100644 index ea0387f9..00000000 --- a/Tiobon.Core.Model/Models/RootTkey/RootEntityTkey.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Tiobon.Core.Model; - -public class RootEntityTkey where Tkey : IEquatable -{ - /// - /// ID - /// 泛型主键Tkey - /// - [SugarColumn(IsNullable = false, IsPrimaryKey = true)] - public Tkey Id { get; set; } -} \ No newline at end of file diff --git a/Tiobon.Core.Model/Models/SysTenant.cs b/Tiobon.Core.Model/Models/SysTenant.cs deleted file mode 100644 index 27b4d7af..00000000 --- a/Tiobon.Core.Model/Models/SysTenant.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Tiobon.Core.Model.Tenants; -using SqlSugar; - -namespace Tiobon.Core.Model.Models; - -/// -/// 系统租户表
-/// 根据TenantType 分为两种方案:
-/// 1.按租户字段区分
-/// 2.按租户分库
-/// -///
-/// -/// 注意:
-/// 使用租户Id方案,无需配置分库的连接 -///
-public class SysTenant : RootEntityTkey -{ - /// - /// 名称 - /// - public string Name { get; set; } - - /// - /// 租户类型 - /// - public TenantTypeEnum TenantType { get; set; } - - /// - /// 数据库/租户标识 不可重复
- /// 使用Id方案,可无需配置 - ///
- [SugarColumn(Length = 64)] - public string ConfigId { get; set; } - - /// - /// 主机
- /// 使用Id方案,可无需配置 - ///
- [SugarColumn(IsNullable = true)] - public string Host { get; set; } - - /// - /// 数据库类型
- /// 使用Id方案,可无需配置 - ///
- [SugarColumn(IsNullable = true)] - public SqlSugar.DbType? DbType { get; set; } - - /// - /// 数据库连接
- /// 使用Id方案,可无需配置 - ///
- [SugarColumn(IsNullable = true)] - public string Connection { get; set; } - - /// - /// 状态 - /// - public bool Status { get; set; } = true; - - /// - /// 备注 - /// - [SugarColumn(IsNullable = true)] - public string Remark { get; set; } -} \ No newline at end of file diff --git a/Tiobon.Core.Model/Models/Tenant/BusinessTable.cs b/Tiobon.Core.Model/Models/Tenant/BusinessTable.cs index daf5776e..70646cc9 100644 --- a/Tiobon.Core.Model/Models/Tenant/BusinessTable.cs +++ b/Tiobon.Core.Model/Models/Tenant/BusinessTable.cs @@ -1,5 +1,4 @@ -using Tiobon.Core.Model.Models.RootTkey; -using Tiobon.Core.Model.Tenants; +using Tiobon.Core.Model.Tenants; namespace Tiobon.Core.Model.Models; diff --git a/Tiobon.Core.Model/Models/Tenant/MultiBusinessSubTable.cs b/Tiobon.Core.Model/Models/Tenant/MultiBusinessSubTable.cs index 64a32f82..8c86cecf 100644 --- a/Tiobon.Core.Model/Models/Tenant/MultiBusinessSubTable.cs +++ b/Tiobon.Core.Model/Models/Tenant/MultiBusinessSubTable.cs @@ -1,7 +1,4 @@ -using Tiobon.Core.Model.Models.RootTkey; -using Tiobon.Core.Model.Tenants; - -namespace Tiobon.Core.Model.Models; +namespace Tiobon.Core.Model.Models; /// /// 多租户-多表方案 业务表 子表
diff --git a/Tiobon.Core.Model/Models/Tenant/MultiBusinessTable.cs b/Tiobon.Core.Model/Models/Tenant/MultiBusinessTable.cs index 662c0d17..46b1f903 100644 --- a/Tiobon.Core.Model/Models/Tenant/MultiBusinessTable.cs +++ b/Tiobon.Core.Model/Models/Tenant/MultiBusinessTable.cs @@ -1,7 +1,4 @@ -using Tiobon.Core.Model.Models.RootTkey; -using Tiobon.Core.Model.Tenants; - -namespace Tiobon.Core.Model.Models; +namespace Tiobon.Core.Model.Models; /// /// 多租户-多表方案 业务表
diff --git a/Tiobon.Core.Model/Models/Tenant/SubLibraryBusinessTable.cs b/Tiobon.Core.Model/Models/Tenant/SubLibraryBusinessTable.cs index 737e2238..075e782d 100644 --- a/Tiobon.Core.Model/Models/Tenant/SubLibraryBusinessTable.cs +++ b/Tiobon.Core.Model/Models/Tenant/SubLibraryBusinessTable.cs @@ -1,7 +1,4 @@ -using Tiobon.Core.Model.Models.RootTkey; -using Tiobon.Core.Model.Tenants; - -namespace Tiobon.Core.Model.Models; +namespace Tiobon.Core.Model.Models; /// /// 多租户-多库方案 业务表
diff --git a/Tiobon.Core.Model/Tenants/ITenantEntity.cs b/Tiobon.Core.Model/Tenants/ITenantEntity.cs deleted file mode 100644 index dd97a0bf..00000000 --- a/Tiobon.Core.Model/Tenants/ITenantEntity.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Tiobon.Core.Model.Tenants; - -/// -/// 租户模型接口 -/// -public interface ITenantEntity -{ - /// - /// 租户Id - /// - [SugarColumn(DefaultValue = "0")] - public long TenantId { get; set; } -} \ No newline at end of file diff --git a/Tiobon.Core.Model/Tenants/MultiTenantAttribute.cs b/Tiobon.Core.Model/Tenants/MultiTenantAttribute.cs deleted file mode 100644 index ef843ea9..00000000 --- a/Tiobon.Core.Model/Tenants/MultiTenantAttribute.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Tiobon.Core.Model.Tenants; - -/// -/// 标识 多租户 的业务表
-/// 默认设置是多库
-/// 公共表无需区分 直接使用主库 各自业务在各自库中
-///
-[AttributeUsage(AttributeTargets.Class)] -public class MultiTenantAttribute : Attribute -{ - public MultiTenantAttribute() - { - } - - public MultiTenantAttribute(TenantTypeEnum tenantType) - { - TenantType = tenantType; - } - - - public TenantTypeEnum TenantType { get; set; } = TenantTypeEnum.Db; -} \ No newline at end of file diff --git a/Tiobon.Core.Model/Tenants/TenantTypeEnum.cs b/Tiobon.Core.Model/Tenants/TenantTypeEnum.cs deleted file mode 100644 index 373b1552..00000000 --- a/Tiobon.Core.Model/Tenants/TenantTypeEnum.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Tiobon.Core.Model.Tenants; - -/// -/// 租户隔离方案 -/// -public enum TenantTypeEnum -{ - None = 0, - - /// - /// Id隔离 - /// - [Description("Id隔离")] - Id = 1, - - /// - /// 库隔离 - /// - [Description("库隔离")] - Db = 2, - - /// - /// 表隔离 - /// - [Description("表隔离")] - Tables = 3, -} \ No newline at end of file diff --git a/Tiobon.Core.Tests/DependencyInjection/DI_Test.cs b/Tiobon.Core.Tests/DependencyInjection/DI_Test.cs index f38a19e4..a0b3a2e8 100644 --- a/Tiobon.Core.Tests/DependencyInjection/DI_Test.cs +++ b/Tiobon.Core.Tests/DependencyInjection/DI_Test.cs @@ -11,7 +11,7 @@ using System.Reflection; using System.Security.Claims; using System.Text; using Tiobon.Core.AuthHelper; -using Tiobon.Core.Common.AppConfig; +using Tiobon.Core.AppConfig; using Tiobon.Core.Common.Seed; using Tiobon.Core.DB; using Tiobon.Core.Extensions; diff --git a/Tiobon.Core/Tiobon.Core.Model.xml b/Tiobon.Core/Tiobon.Core.Model.xml index a62d69ce..df038433 100644 --- a/Tiobon.Core/Tiobon.Core.Model.xml +++ b/Tiobon.Core/Tiobon.Core.Model.xml @@ -39070,117 +39070,6 @@ 修改时间
- - - 状态
- 中立字段,某些表可使用某些表不使用 -
-
- - - 中立字段,某些表可使用某些表不使用
- 逻辑上的删除,非物理删除
- 例如:单据删除并非直接删除 -
-
- - - 中立字段
- 是否内置数据 -
-
- - - 创建ID - - - - - 创建者 - - - - - 创建时间 - - - - - 修改ID - - - - - 更新者 - - - - - 修改日期 - - - - - 数据版本 - - - - - 系统租户表
- 根据TenantType 分为两种方案:
- 1.按租户字段区分
- 2.按租户分库
- -
- - 注意:
- 使用租户Id方案,无需配置分库的连接 -
-
- - - 名称 - - - - - 租户类型 - - - - - 数据库/租户标识 不可重复
- 使用Id方案,可无需配置 -
-
- - - 主机
- 使用Id方案,可无需配置 -
-
- - - 数据库类型
- 使用Id方案,可无需配置 -
-
- - - 数据库连接
- 使用Id方案,可无需配置 -
-
- - - 状态 - - - - - 备注 - - 用户信息表 @@ -42872,12 +42761,6 @@ api ID - - - ID - 泛型主键Tkey - - 用户信息表 @@ -42967,43 +42850,6 @@ 数据库读取类型 - - - 租户模型接口 - - - - - 租户Id - - - - - 标识 多租户 的业务表
- 默认设置是多库
- 公共表无需区分 直接使用主库 各自业务在各自库中
-
-
- - - 租户隔离方案 - - - - - Id隔离 - - - - - 库隔离 - - - - - 表隔离 - - 博客信息展示类