54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
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(CreateGetUploadRecordJob), "0 0/1 * * * ?", Name = "创建上传设备数据任务")]
|
|
public class CreateGetUploadRecordJob : BaseJob
|
|
{
|
|
|
|
public CreateGetUploadRecordJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
{
|
|
}
|
|
|
|
public override async Task RunAsync(IServiceProvider serviceProvider)
|
|
{
|
|
var devices = await DbContext.Queryable<DeviceEntity>()
|
|
.Where(x => x.Enable)
|
|
.Where(x => x.Type == DeviceTypeEnumType.Attendance || x.Type == DeviceTypeEnumType.Door)
|
|
.ToListAsync();
|
|
|
|
//过滤处理中的任务
|
|
var currentUniqueNos = await DbContext.Queryable<DeviceTaskEntity>()
|
|
.Where(x => x.Type == DeviceTaskEnumType.UploadRecord)
|
|
.Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Wait)
|
|
.Select(x => x.DeviceUniqueNo)
|
|
.ToListAsync();
|
|
|
|
var tasks = devices.Where(x => !currentUniqueNos.Contains(x.UniqueNo)).Select(x => new DeviceTaskEntity
|
|
{
|
|
DeviceUniqueNo = x.UniqueNo,
|
|
Status = DeviceTaskStatusEnumType.Wait,
|
|
|
|
TenantId = x.TenantId,
|
|
Version = 0,
|
|
Type = DeviceTaskEnumType.UploadRecord,
|
|
|
|
CreatedBy = 1,
|
|
CreateTime = DateTime.Now,
|
|
ModifiedBy = 1,
|
|
ModifiedTime = DateTime.Now,
|
|
|
|
})
|
|
.ToList();
|
|
|
|
await DbContext.InsertAsync(tasks);
|
|
}
|
|
}
|