Browse Source

!779 增加集合假删除方法
Merge pull request !779 from KaneLeung/next

zuohuaijun 2 years ago
parent
commit
b3b4411d21
1 changed files with 56 additions and 0 deletions
  1. 56 0
      Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs

+ 56 - 0
Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs

@@ -41,6 +41,34 @@ public static class RepositoryExtension
             .ExecuteCommand();
     }
 
+    /// <summary>
+    /// 实体集合批量假删除 _rep.FakeDelete(entity)
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <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()
+    {
+        return repository.Context.FakeDelete(entity);
+    }
+
+    /// <summary>
+    /// 实体集合批量假删除 db.FakeDelete(entity)
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <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()
+    {
+        return db.Updateable(entity).AS().ReSetValue(x => { x.IsDelete = true; })
+            .IgnoreColumns(ignoreAllNullColumns: true)
+            .EnableDiffLogEvent()   // 记录差异日志
+            .UpdateColumns(x => new { x.IsDelete, x.UpdateTime, x.UpdateUserId })  // 允许更新的字段-AOP拦截自动设置UpdateTime、UpdateUserId
+            .ExecuteCommand();
+    }
+
     /// <summary>
     /// 实体假删除异步 _rep.FakeDeleteAsync(entity)
     /// </summary>
@@ -69,6 +97,34 @@ public static class RepositoryExtension
             .ExecuteCommandAsync();
     }
 
+    /// <summary>
+    /// 实体集合批量假删除异步 _rep.FakeDeleteAsync(entity)
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <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()
+    {
+        return repository.Context.FakeDeleteAsync(entity);
+    }
+
+    /// <summary>
+    /// 实体集合批量假删除 db.FakeDelete(entity)
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <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()
+    {
+        return db.Updateable(entity).AS().ReSetValue(x => { x.IsDelete = true; })
+            .IgnoreColumns(ignoreAllNullColumns: true)
+            .EnableDiffLogEvent()   // 记录差异日志
+            .UpdateColumns(x => new { x.IsDelete, x.UpdateTime, x.UpdateUserId })  // 允许更新的字段-AOP拦截自动设置UpdateTime、UpdateUserId
+            .ExecuteCommandAsync();
+    }
+
     /// <summary>
     /// 排序方式(默认降序)
     /// </summary>