fix 调试大华设备对接
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Job
|
||||
{
|
||||
public class CreateGetAttendanceJob
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ILogger<CreateSyncServerDateTimeJob> _logger;
|
||||
|
||||
public CreateGetAttendanceJob(IDbContext dbContext, ILogger<CreateSyncServerDateTimeJob> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup();
|
||||
try
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Enable).ToListAsync();
|
||||
devices = devices.Where(x => x.Funcs.Contains(DeviceFuncEnumType.Attendance)).ToList();
|
||||
|
||||
var tasks = devices.Select(x => new DeviceTaskEntity
|
||||
{
|
||||
DeviceUniqueNo = x.UniqueNo,
|
||||
Status = DeviceTaskStatusEnumType.Wait,
|
||||
|
||||
TenantId = x.TenantId,
|
||||
Version = 0,
|
||||
UserNo = string.Empty,
|
||||
UserCode = string.Empty,
|
||||
Type = DeviceTaskEnumType.UploadRecord,
|
||||
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
ModifiedBy = 1,
|
||||
ModifiedTime = DateTime.Now,
|
||||
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.InsertAsync(tasks);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"生成{DeviceTaskEnumType.UploadRecord.GetDescription()}任务失败:" + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Job
|
||||
{
|
||||
public class CreateSyncServerDateTimeJob
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ILogger<CreateSyncServerDateTimeJob> _logger;
|
||||
|
||||
public CreateSyncServerDateTimeJob(IDbContext dbContext, ILogger<CreateSyncServerDateTimeJob> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
_dbContext.Client.QueryFilter.ClearAndBackup();
|
||||
try
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().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,
|
||||
UserCode = 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, "生成同步时间任务失败:" + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dbContext.Client.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,19 @@ public class TimePeriodToDeviceResponse
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 星期
|
||||
/// </summary>
|
||||
public List<DayOfWeek> Weeks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时段区间
|
||||
/// 时段名称
|
||||
/// </summary>
|
||||
public TimePeriod TimePeriod { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使能
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 星期时段
|
||||
/// </summary>
|
||||
public List<TimePeriodWeekDaySection> Sections { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using Kurisu.Core.CustomClass;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||
|
||||
public class TimePeriodWeekDaySection
|
||||
{
|
||||
/// <summary>
|
||||
/// 星期
|
||||
/// </summary>
|
||||
public DayOfWeek DayOfWeek { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时段区间 最多4个
|
||||
/// </summary>
|
||||
public List<TimePeriod> TimePeriods { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Kurisu.Core.CustomClass;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||
|
||||
public class UploadRecordToDeviceResponse
|
||||
{
|
||||
public DateTimePeriod DateTimePeriod { get; set; }
|
||||
}
|
||||
@@ -106,6 +106,30 @@ public class AssignmentService : IAssignmentService
|
||||
return new List<DeviceTaskToDeviceByDeviceResponse>();
|
||||
}
|
||||
|
||||
Dictionary<string, DateTime?> deviceUploadInfos = null;
|
||||
if (data.Any(x => x.Type == DeviceTaskEnumType.UploadRecord))
|
||||
{
|
||||
var deviceNos = data.Select(x => x.DeviceUniqueNo).Distinct();
|
||||
deviceUploadInfos = new Dictionary<string, DateTime?>(deviceNos.Count());
|
||||
|
||||
var logInfos = await _dbContext.Queryable<DeviceUploadLogEntity>().Select(it => new
|
||||
{
|
||||
Index2 = SqlFunc.RowNumber(SqlFunc.Desc(it.Id), it.DeviceUniqueNo),
|
||||
it.DeviceUniqueNo,
|
||||
it.RaiseDateTime
|
||||
})
|
||||
.MergeTable()
|
||||
.Where(it => it.Index2 == 1)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in deviceNos)
|
||||
{
|
||||
var logInfo = logInfos.FirstOrDefault(x => x.DeviceUniqueNo == item);
|
||||
deviceUploadInfos.Add(item, logInfo?.RaiseDateTime);
|
||||
}
|
||||
}
|
||||
|
||||
//申请新的请求域
|
||||
return Scoped.Request.Value.Create((sp) =>
|
||||
{
|
||||
var faceUrlOptions = sp.GetService<IOptions<FaceUrlOptions>>().Value;
|
||||
@@ -137,9 +161,9 @@ public class AssignmentService : IAssignmentService
|
||||
Tasks = x.AsEnumerable().Select(item =>
|
||||
{
|
||||
var key = $"face:{item.UserCode}";
|
||||
var token = item.Type == DeviceTaskEnumType.Add
|
||||
? timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit))
|
||||
: string.Empty;
|
||||
var token = item.Type == DeviceTaskEnumType.Delete
|
||||
? string.Empty
|
||||
: timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit));
|
||||
|
||||
var dto = new TaskCombineDto
|
||||
{
|
||||
@@ -162,11 +186,11 @@ public class AssignmentService : IAssignmentService
|
||||
UserName = item.UserName,
|
||||
DepartmentNo = item.DepartmentNo,
|
||||
DepartmentName = item.DepartmentName,
|
||||
CardNo = item.Type == DeviceTaskEnumType.Add ? item.CardNo : string.Empty,
|
||||
Face = item.Type == DeviceTaskEnumType.Add ? faceUrlOptions.Url + token : string.Empty,//下发才附带照片信息
|
||||
CardNo = item.Type == DeviceTaskEnumType.Delete ? string.Empty : item.CardNo,
|
||||
Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : faceUrlOptions.Url + token,//下发才附带照片信息
|
||||
ValidDatePeriod = new DatePeriod
|
||||
{
|
||||
Start = DateOnly.FromDateTime(DateTime.Now),
|
||||
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
|
||||
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
|
||||
},
|
||||
TimePeriods = new List<int> { 1 },
|
||||
@@ -181,15 +205,23 @@ public class AssignmentService : IAssignmentService
|
||||
dto.Info = new TimePeriodToDeviceResponse
|
||||
{
|
||||
Id = 1,
|
||||
TimePeriod = new TimePeriod
|
||||
Name = "小白领",
|
||||
Enable = true,
|
||||
Sections = new List<TimePeriodWeekDaySection>()
|
||||
{
|
||||
Start = TimeOnly.Parse("08:00:00"),
|
||||
End = TimeOnly.Parse("17:30:00"),
|
||||
},
|
||||
Weeks = new List<DayOfWeek>
|
||||
{
|
||||
DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday
|
||||
},
|
||||
new TimePeriodWeekDaySection()
|
||||
{
|
||||
DayOfWeek= DayOfWeek.Monday,
|
||||
TimePeriods = new List<TimePeriod>()
|
||||
{
|
||||
new TimePeriod
|
||||
{
|
||||
Start = TimeOnly.Parse("08:00:00"),
|
||||
End = TimeOnly.Parse("17:30:00"),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
@@ -205,16 +237,30 @@ public class AssignmentService : IAssignmentService
|
||||
{
|
||||
new ScheduleDto
|
||||
{
|
||||
Name = "国庆节",
|
||||
Name = "国庆节",
|
||||
DateTimePeriod = new DateTimePeriod
|
||||
{
|
||||
Start = new DateTime(2024,10,1), End = new DateTime(2024,10,7)
|
||||
Start = new DateTime(2024,10,1),
|
||||
End = new DateTime(2024,10,7)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceTaskEnumType.UploadRecord:
|
||||
{
|
||||
dto.Info = new UploadRecordToDeviceResponse
|
||||
{
|
||||
DateTimePeriod = new DateTimePeriod
|
||||
{
|
||||
Start = deviceUploadInfos[d] ?? DateTime.Now,
|
||||
End = DateTime.Now.AddDays(1)
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user