fix 优化同步更新处理
This commit is contained in:
@@ -233,7 +233,6 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
await _dbContext.Client.Ado.BeginTranAsync();
|
||||
try
|
||||
{
|
||||
var info = GainfoSapToGainfo(item);
|
||||
await _dbContext.Updateable<GainfoSapEntity>().SetColumns(g => new GainfoSapEntity
|
||||
{
|
||||
PERNR = item.PERNR,
|
||||
@@ -261,13 +260,32 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
//获取当前在职人员
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.ename).SingleAsync();
|
||||
|
||||
var workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM;
|
||||
var factory = _tenants.LastOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM;
|
||||
|
||||
//默认人员存在
|
||||
if (gainfo != null)
|
||||
{
|
||||
var workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM;
|
||||
var factory = _tenants.LastOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM;
|
||||
|
||||
if (item.isowner == "T")
|
||||
{
|
||||
var change = string.Empty;
|
||||
|
||||
if (gainfo.Factory != factory || gainfo.Workplace != workplace || gainfo.DepartmentNo != item.appellation)
|
||||
{
|
||||
if (gainfo.Factory != factory)
|
||||
{
|
||||
change = $"{gainfo.Factory}->{factory}";
|
||||
}
|
||||
|
||||
if (gainfo.DepartmentNo != item.appellation)
|
||||
{
|
||||
change += $"{gainfo.DepartmentNo}->{item.appellation}";
|
||||
}
|
||||
|
||||
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, $"异动生成({change})");
|
||||
}
|
||||
|
||||
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||
{
|
||||
InternalNo = item.PERNR,
|
||||
@@ -288,14 +306,9 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
ModifiedTime = DateTime.Now
|
||||
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
|
||||
|
||||
if (gainfo.Factory != factory)
|
||||
if (change.IsPresent())
|
||||
{
|
||||
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
|
||||
}
|
||||
|
||||
if (gainfo.Factory != factory || gainfo.Workplace != workplace || gainfo.DepartmentNo != item.appellation)
|
||||
{
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Delete, null, "异动生成");
|
||||
await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Add, null, $"异动生成({change})");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -317,42 +330,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
|
||||
gainfo.Id = gainfo.IdentityUserId;
|
||||
await _dbContext.DeleteReallyAsync(gainfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.isowner == "T")
|
||||
{
|
||||
await _dbContext.InsertAsync(info);
|
||||
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, factory);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
|
||||
{
|
||||
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await _dbContext.Updateable<GainfoLeaveEntity>().SetColumns(g => new GainfoLeaveEntity
|
||||
{
|
||||
InternalNo = item.PERNR,
|
||||
Name = item.gname,
|
||||
PositionNo = item.STELL,
|
||||
Grade = item.ZZ_ZD,
|
||||
Title = item.Z_ZJ,
|
||||
Phone = item.phone,
|
||||
DepartmentNo = item.appellation,
|
||||
Remark = item.remark,
|
||||
Degree = item.email,
|
||||
Werks = item.WERKS,
|
||||
CostId = item.KOSTL,
|
||||
EntryDate = item.createdate,
|
||||
ResignationDate = item.ZLZRQ,
|
||||
Workplace = workplace,
|
||||
Factory = factory,
|
||||
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
|
||||
}
|
||||
await _identityUserSyncService.LockAccountAsync(gainfo.Code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +339,7 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _dbContext.Client.Ado.RollbackTranAsync();
|
||||
_logger.LogError(ex, "离职任务生成失败:{message}", ex.Message);
|
||||
_logger.LogError(ex, "更新人员失败:{message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user