refactor 封装任务,调整人员获取
This commit is contained in:
54
Src/Dlhis.ScheduledTask/Jobs/CreateSyncServerDateTimeJob.cs
Normal file
54
Src/Dlhis.ScheduledTask/Jobs/CreateSyncServerDateTimeJob.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.Scheduled;
|
||||
using Kurisu.Scheduled.Attributes;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 设备时间同步
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(CreateSyncServerDateTimeJob), "0 0 0/1 * * ?", Name = "设备时间同步")]
|
||||
public class CreateSyncServerDateTimeJob : BaseJob
|
||||
{
|
||||
|
||||
public CreateSyncServerDateTimeJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var deviceUniqueNos = await DbContext.Queryable<DeviceTaskEntity>()
|
||||
.Where(x => x.Status == DeviceTaskStatusEnumType.Wait || x.Status == DeviceTaskStatusEnumType.Process)
|
||||
.Where(x => x.Type == DeviceTaskEnumType.SyncDateTime)
|
||||
.Select(x => x.DeviceUniqueNo)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
var devices = await DbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => !deviceUniqueNos.Contains(x.UniqueNo))
|
||||
.Where(x => x.Enable)
|
||||
.ToListAsync();
|
||||
|
||||
var tasks = devices.Select(x => new DeviceTaskEntity
|
||||
{
|
||||
DeviceUniqueNo = x.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
|
||||
TenantId = x.TenantId,
|
||||
Version = 0,
|
||||
UserNo = string.Empty,
|
||||
Type = DeviceTaskEnumType.SyncDateTime,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifiedBy = 1,
|
||||
ModifiedTime = DateTime.Now,
|
||||
|
||||
}).ToList();
|
||||
|
||||
await DbContext.InsertAsync(tasks);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user