fix 调整为凌晨3点执行

This commit is contained in:
2025-05-22 16:05:33 +08:00
parent 8581cb5190
commit 81be8763a4

View File

@@ -6,7 +6,7 @@ namespace Dlhis.ScheduledTask.Jobs;
/// <summary>
/// 归档设备通行记录
/// </summary>
[RecurringJob(nameof(ArchiveDeviceUploadLogJob), "0 0 20 * * ? ", Name = "归档设备通行记录")]
[RecurringJob(nameof(ArchiveDeviceUploadLogJob), "0 0 3 * * ? ", Name = "归档设备通行记录")]
public class ArchiveDeviceUploadLogJob : BaseJob
{
public ArchiveDeviceUploadLogJob(IServiceProvider serviceProvider) : base(serviceProvider)
@@ -15,13 +15,19 @@ public class ArchiveDeviceUploadLogJob : BaseJob
protected override async Task RunAsync(IServiceProvider serviceProvider)
{
//设置60天前的数据需要归档
var before60Days = DateTime.Today.AddDays(-60).AddSeconds(1);
//每次查询500条数据
const int limit = 500;
//归档表
const string tableName = "deviceuploadlog_20250107";
var data = await DbContext.Queryable<DeviceUploadLogEntity>().Where(x => x.RaiseDateTime < before60Days).OrderBy(x => x.Id).ToPageListAsync(1, limit);
//正序获取数据
var data = await DbContext.Queryable<DeviceUploadLogEntity>()
.Where(x => x.RaiseDateTime < before60Days)
.OrderBy(x => x.Id)
.ToPageListAsync(1, limit);
var now = DateTime.Now;
do
{
if (data.Any())
@@ -29,13 +35,14 @@ public class ArchiveDeviceUploadLogJob : BaseJob
await DbContext.Client.Ado.BeginTranAsync();
try
{
//删除数据
await DbContext.DeleteReallyAsync(data);
foreach (var item in data)
{
item.Id = 0;
}
//插入到归档表
await DbContext.Client.Insertable(data).AS(tableName).ExecuteCommandAsync();
await DbContext.Client.Ado.CommitTranAsync();
}
@@ -46,20 +53,9 @@ public class ArchiveDeviceUploadLogJob : BaseJob
await Task.Delay(200);
//再次获取数据
data = await DbContext.Queryable<DeviceUploadLogEntity>().Where(x => x.RaiseDateTime < before60Days).OrderBy(x => x.Id).ToPageListAsync(1, limit);
}
now = DateTime.Now;
} while (data.Count == limit && TimeSetting(now));
}
private bool TimeSetting(DateTime d)
{
if (d.Hour is >= 20 or <= 7)
{
return true;
}
return false;
} while (data.Count == limit);
}
}