refactor 封装任务,调整人员获取
This commit is contained in:
74
Src/Dlhis.ScheduledTask/Jobs/SyncOriginCardInfoJob.cs
Normal file
74
Src/Dlhis.ScheduledTask/Jobs/SyncOriginCardInfoJob.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo;
|
||||
using Dlhis.ScheduledTask.SyncSapInfo.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Scheduled;
|
||||
using Kurisu.Scheduled.Attributes;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 上传考勤记录
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(SyncOriginCardInfoJob), "0/20 * * * * ?", Name = "上传考勤记录", Queue = "SAP")]
|
||||
public class SyncOriginCardInfoJob : BaseJob
|
||||
{
|
||||
private readonly IJinkoJIPService _jinkoJIPService;
|
||||
private readonly ISqlSugarOptionsService _sqlSugarOptionsService;
|
||||
|
||||
public SyncOriginCardInfoJob(IJinkoJIPService jinkoJIPService, IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
_jinkoJIPService = jinkoJIPService;
|
||||
}
|
||||
|
||||
public override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
//考勤设备(不需要Enable参数)
|
||||
var devices = await DbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Attendance || x.Type == DeviceTypeEnumType.Door && x.AsAttendance)
|
||||
.ToListAsync();
|
||||
|
||||
//获取上传日志(有效的)
|
||||
var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
var logs = await DbContext.Queryable<DeviceUploadLogEntity>()
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Where(x => !string.IsNullOrEmpty(x.UserUniqueNo))
|
||||
.Where(x => x.Sync == false)
|
||||
.ToListAsync();
|
||||
|
||||
//获取人员信息
|
||||
var userCodes = logs.Select(x => x.UserUniqueNo).ToList();
|
||||
var gainfoCodes = await DbContext.Queryable<GainfoEntity>().Where(x => userCodes.Contains(x.Code)).Select(x => x.Code).ToListAsync();
|
||||
|
||||
var requests = logs.Select(x => new UploadAttendanceRequest
|
||||
{
|
||||
Id = x.Id,
|
||||
RaiseDateTime = x.RaiseDateTime,
|
||||
ZNOTE = devices.First(item => item.UniqueNo == x.DeviceUniqueNo).DeployPlace,
|
||||
ZWORKCODE = gainfoCodes.Contains(x.UserUniqueNo) ? x.UserUniqueNo?.TrimEnd('\0') : string.Empty,
|
||||
|
||||
}).Where(x => x.ZWORKCODE.IsPresent()).ToList();
|
||||
|
||||
var ids = requests.Select(x => x.Id).ToList();
|
||||
if (ids.Any())
|
||||
{
|
||||
var r = await _jinkoJIPService.UploadAttendancesAsync(requests);
|
||||
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
|
||||
{
|
||||
throw new Exception(r.OMS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user