72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using Dlhis.Basic.Api;
|
|
using Dlhis.Jip.Api;
|
|
using Dlhis.Jip.Api.Request;
|
|
using Dlhis.Jip.Api.Requests;
|
|
using Hangfire;
|
|
using Kurisu.AspNetCore.Utils;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Dlhis.ScheduledTask.TaskAssignment.Controllers;
|
|
|
|
/// <summary>
|
|
/// 调度任务
|
|
/// </summary>
|
|
[AllowAnonymous]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class HangfireController : ControllerBase
|
|
{
|
|
private readonly RedisCache _redisCache;
|
|
private readonly IJinkoJipApi _jinkoJipApi;
|
|
|
|
public HangfireController(RedisCache redisCache, IJinkoJipApi jinkoJipApi)
|
|
{
|
|
_redisCache = redisCache;
|
|
_jinkoJipApi = jinkoJipApi;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手动获取人员
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("sap/person/no")]
|
|
public async Task PersonManuallySync(SapNoRequest request)
|
|
{
|
|
var jobKey = $"hangfire:background:person:{request.Code}";
|
|
await using var handler = await _redisCache.LockAsync(jobKey);
|
|
if (handler.Acquired)
|
|
{
|
|
BackgroundJob.Enqueue<ISyncApi>(x => x.SyncGainfoByUserCodeAsync(request.Code));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手动启动人事范围同步
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("sap/werk/no")]
|
|
public async Task WerkManuallySync(SapNoRequest request)
|
|
{
|
|
var jobKey = $"hangfire:background:werk:{request.Code}";
|
|
await using var handler = await _redisCache.LockAsync(jobKey);
|
|
if (handler.Acquired)
|
|
{
|
|
BackgroundJob.Enqueue<ISyncApi>(x => x.SyncGainfoByWerkAsync(request.Code));
|
|
}
|
|
}
|
|
|
|
[HttpPost("test")]
|
|
public async Task<object> TestAsync()
|
|
{
|
|
return await _jinkoJipApi.SyncMealSupplementRecordsAsync(new List<SyncMealSupplementRecordRequest>()
|
|
{
|
|
new()
|
|
{
|
|
UniqueId = "Dl-Test01", Msg = "成功", Status = "SUCCESS"
|
|
}
|
|
});
|
|
}
|
|
} |