33 lines
772 B
C#
33 lines
772 B
C#
using Dlhis.Entity.Common;
|
|
using Kurisu.SqlSugar.Services;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.ScheduledTask.CommonJobs;
|
|
|
|
public class DelApiLogTaskJob
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public DelApiLogTaskJob(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task RunAsync()
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
DateTime todayStart = now.Date;
|
|
DateTime threeDaysAgoStart = todayStart.AddDays(-3);
|
|
|
|
var logs = await _dbContext.ChangeDb("log")
|
|
.Queryable<ApiLogEntity>()
|
|
.Where(x => x._ts<= threeDaysAgoStart)
|
|
.OrderBy(x =>x._ts,OrderByType.Asc)
|
|
.ToListAsync();
|
|
|
|
await _dbContext.ChangeDb("log").DeleteReallyAsync(logs);
|
|
}
|
|
}
|
|
|
|
|