¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core.DB.Models; |
| | | using WIDESEA_Core.Tenants; |
| | | |
| | | namespace WIDESEA_Core.DB |
| | | { |
| | | public class RepositorySetting |
| | | { |
| | | private static readonly Lazy<IEnumerable<Type>> AllEntitys = new(() => |
| | | { |
| | | var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; |
| | | var referencedAssemblies = System.IO.Directory.GetFiles(path, MainDb.AssemblyName).Select(Assembly.LoadFrom).FirstOrDefault(); |
| | | return referencedAssemblies |
| | | .GetTypes() |
| | | .Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(BaseEntity))) |
| | | .Where(it => it.FullName != null && it.FullName.StartsWith(MainDb.EntityNameSpace)); |
| | | }); |
| | | |
| | | public static IEnumerable<Type> Entitys => AllEntitys.Value; |
| | | |
| | | /// <summary> |
| | | /// é
ç½®å®ä½è½¯å é¤è¿æ»¤å¨<br/> |
| | | /// ç»ä¸è¿æ»¤ 软å é¤ æ éèªå·±åæ¡ä»¶ |
| | | /// </summary> |
| | | public static void SetDeletedEntityFilter(SqlSugarScopeProvider db) |
| | | { |
| | | //db.QueryFilter.AddTableFilter<IDeleteFilter>(it => it.IsDeleted == false); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// é
ç½®ç§æ· |
| | | /// </summary> |
| | | public static void SetTenantEntityFilter(SqlSugarScopeProvider db) |
| | | { |
| | | if (App.User is not { UserId: > 0, TenantId: > 0 }) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //å¤ç§æ· å表 |
| | | //db.QueryFilter.AddTableFilter<ITenantEntity>(it => it.TenantId == App.User.TenantId || it.TenantId == 0); |
| | | |
| | | //å¤ç§æ· å¤è¡¨ |
| | | //db.SetTenantTable(App.User.TenantId.ToString()); |
| | | } |
| | | } |
| | | } |