73 lines
2.7 KiB
C#
73 lines
2.7 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Basic.Enums;
|
|
using Dlhis.Entity.Device.Entities;
|
|
using Dlhis.Entity.Device.Enums;
|
|
using Dlhis.Jip.Api;
|
|
using Dlhis.Jip.Api.Requests;
|
|
using Dlhis.ScheduledTask.Attributes;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.ScheduledTask.Jobs;
|
|
|
|
/// <summary>
|
|
/// 上传考勤记录
|
|
/// </summary>
|
|
[RecurringJob(nameof(SyncOriginCardInfoJob), "0 0/1 * * * ?", Name = "上传考勤记录")]
|
|
public class SyncOriginCardInfoJob : BaseJob
|
|
{
|
|
private readonly IJinkoJipApi _jinkoJipApi;
|
|
|
|
public SyncOriginCardInfoJob(IJinkoJipApi jinkoJipApi, IServiceProvider serviceProvider) : base(serviceProvider)
|
|
{
|
|
_jinkoJipApi = jinkoJipApi;
|
|
}
|
|
|
|
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
|
{
|
|
var start = DateTime.Now.AddDays(-3);
|
|
|
|
var requests = await DbContext.Queryable<DeviceUploadLogEntity>()
|
|
.LeftJoin<DeviceEntity>((x, device) => x.DeviceUniqueNo == device.UniqueNo)
|
|
.Where(x => x.ModifiedTime > start)
|
|
.Where(x => x.NeedUpload && x.Sync == false && (x.UserType == GainfoUserTypeEnumType.Normal || x.UserType == GainfoUserTypeEnumType.SecurityWhite))
|
|
.OrderBy(x => x.ModifiedTime)
|
|
.Select((x, device) => new UploadAttendanceRequestItem
|
|
{
|
|
Id = x.Id,
|
|
RaiseDateTime = x.RaiseDateTime,
|
|
ZNOTE = device.DeployPlace,
|
|
ZWORKCODE = x.UserUniqueNo
|
|
})
|
|
.ToPageListAsync(1, 1000);
|
|
|
|
Logger.LogInformation("获取待上传考勤记录数:{count}", requests.Count);
|
|
|
|
if (requests.Any())
|
|
{
|
|
foreach (var items in requests.Chunk(500))
|
|
{
|
|
try
|
|
{
|
|
var ids = items.Select(x => x.Id).ToList();
|
|
var r = await _jinkoJipApi.UploadAttendancesAsync(new UploadAttendanceRequest { Data = items.ToList() });
|
|
if (r.OLX == "0")
|
|
{
|
|
await DbContext.Updateable<DeviceUploadLogEntity>()
|
|
.SetColumns(x => x.Sync == true)
|
|
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
|
.Where(x => ids.Contains(x.Id))
|
|
.ExecuteCommandAsync();
|
|
}
|
|
else
|
|
{
|
|
Logger.LogError("考勤上传异常:{message}", r.OMS);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex, "考勤上传异常:{message}", ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |