fix 恢复job

This commit is contained in:
2025-05-28 14:41:16 +08:00
parent de976738e2
commit bf095f2a7c

View File

@@ -1,61 +1,61 @@
// using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Entities;
// using Dlhis.ScheduledTask.Attributes; using Dlhis.ScheduledTask.Attributes;
//
// namespace Dlhis.ScheduledTask.Jobs; namespace Dlhis.ScheduledTask.Jobs;
//
// /// <summary> /// <summary>
// /// 归档设备通行记录 /// 归档设备通行记录
// /// </summary> /// </summary>
// [RecurringJob(nameof(ArchiveDeviceUploadLogJob), "0 0 3 * * ? ", Name = "归档设备通行记录")] [RecurringJob(nameof(ArchiveDeviceUploadLogJob), "0 0 3 * * ? ", Name = "归档设备通行记录")]
// public class ArchiveDeviceUploadLogJob : BaseJob public class ArchiveDeviceUploadLogJob : BaseJob
// { {
// public ArchiveDeviceUploadLogJob(IServiceProvider serviceProvider) : base(serviceProvider) public ArchiveDeviceUploadLogJob(IServiceProvider serviceProvider) : base(serviceProvider)
// { {
// } }
//
// protected override async Task RunAsync(IServiceProvider serviceProvider) protected override async Task RunAsync(IServiceProvider serviceProvider)
// { {
// //设置60天前的数据需要归档 //设置60天前的数据需要归档
// var before60Days = DateTime.Today.AddDays(-60).AddSeconds(1); var before60Days = DateTime.Today.AddDays(-60).AddSeconds(1);
// //每次查询500条数据 //每次查询500条数据
// const int limit = 500; const int limit = 500;
// //归档表 //归档表
// const string tableName = "deviceuploadlog_20250107"; const string tableName = "deviceuploadlog_20250107";
//
// //正序获取数据 //正序获取数据
// var data = await DbContext.Queryable<DeviceUploadLogEntity>() var data = await DbContext.Queryable<DeviceUploadLogEntity>()
// .Where(x => x.RaiseDateTime < before60Days) .Where(x => x.RaiseDateTime < before60Days)
// .OrderBy(x => x.Id) .OrderBy(x => x.Id)
// .ToPageListAsync(1, limit); .ToPageListAsync(1, limit);
//
// do do
// { {
// if (data.Any()) if (data.Any())
// { {
// await DbContext.Client.Ado.BeginTranAsync(); await DbContext.Client.Ado.BeginTranAsync();
// try try
// { {
// //删除数据 //删除数据
// await DbContext.DeleteReallyAsync(data); await DbContext.DeleteReallyAsync(data);
// foreach (var item in data) foreach (var item in data)
// { {
// item.Id = 0; item.Id = 0;
// } }
//
// //插入到归档表 //插入到归档表
// await DbContext.Client.Insertable(data).AS(tableName).ExecuteCommandAsync(); await DbContext.Client.Insertable(data).AS(tableName).ExecuteCommandAsync();
// await DbContext.Client.Ado.CommitTranAsync(); await DbContext.Client.Ado.CommitTranAsync();
// } }
// catch (Exception) catch (Exception)
// { {
// await DbContext.Client.Ado.RollbackTranAsync(); await DbContext.Client.Ado.RollbackTranAsync();
// } }
//
// await Task.Delay(200); await Task.Delay(200);
//
// //再次获取数据 //再次获取数据
// data = await DbContext.Queryable<DeviceUploadLogEntity>().Where(x => x.RaiseDateTime < before60Days).OrderBy(x => x.Id).ToPageListAsync(1, limit); data = await DbContext.Queryable<DeviceUploadLogEntity>().Where(x => x.RaiseDateTime < before60Days).OrderBy(x => x.Id).ToPageListAsync(1, limit);
// } }
// } while (data.Count == limit); } while (data.Count == limit);
// } }
// } }