fix 人事范围同步控制,餐补消费离职人员处理

This commit is contained in:
2024-04-07 14:58:29 +08:00
parent b9977df4eb
commit babf8a838b
13 changed files with 144 additions and 57 deletions

View File

@@ -1,21 +1,26 @@
using Dlhis.ScheduledTask.Common.Dto;
using Dlhis.Entity.Basic.Entity;
using Dlhis.ScheduledTask.Common.Request;
using Hangfire;
using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.SqlSugar.Services;
namespace Dlhis.ScheduledTask.Common.Services.Implements;
public class HangfireService : IHangfireService
{
private readonly RedisCache _redisCache;
private readonly IDbContext _dbContext;
public HangfireService(RedisCache redisCache)
public HangfireService(RedisCache redisCache, IDbContext dbContext)
{
_redisCache = redisCache;
_dbContext = dbContext;
}
public async Task CreateSapPersonSyncBackgroundJobAsync(SapPersonNoRequest request)
public async Task CreateSapPersonSyncBackgroundJobAsync(SapNoRequest request)
{
var jobKey = $"hangfire:background:{request.Code}";
var jobKey = $"hangfire:background:person:{request.Code}";
using var handler = await _redisCache.LockAsync(jobKey);
if (handler.Acquired)
@@ -23,4 +28,20 @@ public class HangfireService : IHangfireService
BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByCodeAsync(request.Code));
}
}
public async Task CreateSapWerkSyncBackgroundJobAsync(SapNoRequest request)
{
var jobKey = $"hangfire:background:werk:{request.Code}";
using var handler = await _redisCache.LockAsync(jobKey);
if (handler.Acquired)
{
var werkInfo = await _dbContext.Queryable<WerkEntity>().Where(x => x.Werk == request.Code).SingleAsync();
werkInfo.ThrowIfNull("人事范围不存在");
werkInfo.BackgroundJobKey.IsPresent().ThrowIfTrue("任务进行中,无法再次发起同步");
BackgroundJob.Enqueue<IGainfoUpdateService>(x => x.TodoByWerkAsync(request.Code));
}
}
}