fix(log): 修正CleanService日志级别为Information
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WCTDataMiner.Core.Data;
|
||||
using WCTDataMiner.Core.Models;
|
||||
|
||||
@@ -10,10 +11,12 @@ namespace WCTDataMiner.Core.Services;
|
||||
public class CleanService
|
||||
{
|
||||
private readonly WctMinerDbContext _context;
|
||||
private readonly ILogger<CleanService> _logger;
|
||||
|
||||
public CleanService(WctMinerDbContext context)
|
||||
public CleanService(WctMinerDbContext context, ILogger<CleanService> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -21,8 +24,14 @@ public class CleanService
|
||||
/// </summary>
|
||||
public async Task<int> CleanByScenarioAsync(Guid scenarioId)
|
||||
{
|
||||
_logger.LogInformation("开始清理场景 {ScenarioId} 的数据", scenarioId);
|
||||
|
||||
var scenario = await _context.TestScenarios.FindAsync(scenarioId);
|
||||
if (scenario == null) return 0;
|
||||
if (scenario == null)
|
||||
{
|
||||
_logger.LogWarning("场景 {ScenarioId} 不存在", scenarioId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 软删除关联的Qfod记录
|
||||
var qfodRecords = await _context.QfodRecords
|
||||
@@ -47,7 +56,10 @@ public class CleanService
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return qfodRecords.Count + plossRecords.Count + 1;
|
||||
var count = qfodRecords.Count + plossRecords.Count + 1;
|
||||
_logger.LogInformation("场景 {ScenarioId} 清理完成,共删除 {Count} 条记录", scenarioId, count);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,6 +67,8 @@ public class CleanService
|
||||
/// </summary>
|
||||
public async Task<int> CleanAllAsync()
|
||||
{
|
||||
_logger.LogWarning("开始清理所有数据");
|
||||
|
||||
int count = 0;
|
||||
|
||||
// 软删除所有Qfod记录
|
||||
@@ -82,6 +96,8 @@ public class CleanService
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("所有数据清理完成,共删除 {Count} 条记录", count);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user