48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Device.Entities;
|
|
using Dlhis.Entity.Device.Enums;
|
|
using Dlhis.ScheduledTask.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)
|
|
{
|
|
}
|
|
|
|
protected 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,
|
|
DeviceType = x.Type,
|
|
Priority = 49,
|
|
Source = "定时任务创建设备同步时间任务"
|
|
}).ToList();
|
|
|
|
await DbContext.InsertAsync(tasks);
|
|
}
|
|
} |