refactor 封装任务,调整人员获取
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Job;
|
||||
|
||||
public class CreateGetUploadRecordJob
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ILogger<CreateGetUploadRecordJob> _logger;
|
||||
private readonly ISqlSugarOptionsService _sqlSugarOptionsService;
|
||||
|
||||
public CreateGetUploadRecordJob(IDbContext dbContext, ILogger<CreateGetUploadRecordJob> logger, ISqlSugarOptionsService sqlSugarOptionsService)
|
||||
{
|
||||
_logger = logger;
|
||||
_sqlSugarOptionsService = sqlSugarOptionsService;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
_sqlSugarOptionsService.IgnoreTenant = true;
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "生成{type}任务失败:{message}", DeviceTaskEnumType.UploadRecord.GetDescription(), ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_sqlSugarOptionsService.IgnoreTenant = false;
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Job
|
||||
{
|
||||
public class CreateSyncServerDateTimeJob
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ILogger<CreateSyncServerDateTimeJob> _logger;
|
||||
private readonly ISqlSugarOptionsService _sqlSugarOptionsService;
|
||||
|
||||
public CreateSyncServerDateTimeJob(IDbContext dbContext, ILogger<CreateSyncServerDateTimeJob> logger, ISqlSugarOptionsService sqlSugarOptionsService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
_sqlSugarOptionsService = sqlSugarOptionsService;
|
||||
}
|
||||
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||
_sqlSugarOptionsService.IgnoreTenant = true;
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "生成同步时间任务失败:{message}", ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_sqlSugarOptionsService.IgnoreTenant = false;
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,6 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
|
||||
{
|
||||
var tasks = await _dbContext.Queryable<DeviceTaskEntity>()
|
||||
.Where(x => request.Ids.Contains(x.Id))
|
||||
.Where(x => x.Status == DeviceTaskStatusEnumType.Process || x.Status == DeviceTaskStatusEnumType.Error)
|
||||
.ToListAsync();
|
||||
|
||||
//判断process任务时间
|
||||
|
||||
Reference in New Issue
Block a user