refactor:删除不必要的方法
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq.Expressions;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Data;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
@@ -121,42 +119,6 @@ public abstract class BaseRepository<TEntity>
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID (Guid类型) 获取单个实体。
|
||||
/// </summary>
|
||||
/// <param name="id">实体的主键 ID (Guid类型)。</param>
|
||||
/// <returns>返回找到的实体,如果未找到则返回 null。</returns>
|
||||
public virtual async Task<TEntity> GetByIdAsync(Guid id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var entity = await _dbContext.GetInstance().Queryable<TEntity>()
|
||||
.In(id)
|
||||
.FirstAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"GetById {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步判断是否存在满足条件的实体。
|
||||
/// </summary>
|
||||
/// <param name="expression">查询条件的 Lambda 表达式。</param>
|
||||
/// <returns>如果存在则返回 true,否则返回 false。</returns>
|
||||
public virtual async Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> expression)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Queryable<TEntity>()
|
||||
.AnyAsync(expression);
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"Exists {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步开始数据库事务。
|
||||
@@ -186,38 +148,8 @@ public abstract class BaseRepository<TEntity>
|
||||
await _dbContext.GetInstance().RollbackTranAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步获取指定数量的实体。
|
||||
/// </summary>
|
||||
/// <param name="number">要获取的实体数量。</param>
|
||||
/// <returns>包含指定数量实体对象的列表。</returns>
|
||||
public virtual async Task<List<TEntity>> TakeAsync(int number)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var entity = await _dbContext.GetInstance().Queryable<TEntity>().Take(number).ToListAsync();
|
||||
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"TakeAsync {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID 删除单个实体。
|
||||
/// </summary>
|
||||
/// <param name="id">要删除的实体的主键 ID。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteByIdAsync(int id)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable<TEntity>()
|
||||
.In(id)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"DeleteById {typeof(TEntity).Name}, ID: {id}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<TEntity>> AddBatchAsync(List<TEntity> entities)
|
||||
{
|
||||
@@ -238,20 +170,4 @@ public abstract class BaseRepository<TEntity>
|
||||
return retrunEntities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步根据主键 ID 列表批量删除实体。
|
||||
/// </summary>
|
||||
/// <param name="ids">要删除的实体主键 ID 列表。</param>
|
||||
/// <returns>返回受影响的行数。</returns>
|
||||
public virtual async Task<int> DeleteByIdsAsync(List<int> ids)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
var result = await _dbContext.GetInstance().Deleteable<TEntity>()
|
||||
.In(ids)
|
||||
.ExecuteCommandAsync();
|
||||
stopwatch.Stop();
|
||||
_logger.LogInformation($"DeleteByIds {typeof(TEntity).Name}, Count: {ids.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user