61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
|
|
using Dlhis.ScheduledTask.SyncSapInfo.Services;
|
|
using Kurisu.Scheduled;
|
|
using Kurisu.Scheduled.Attributes;
|
|
|
|
namespace Dlhis.ScheduledTask.Jobs;
|
|
|
|
/// <summary>
|
|
/// SAP岗位信息同步
|
|
/// </summary>
|
|
[RecurringJob(nameof(SyncPositionJob), "0 0 0 * * ?", Name = "SAP岗位信息同步", Queue = "SAP")]
|
|
public class SyncPositionJob : BaseJob
|
|
{
|
|
private readonly IJinkoSapService _jinkoSapService;
|
|
|
|
public SyncPositionJob(IServiceProvider serviceProvider, IJinkoSapService jinkoSapService) : base(serviceProvider)
|
|
{
|
|
_jinkoSapService = jinkoSapService;
|
|
}
|
|
|
|
public override async Task RunAsync(IServiceProvider serviceProvider)
|
|
{
|
|
var positionResult = await _jinkoSapService.GetPositionsAsync();
|
|
|
|
if (positionResult.Position != null && positionResult.Position.Items.Count > 0)
|
|
{
|
|
Logger.LogWarning("SAP岗位数量:{count}", positionResult.Position.Items.Count);
|
|
await SaveOrg(positionResult.Position.Items);
|
|
}
|
|
}
|
|
|
|
private async Task SaveOrg(List<SapPositionItem> modifiedPostList)
|
|
{
|
|
foreach (var item in modifiedPostList)
|
|
{
|
|
var position = await DbContext.Queryable<PositionEntity>().Where(x => x.No == item.ZJOBID).FirstAsync();
|
|
if (position == null)
|
|
{
|
|
position = new PositionEntity
|
|
{
|
|
No = item.ZJOBID,
|
|
Name = item.ZJOBNAME,
|
|
DepartmentNo = item.ZDEPID,
|
|
Grade = item.ZZWID
|
|
};
|
|
|
|
await DbContext.InsertAsync(position);
|
|
}
|
|
else
|
|
{
|
|
position.Name = item.ZJOBNAME;
|
|
position.DepartmentNo = item.ZDEPID;
|
|
position.Grade = item.ZZWID;
|
|
|
|
await DbContext.UpdateAsync(position);
|
|
}
|
|
}
|
|
}
|
|
}
|