60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.ScheduledTask.SyncSapInfo.Dto;
|
|
using Dlhis.ScheduledTask.SyncSapInfo.Services;
|
|
using Kurisu.SqlSugar.Services;
|
|
|
|
namespace Dlhis.ScheduledTask.SyncSapInfo.Job;
|
|
|
|
/// <summary>
|
|
/// 职位同步定时任务
|
|
/// </summary>
|
|
public class SyncPositionJob
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly IJinkoSapService _jinkoSapService;
|
|
|
|
public SyncPositionJob(IDbContext dbContext, IJinkoSapService jinkoSapService)
|
|
{
|
|
_dbContext = dbContext;
|
|
_jinkoSapService = jinkoSapService;
|
|
}
|
|
|
|
public async Task RunAsync()
|
|
{
|
|
var positionResult = await _jinkoSapService.GetPositionsAsync();
|
|
|
|
if (positionResult.Position != null && positionResult.Position.Items.Count > 0)
|
|
{
|
|
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.ZDEPID,
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|