初步添加报警功能

This commit is contained in:
2025-09-13 12:30:12 +08:00
parent 5a39796f0e
commit 15e2caed22
12 changed files with 457 additions and 1 deletions

View File

@@ -199,7 +199,7 @@ public abstract class BaseRepository<TEntity>
/// </summary>
/// <param name="number">要获取的实体数量。</param>
/// <returns>包含指定数量实体对象的列表。</returns>
protected async Task<List<TEntity>> TakeAsync(int number)
public virtual async Task<List<TEntity>> TakeAsync(int number)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
@@ -210,6 +210,23 @@ public abstract class BaseRepository<TEntity>
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 Db.Deleteable<TEntity>()
.In(id)
.ExecuteCommandAsync();
stopwatch.Stop();
_logger.LogInformation($"DeleteById {typeof(TEntity).Name}, ID: {id}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
public async Task<bool> AddBatchAsync(List<TEntity> entities)
{
var stopwatch = new Stopwatch();