Procházet zdrojové kódy

!1704 优化框架基类中IsDelete字段的定义,调整为按需继承;框架功能基本不用假删除;应用中也用的不多,不必在每个查询都自动带上IsDelete=false
Merge pull request !1704 from Lzh666/N/A

zuohuaijun před 1 rokem
rodič
revize
bb08e1bf30

+ 44 - 1
Admin.NET/Admin.NET.Core/Entity/EntityBase.cs

@@ -22,7 +22,7 @@ public abstract class EntityBaseId
 /// 框架实体基类
 /// </summary>
 [SugarIndex("index_{table}_CT", nameof(CreateTime), OrderByType.Asc)]
-public abstract class EntityBase : EntityBaseId, IDeletedFilter
+public abstract class EntityBase : EntityBaseId
 {
     /// <summary>
     /// 创建时间
@@ -76,7 +76,14 @@ public abstract class EntityBase : EntityBaseId, IDeletedFilter
     /// </summary>
     [SugarColumn(ColumnDescription = "修改者姓名", Length = 64)]
     public virtual string? UpdateUserName { get; set; }
+}
 
+/// <summary>
+/// 框架实体基类(删除标志)
+/// </summary>
+[SugarIndex("index_{table}_D", nameof(IsDelete), OrderByType.Asc)]
+public abstract class EntityBaseDel : EntityBase, IDeletedFilter
+{
     /// <summary>
     /// 软删除
     /// </summary>
@@ -116,6 +123,18 @@ public abstract class EntityBaseOrg : EntityBase, IOrgIdFilter
     //public virtual string? CreateOrgName { get; set; }
 }
 
+/// <summary>
+/// 机构实体基类(数据权限、删除标志)
+/// </summary>
+public abstract class EntityBaseOrgDel : EntityBaseDel, IOrgIdFilter
+{
+    /// <summary>
+    /// 机构Id
+    /// </summary>
+    [SugarColumn(ColumnDescription = "机构Id", IsNullable = true)]
+    public virtual long OrgId { get; set; }
+}
+
 /// <summary>
 /// 租户实体基类
 /// </summary>
@@ -128,6 +147,18 @@ public abstract class EntityBaseTenant : EntityBase, ITenantIdFilter
     public virtual long? TenantId { get; set; }
 }
 
+/// <summary>
+/// 租户实体基类(删除标志)
+/// </summary>
+public abstract class EntityBaseTenantDel : EntityBaseDel, ITenantIdFilter
+{
+    /// <summary>
+    /// 租户Id
+    /// </summary>
+    [SugarColumn(ColumnDescription = "租户Id", IsOnlyIgnoreUpdate = true)]
+    public virtual long? TenantId { get; set; }
+}
+
 /// <summary>
 /// 租户实体基类Id
 /// </summary>
@@ -144,6 +175,18 @@ public abstract class EntityBaseTenantId : EntityBaseId, ITenantIdFilter
 /// 租户机构实体基类(数据权限)
 /// </summary>
 public abstract class EntityBaseTenantOrg : EntityBaseOrg, ITenantIdFilter
