fix 调整为同步处理
This commit is contained in:
@@ -30,27 +30,27 @@ public class SyncPersonJob
|
||||
_logger.LogInformation("获取SAP人员数量为:{count}", persons.Count);
|
||||
if (persons.Count > 0)
|
||||
{
|
||||
await Scoped.Temp.Value.CreateAsync(async sp =>
|
||||
Scoped.Temp.Value.Create(sp =>
|
||||
{
|
||||
var dbContext = sp.GetService<IDbContext>();
|
||||
_positions = await dbContext.Queryable<PositionEntity>().ToListAsync();
|
||||
var modifiedPersons = await GetModifiedPersonAsync(dbContext, persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList());
|
||||
_positions = dbContext.Queryable<PositionEntity>().ToList();
|
||||
var modifiedPersons = GetModifiedPerson(dbContext, persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList());
|
||||
_logger.LogInformation("SAP人员差异数量为:{count}", modifiedPersons.Count);
|
||||
if (modifiedPersons.Count > 0)
|
||||
{
|
||||
var failedRecords = await SavePerson(modifiedPersons);
|
||||
var failedRecords = SavePerson(modifiedPersons);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<int> SavePerson(List<SapPersonItem> persons)
|
||||
private int SavePerson(List<SapPersonItem> persons)
|
||||
{
|
||||
var failure = 0;
|
||||
var workCodes = persons.Select(x => x.ZWORKCODE).ToList();
|
||||
var chunks = workCodes.Chunk(4000).ToList();
|
||||
|
||||
await Scoped.Temp.Value.CreateAsync(async sp =>
|
||||
Scoped.Temp.Value.Create(sp =>
|
||||
{
|
||||
var dbContext = sp.GetService<IDbContext>();
|
||||
|
||||
@@ -58,10 +58,10 @@ public class SyncPersonJob
|
||||
{
|
||||
_logger.LogInformation("SAP分批处理Chunk数量:{count}", searchCodes.Count());
|
||||
|
||||
var existsWorkCodes = await dbContext.Queryable<GainfoSapEntity>()
|
||||
.Where(x => searchCodes.Contains(x.ename))
|
||||
.Select(x => x.ename)
|
||||
.ToListAsync();
|
||||
var existsWorkCodes = dbContext.Queryable<GainfoSapEntity>()
|
||||
.Where(x => searchCodes.Contains(x.ename))
|
||||
.Select(x => x.ename)
|
||||
.ToList();
|
||||
|
||||
var originUpdates = persons.Where(x => existsWorkCodes.Contains(x.ZWORKCODE)).ToList();
|
||||
var existsUpdateWorkCodes = originUpdates.Select(x => x.ZWORKCODE).ToList();
|
||||
@@ -80,7 +80,7 @@ public class SyncPersonJob
|
||||
i++;
|
||||
try
|
||||
{
|
||||
await InsertPerson(dbContext, item);
|
||||
InsertPerson(dbContext, item);
|
||||
_logger.LogInformation("执行新增成功 工号:{code},姓名:{name}", item.ename, item.gname);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -96,7 +96,7 @@ public class SyncPersonJob
|
||||
i++;
|
||||
try
|
||||
{
|
||||
await UpdatePerson(dbContext, item);
|
||||
UpdatePerson(dbContext, item);
|
||||
_logger.LogInformation("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -112,7 +112,7 @@ public class SyncPersonJob
|
||||
return 0;
|
||||
}
|
||||
|
||||
private async Task InsertPerson(IDbContext db, GainfoSapEntity item)
|
||||
private void InsertPerson(IDbContext db, GainfoSapEntity item)
|
||||
{
|
||||
var info = new GainfoEntity
|
||||
{
|
||||
@@ -141,12 +141,12 @@ public class SyncPersonJob
|
||||
Employed = item.isowner,
|
||||
};
|
||||
|
||||
await db.InsertAsync(info);
|
||||
db.Client.Insertable(info).ExecuteCommand();
|
||||
}
|
||||
private async Task UpdatePerson(IDbContext db, GainfoSapEntity item)
|
||||
private void UpdatePerson(IDbContext db, GainfoSapEntity item)
|
||||
{
|
||||
var gainfo = await db.Queryable<GainfoEntity>().Where(x => x.IdNo == item.idno).FirstAsync();
|
||||
await db.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||
var gainfo = db.Queryable<GainfoEntity>().Where(x => x.IdNo == item.idno).First();
|
||||
db.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||
{
|
||||
SapNo = item.PERNR,
|
||||
Name = item.gname,
|
||||
@@ -160,12 +160,12 @@ public class SyncPersonJob
|
||||
Werks = item.WERKS
|
||||
})
|
||||
.Where(x => x.Code == item.ename)
|
||||
.ExecuteCommandAsync();
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
private async Task<List<SapPersonItem>> GetModifiedPersonAsync(IDbContext db, List<SapPersonItem> sapList)
|
||||
private List<SapPersonItem> GetModifiedPerson(IDbContext db, List<SapPersonItem> sapList)
|
||||
{
|
||||
var last = await LoadDataAsync(db);
|
||||
var last = LoadData(db);
|
||||
if (last.Count <= 0)
|
||||
{
|
||||
return sapList;
|
||||
@@ -176,9 +176,9 @@ public class SyncPersonJob
|
||||
}
|
||||
|
||||
|
||||
private async Task<List<SapPersonItem>> LoadDataAsync(IDbContext db)
|
||||
private List<SapPersonItem> LoadData(IDbContext db)
|
||||
{
|
||||
var gainfo = await db.Queryable<GainfoSapEntity>().ToListAsync();
|
||||
var gainfo = db.Queryable<GainfoSapEntity>().ToList();
|
||||
|
||||
return gainfo.Select(x => new SapPersonItem
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user