|
@@ -226,8 +226,8 @@ namespace Hotline.Repository.SqlSugar.Extensions
|
|
//Log.Warning($"sql参数:{JsonSerializer.Serialize(db.Ado.SqlStackTrace, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs) })}");
|
|
//Log.Warning($"sql参数:{JsonSerializer.Serialize(db.Ado.SqlStackTrace, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs) })}");
|
|
|
|
|
|
|
|
|
|
- ////获取原生SQL推荐 5.1.4.63 性能OK
|
|
|
|
- //Log.Information(UtilMethods.GetNativeSql(sql, pars));
|
|
|
|
|
|
+ //获取原生SQL推荐 5.1.4.63 性能OK
|
|
|
|
+ Log.Information(UtilMethods.GetNativeSql(sql, pars));
|
|
|
|
|
|
//Log.Information("Sql: {0}", sql);
|
|
//Log.Information("Sql: {0}", sql);
|
|
//Log.Information("SqlParameters: {0}", string.Join(',', pars.Select(d => d.Value)));
|
|
//Log.Information("SqlParameters: {0}", string.Join(',', pars.Select(d => d.Value)));
|
|
@@ -331,52 +331,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
|
|
#endregion
|
|
}
|
|
}
|