+{
+    /// <summary>
+    /// 租户Id
+    /// </summary>
+    [SugarColumn(ColumnDescription = "租户Id", IsOnlyIgnoreUpdate = true)]
+    public virtual long? TenantId { get; set; }
+}
+
+/// <summary>
+/// 租户机构实体基类(数据权限、删除标志)
+/// </summary>
+public abstract class EntityBaseTenantOrgDel: EntityBaseOrgDel, ITenantIdFilter
 {
     /// <summary>
     /// 租户Id

+ 1 - 1
Admin.NET/Admin.NET.Core/Entity/SysLdap.cs

@@ -11,7 +11,7 @@ namespace Admin.NET.Core;
 /// </summary>
 [SugarTable(null, "系统域登录信息配置表")]
 [SysTable]
-public class SysLdap : EntityBaseTenant
+public class SysLdap : EntityBaseTenantDel
 {
     /// <summary>
     /// 主机

+ 8 - 8
Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs

@@ -17,7 +17,7 @@ public static class RepositoryExtension
     /// <param name="repository"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static int FakeDelete<T>(this ISugarRepository repository, T entity) where T : EntityBase, new()
+    public static int FakeDelete<T>(this ISugarRepository repository, T entity) where T : EntityBaseDel, new()
     {
         return repository.Context.FakeDelete(entity);
     }
@@ -29,7 +29,7 @@ public static class RepositoryExtension
     /// <param name="db"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static int FakeDelete<T>(this ISqlSugarClient db, T entity) where T : EntityBase, new()
+    public static int FakeDelete<T>(this ISqlSugarClient db, T entity) where T : EntityBaseDel, new()
     {
         return db.Updateable(entity).AS().ReSetValue(x => { x.IsDelete = true; })
             .IgnoreColumns(ignoreAllNullColumns: true)
@@ -45,7 +45,7 @@ public static class RepositoryExtension
     /// <param name="repository"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static int FakeDelete<T>(this ISugarRepository repository, List<T> entity) where T : EntityBase, new()
+    public static int FakeDelete<T>(this ISugarRepository repository, List<T> entity) where T : EntityBaseDel, new()
     {
         return repository.Context.FakeDelete(entity);
     }
@@ -57,7 +57,7 @@ public static class RepositoryExtension
     /// <param name="db"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static int FakeDelete<T>(this ISqlSugarClient db, List<T> entity) where T : EntityBase, new()
+    public static int FakeDelete<T>(this ISqlSugarClient db, List<T> entity) where T : EntityBaseDel, new()
     {
         return db.Updateable(entity).AS().ReSetValue(x => { x.IsDelete = true; })
             .IgnoreColumns(ignoreAllNullColumns: true)
@@ -73,7 +73,7 @@ public static class RepositoryExtension
     /// <param name="repository"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static Task<int> FakeDeleteAsync<T>(this ISugarRepository repository, T entity) where T : EntityBase, new()
+    public static Task<int> FakeDeleteAsync<T>(this ISugarRepository repository, T entity) where T : EntityBaseDel, new()
     {
         return repository.Context.FakeDeleteAsync(entity);
     }
@@ -85,7 +85,7 @@ public static class RepositoryExtension
     /// <param name="db"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static Task<int> FakeDeleteAsync<T>(this ISqlSugarClient db, T entity) where T : EntityBase, new()
+    public static Task<int> FakeDeleteAsync<T>(this ISqlSugarClient db, T entity) where T : EntityBaseDel, new()
     {
         return db.Updateable(entity).AS().ReSetValue(x => { x.IsDelete = true; })
             .IgnoreColumns(ignoreAllNullColumns: true)
@@ -101,7 +101,7 @@ public static class RepositoryExtension
     /// <param name="repository"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static Task<int> FakeDeleteAsync<T>(this ISugarRepository repository, List<T> entity) where T : EntityBase, new()
+    public static Task<int> FakeDeleteAsync<T>(this ISugarRepository repository, List<T> entity) where T : EntityBaseDel, new()
     {
         return repository.Context.FakeDeleteAsync(entity);
     }
@@ -113,7 +113,7 @@ public static class RepositoryExtension
     /// <param name="db"></param>
     /// <param name="entity"></param>
     /// <returns></returns>
-    public static Task<int> FakeDeleteAsync<T>(this ISqlSugarClient db, List<T> entity) where T : EntityBase, new()
+    public static Task<int> FakeDeleteAsync<T>(this ISqlSugarClient db, List<T> entity) where T : EntityBaseDel, new()
     {
         return db.Updateable(entity).AS().ReSetValue(x => { x.IsDelete = true; })
             .IgnoreColumns(ignoreAllNullColumns: true)

+ 1 - 1
Admin.NET/Admin.NET.Core/Service/Tenant/SysTenantService.cs

@@ -106,7 +106,7 @@ public class SysTenantService : IDynamicApiController, ITransient
     {
         return await _sysTenantRep.AsQueryable()
            .LeftJoin<SysOrg>((u, a) => u.OrgId == a.Id).ClearFilter()
-           .Where(u => u.Status == StatusEnum.Enable && u.IsDelete == false)
+           .Where(u => u.Status == StatusEnum.Enable)
            .Select((u, a) => new
            {
                Label = $"{u.Title}-{a.Name}",

+ 2 - 2
Admin.NET/Admin.NET.Core/Service/User/SysUserLdapService.cs

@@ -1,4 +1,4 @@
-// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
+// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
 //
 // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
 //
@@ -33,7 +33,7 @@ public class SysUserLdapService : ITransient
         await _sysUserLdapRep.AsUpdateable()
             .InnerJoin<SysUser>((l, u) => l.EmployeeId == u.Account)
             .SetColumns((l, u) => new SysUserLdap { UserId = u.Id })
-            .Where((l, u) => l.TenantId == tenantId && u.Status == StatusEnum.Enable && u.IsDelete == false)
+            .Where((l, u) => l.TenantId == tenantId && u.Status == StatusEnum.Enable)
             .ExecuteCommandAsync();
     }
 

+ 1 - 1
Admin.NET/Admin.NET.Core/Utils/CodeGenUtil.cs

@@ -264,7 +264,7 @@ public static class CodeGenUtil
             nameof(EntityBase.UpdateUserId),
             nameof(EntityBase.CreateUserName),
             nameof(EntityBase.UpdateUserName),
-            nameof(EntityBase.IsDelete)
+            nameof(EntityBaseDel.IsDelete)
         };
         return columnList.Contains(columnName);
     }

+ 1 - 1
Admin.NET/Plugins/Admin.NET.Plugin.ApprovalFlow/Entity/ApprovalFlow.cs

@@ -10,7 +10,7 @@ namespace Admin.NET.Plugin.ApprovalFlow;
 /// 审批流程信息表
 /// </summary>
 [SugarTable(null, "审批流程信息表")]
-public class ApprovalFlow : EntityBaseOrg
+public class ApprovalFlow : EntityBaseOrgDel
 {
     /// <summary>
     /// 编号

+ 2 - 2
Admin.NET/Plugins/Admin.NET.Plugin.DingTalk/Entity/DingTalkRoleUser.cs

@@ -1,10 +1,10 @@
-namespace Admin.NET.Plugin.DingTalk;
+namespace Admin.NET.Plugin.DingTalk;
 
 /// <summary>
 /// 钉钉角色信息
 /// </summary>
 [SugarTable(null, "钉钉角色表")]
-public class DingTalkRoleUser : EntityBase
+public class DingTalkRoleUser : EntityBaseDel
 {
     /// <summary>
     /// 钉钉用户id