|
@@ -129,6 +129,7 @@ namespace Hotline.Repository.SqlSugar.Extensions
|
|
|
db =>
|
|
|
{
|
|
|
SetDbAop(db, services);
|
|
|
+ db.QueryFilter.AddTableFilter<ISoftDelete>(entity => !entity.IsDeleted);
|
|
|
}
|
|
|
);
|
|
|
|
|
@@ -331,52 +332,52 @@ namespace Hotline.Repository.SqlSugar.Extensions
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- SetDeletedEntityFilter(db);
|
|
|
+ //SetDeletedEntityFilter(db);
|
|
|
}
|
|
|
|
|
|
- private static void SetDeletedEntityFilter(SqlSugarClient db)
|
|
|
- {
|
|
|
- var cacheKey = $"DbFilter:{db.CurrentConnectionConfig.ConfigId}:IsDeleted";
|
|
|
- var tableFilterItemList = db.DataCache.Get<List<TableFilterItem<object>>>(cacheKey);
|
|
|
- if (tableFilterItemList == null)
|
|
|
- {
|
|
|
- // 获取基类实体数据表
|
|
|
- var entityTypes = AppDomain.CurrentDomain.GetAssemblies()
|
|
|
- .SelectMany(d => d.GetTypes())
|
|
|
- .Where(d => !d.IsInterface
|
|
|
- && !d.IsAbstract
|
|
|
- && d.IsClass
|
|
|
- && d.GetInterfaces().Any(x => x == typeof(ISoftDelete)));
|
|
|
- if (!entityTypes.Any()) return;
|
|
|
-
|
|
|
- var tableFilterItems = new List<TableFilterItem<object>>();
|
|
|
- foreach (var entityType in entityTypes)
|
|
|
- {
|
|
|
- if (entityType.GetProperty("IsDeleted") is null) continue;
|
|
|
- //// 排除非当前数据库实体
|
|
|
- //var tAtt = entityType.GetCustomAttribute<TenantAttribute>();
|
|
|
- //if ((tAtt != null && (string)db.CurrentConnectionConfig.ConfigId != tAtt.configId.ToString()) ||
|
|
|
- // (tAtt == null && (string)db.CurrentConnectionConfig.ConfigId != SqlSugarConst.ConfigId))
|
|
|
- // continue;
|
|
|
-
|
|
|
- var lambda = DynamicExpressionParser.ParseLambda(new[] {
|
|
|
- Expression.Parameter(entityType, "d") },
|
|
|
- typeof(bool),
|
|
|
- $"{nameof(SoftDeleteEntity.IsDeleted)} == @0", false);
|
|
|
- var tableFilterItem = new TableFilterItem<object>(entityType, lambda);
|
|
|
- tableFilterItems.Add(tableFilterItem);
|
|
|
- db.QueryFilter.Add(tableFilterItem);
|
|
|
- }
|
|
|
- db.DataCache.Add(cacheKey, tableFilterItems);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- tableFilterItemList.ForEach(u =>
|
|
|
- {
|
|
|
- db.QueryFilter.Add(u);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ //private static void SetDeletedEntityFilter(SqlSugarClient db)
|
|
|
+ //{
|
|
|
+ // var cacheKey = $"DbFilter:{db.CurrentConnectionConfig.ConfigId}:IsDeleted";
|
|
|
+ // var tableFilterItemList = db.DataCache.Get<List<TableFilterItem<object>>>(cacheKey);
|
|
|
+ // if (tableFilterItemList == null)
|
|
|
+ // {
|
|
|
+ // // 获取基类实体数据表
|
|
|
+ // var entityTypes = AppDomain.CurrentDomain.GetAssemblies()
|
|
|
+ // .SelectMany(d => d.GetTypes())
|
|
|
+ // .Where(d => !d.IsInterface
|
|
|
+ // && !d.IsAbstract
|
|
|
+ // && d.IsClass
|
|
|
+ // && d.GetInterfaces().Any(x => x == typeof(ISoftDelete)));
|
|
|
+ // if (!entityTypes.Any()) return;
|
|
|
+
|
|
|
+ // var tableFilterItems = new List<TableFilterItem<object>>();
|
|
|
+ // foreach (var entityType in entityTypes)
|
|
|
+ // {
|
|
|
+ // if (entityType.GetProperty("IsDeleted") is null) continue;
|
|
|
+ // //// 排除非当前数据库实体
|
|
|
+ // //var tAtt = entityType.GetCustomAttribute<TenantAttribute>();
|
|
|
+ // //if ((tAtt != null && (string)db.CurrentConnectionConfig.ConfigId != tAtt.configId.ToString()) ||
|
|
|
+ // // (tAtt == null && (string)db.CurrentConnectionConfig.ConfigId != SqlSugarConst.ConfigId))
|
|
|
+ // // continue;
|
|
|
+
|
|
|
+ // var lambda = DynamicExpressionParser.ParseLambda(new[] {
|
|
|
+ // Expression.Parameter(entityType, "d") },
|
|
|
+ // typeof(bool),
|
|
|
+ // $"{nameof(SoftDeleteEntity.IsDeleted)} == @0", false);
|
|
|
+ // var tableFilterItem = new TableFilterItem<object>(entityType, lambda);
|
|
|
+ // tableFilterItems.Add(tableFilterItem);
|
|
|
+ // db.QueryFilter.Add(tableFilterItem);
|
|
|
+ // }
|
|
|
+ // db.DataCache.Add(cacheKey, tableFilterItems);
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // tableFilterItemList.ForEach(u =>
|
|
|
+ // {
|
|
|
+ // db.QueryFilter.Add(u);
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
#endregion
|
|
|
}
|