fix 人员同步调整
This commit is contained in:
@@ -17,7 +17,7 @@ public class SapPositionComparer : IEqualityComparer<SapPositionItem>
|
|||||||
&& x.ENDDA == y.ENDDA
|
&& x.ENDDA == y.ENDDA
|
||||||
&& x.LANGU == y.LANGU
|
&& x.LANGU == y.LANGU
|
||||||
&& x.ZJOBID == y.ZJOBID
|
&& x.ZJOBID == y.ZJOBID
|
||||||
&& x.ZJOBANME == y.ZJOBANME
|
&& x.ZJOBNAME == y.ZJOBNAME
|
||||||
&& x.ZZWID == y.ZZWID
|
&& x.ZZWID == y.ZZWID
|
||||||
&& x.ZDEPID == y.ZDEPID;
|
&& x.ZDEPID == y.ZDEPID;
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ public class SapPositionComparer : IEqualityComparer<SapPositionItem>
|
|||||||
{
|
{
|
||||||
return obj.BEGDA.SafeGetHashCode() ^ obj.ENDDA.SafeGetHashCode()
|
return obj.BEGDA.SafeGetHashCode() ^ obj.ENDDA.SafeGetHashCode()
|
||||||
^ obj.LANGU.SafeGetHashCode() ^ obj.ZJOBID.SafeGetHashCode()
|
^ obj.LANGU.SafeGetHashCode() ^ obj.ZJOBID.SafeGetHashCode()
|
||||||
^ obj.ZJOBANME.SafeGetHashCode() ^ obj.ZZWID.SafeGetHashCode()
|
^ obj.ZJOBNAME.SafeGetHashCode() ^ obj.ZZWID.SafeGetHashCode()
|
||||||
^ obj.ZDEPID.SafeGetHashCode();
|
^ obj.ZDEPID.SafeGetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ public class SyncPersonJob
|
|||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IJinkoSapService _jinkoSapService;
|
private readonly IJinkoSapService _jinkoSapService;
|
||||||
|
private List<PositionEntity> _positions;
|
||||||
|
|
||||||
public SyncPersonJob(IDbContext dbContext, ILogger logger, IJinkoSapService jinkoSapService)
|
public SyncPersonJob(IDbContext dbContext, ILogger<SyncPersonJob> logger, IJinkoSapService jinkoSapService)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@@ -29,6 +30,7 @@ public class SyncPersonJob
|
|||||||
|
|
||||||
if (persons.Count > 0)
|
if (persons.Count > 0)
|
||||||
{
|
{
|
||||||
|
_positions = await _dbContext.Queryable<PositionEntity>().ToListAsync();
|
||||||
var modifiedPersons = await GetModifiedPersonAsync(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList());
|
var modifiedPersons = await GetModifiedPersonAsync(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList());
|
||||||
if (modifiedPersons.Count > 0)
|
if (modifiedPersons.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -39,173 +41,110 @@ public class SyncPersonJob
|
|||||||
|
|
||||||
private async Task<int> SavePerson(List<SapPersonItem> persons)
|
private async Task<int> SavePerson(List<SapPersonItem> persons)
|
||||||
{
|
{
|
||||||
|
var failure = 0;
|
||||||
var workCodes = persons.Select(x => x.ZWORKCODE).ToList();
|
var workCodes = persons.Select(x => x.ZWORKCODE).ToList();
|
||||||
|
|
||||||
var index = 1;
|
foreach (var searchCodes in workCodes.Chunk(4000))
|
||||||
var count = 4000;
|
|
||||||
var failure = 0;
|
|
||||||
var total = persons.Count;
|
|
||||||
|
|
||||||
var searchCodes = workCodes.Skip((index - 1) * count).Take(count).ToList();
|
|
||||||
while (searchCodes.Count > 0)
|
|
||||||
{
|
{
|
||||||
var existsWorkCodes = _dbContext.Queryable<GainfoEntity>()
|
var existsWorkCodes = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.Where(x => searchCodes.Contains(x.Code))
|
.Where(x => searchCodes.Contains(x.Code))
|
||||||
.Select(x => x.Code)
|
.Select(x => x.Code)
|
||||||
.ToList();
|
.ToListAsync();
|
||||||
|
|
||||||
var originUpdates = persons.Where(x => existsWorkCodes.Contains(x.ZWORKCODE)).ToList();
|
var originUpdates = persons.Where(x => existsWorkCodes.Contains(x.ZWORKCODE)).ToList();
|
||||||
var originInserts = persons.Where(x => searchCodes.Contains(x.ZWORKCODE)).Except(originUpdates, new SapPersonComparer()).ToList();
|
var originInserts = persons.Where(x => searchCodes.Contains(x.ZWORKCODE)).Except(originUpdates, new SapPersonComparer()).ToList();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (originUpdates.Count + originInserts.Count <= count)
|
var currentTotal = originUpdates.Count + originInserts.Count;
|
||||||
|
|
||||||
|
var updates = ToGainfoSap(originUpdates);
|
||||||
|
var inserts = ToGainfoSap(originInserts);
|
||||||
|
|
||||||
|
foreach (var item in inserts)
|
||||||
{
|
{
|
||||||
var currentTotal = originUpdates.Count + originInserts.Count;
|
i++;
|
||||||
|
try
|
||||||
var updates = ToGainfoSap(originUpdates);
|
|
||||||
var inserts = ToGainfoSap(originInserts);
|
|
||||||
|
|
||||||
foreach (var item in inserts)
|
|
||||||
{
|
{
|
||||||
i++;
|
await SavePerson(item);
|
||||||
try
|
//conn.Execute(SqlGeneration.InsertSql, item);
|
||||||
{
|
//log.Debug($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
||||||
await SavePerson(item);
|
}
|
||||||
//conn.Execute(SqlGeneration.InsertSql, item);
|
catch (Exception ex)
|
||||||
//log.Debug($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
{
|
||||||
}
|
failure++;
|
||||||
catch (Exception ex)
|
//log.Error($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
||||||
{
|
|
||||||
failure++;
|
|
||||||
//log.Error($"执行新增{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var item in updates)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await UpdatePerson(item);
|
|
||||||
//conn.Execute(SqlGeneration.UpdateSql, item);
|
|
||||||
//log.Debug($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
failure++;
|
|
||||||
//log.Error($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
foreach (var item in updates)
|
||||||
persons = persons.Except(originUpdates).Except(originUpdates).ToList();
|
{
|
||||||
searchCodes = workCodes.Skip((index - 1) * count).Take(count).ToList();
|
i++;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await UpdatePerson(item);
|
||||||
|
//conn.Execute(SqlGeneration.UpdateSql, item);
|
||||||
|
//log.Debug($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
failure++;
|
||||||
|
//log.Error($"执行更新{i}/{currentTotal} name:{item.gname},ename:{item.ename}失败 \r\n{ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return failure;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SavePerson(GainfoSapEntity item)
|
private async Task SavePerson(GainfoSapEntity item)
|
||||||
{
|
{
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.idno).FirstAsync();
|
var info = new GainfoEntity
|
||||||
if (gainfo != null)
|
|
||||||
{
|
{
|
||||||
gainfo.No = item.guestno;
|
No = item.guestno,
|
||||||
gainfo.SapNo = item.ano;
|
SapNo = item.ano,
|
||||||
gainfo.Type = item.@class;
|
Type = item.@class,
|
||||||
gainfo.Name = item.gname;
|
Name = item.gname,
|
||||||
gainfo.Code = item.ename;
|
Code = item.ename,
|
||||||
gainfo.CountryNo = item.country;
|
CountryNo = item.country,
|
||||||
gainfo.IdClass = item.idcls;
|
IdClass = item.idcls,
|
||||||
gainfo.Native = item.native;
|
IdNo = item.idno,
|
||||||
gainfo.Gender = item.sex == "F" ? GenderEnumType.Female : GenderEnumType.Male;
|
Native = item.native,
|
||||||
gainfo.Birthday = (DateTime)item.birthday;
|
Gender = item.sex == "F" ? GenderEnumType.Female : GenderEnumType.Male,
|
||||||
gainfo.Address = item.address;
|
Birthday = (DateTime)item.birthday,
|
||||||
gainfo.DepartmentNo = item.appellation;
|
Address = item.address,
|
||||||
gainfo.Nation = item.nation;
|
//Marital 已婚未婚
|
||||||
gainfo.Phone = item.phone;
|
//Occuption = item.occuption,
|
||||||
gainfo.Degree = item.email;
|
DepartmentNo = item.appellation,
|
||||||
gainfo.Position = item.web;
|
Nation = item.nation,
|
||||||
gainfo.Remark = item.remark;
|
Phone = item.phone,
|
||||||
gainfo.Werks = item.WERKS;
|
Degree = item.email,
|
||||||
gainfo.Employed = item.isowner; //int.Parse(person.ZSTATUS) < 4 ? "T" : "F", 是否离职
|
Position = item.web,
|
||||||
await _dbContext.UpdateAsync(gainfo);
|
//CarNo
|
||||||
}
|
Remark = item.remark,
|
||||||
else
|
Werks = item.WERKS,
|
||||||
{
|
Employed = item.isowner,
|
||||||
var info = new GainfoEntity
|
};
|
||||||
{
|
await _dbContext.InsertAsync(info);
|
||||||
No = item.guestno,
|
|
||||||
SapNo = item.ano,
|
|
||||||
Type = item.@class,
|
|
||||||
Name = item.gname,
|
|
||||||
Code = item.ename,
|
|
||||||
CountryNo = item.country,
|
|
||||||
IdClass = item.idcls,
|
|
||||||
IdNo = item.idno,
|
|
||||||
Native = item.native,
|
|
||||||
Gender = item.sex == "F" ? GenderEnumType.Female : GenderEnumType.Male,
|
|
||||||
Birthday = (DateTime)item.birthday,
|
|
||||||
Address = item.address,
|
|
||||||
//Marital 已婚未婚
|
|
||||||
//Occuption = item.occuption,
|
|
||||||
DepartmentNo = item.appellation,
|
|
||||||
Nation = item.nation,
|
|
||||||
Phone = item.phone,
|
|
||||||
Degree = item.email,
|
|
||||||
Position = item.web,
|
|
||||||
//CarNo
|
|
||||||
Remark = item.remark,
|
|
||||||
Werks = item.WERKS,
|
|
||||||
Employed = item.isowner,
|
|
||||||
};
|
|
||||||
await _dbContext.InsertAsync(info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private async Task UpdatePerson(GainfoSapEntity item)
|
private async Task UpdatePerson(GainfoSapEntity item)
|
||||||
{
|
{
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.idno).FirstAsync();
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.idno).FirstAsync();
|
||||||
if (gainfo != null)
|
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||||
{
|
{
|
||||||
_dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
SapNo = item.PERNR,
|
||||||
{
|
Name = item.gname,
|
||||||
SapNo = item.PERNR,
|
Code = item.ename,
|
||||||
Name = item.gname,
|
Position = item.web,
|
||||||
Code = item.ename,
|
Phone = item.phone,
|
||||||
Position = item.web,
|
DepartmentNo = item.appellation,
|
||||||
Phone = item.phone,
|
Employed = item.isowner,
|
||||||
DepartmentNo = item.appellation,
|
Remark = item.remark,
|
||||||
Employed = item.isowner,
|
Degree = item.email,
|
||||||
Remark = item.remark,
|
Werks = item.WERKS
|
||||||
Degree = item.email,
|
})
|
||||||
Werks = item.WERKS
|
.Where(x => x.Code == item.ename)
|
||||||
})
|
.ExecuteCommandAsync();
|
||||||
.Where(g => g.IdNo == item.idno
|
|
||||||
&& !_dbContext.Queryable<GainfoEntity>().Any(g => g.IdNo == item.idno && g.SapNo != item.PERNR && g.Employed == "T")
|
|
||||||
&& !_dbContext.Queryable<GainfoEntity>().Any(g => g.IdNo == item.idno && int.Parse(g.SapNo) > int.Parse(item.PERNR) && g.Employed == item.isowner));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
|
||||||
{
|
|
||||||
SapNo = item.PERNR,
|
|
||||||
Name = item.gname,
|
|
||||||
Code = item.ename,
|
|
||||||
Position = item.web,
|
|
||||||
Phone = item.phone,
|
|
||||||
DepartmentNo = item.appellation,
|
|
||||||
Employed = item.isowner,
|
|
||||||
Remark = item.remark,
|
|
||||||
Degree = item.email,
|
|
||||||
Werks = item.WERKS
|
|
||||||
})
|
|
||||||
.Where(g => g.SapNo == item.PERNR
|
|
||||||
&& !_dbContext.Queryable<GainfoEntity>().Any(g => g.Code == item.ename && g.Employed == "T")
|
|
||||||
&& !_dbContext.Queryable<GainfoEntity>().Any(g => g.IdNo == item.idno && int.Parse(g.SapNo) > int.Parse(item.PERNR) && g.Employed == item.isowner));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<SapPersonItem>> GetModifiedPersonAsync(List<SapPersonItem> sapList)
|
private async Task<List<SapPersonItem>> GetModifiedPersonAsync(List<SapPersonItem> sapList)
|
||||||
@@ -259,7 +198,7 @@ public class SyncPersonJob
|
|||||||
GainfoSapEntity o = null;
|
GainfoSapEntity o = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var position = string.Empty; //lastUpdatedPositionList.FirstOrDefault(x => x.ZJOBID == person.PLANS);
|
var position = _positions.FirstOrDefault(x => x.No == person.PLANS);
|
||||||
|
|
||||||
var rzrq = SafeParseDate(person.ZRZRQ);
|
var rzrq = SafeParseDate(person.ZRZRQ);
|
||||||
var lzrq = SafeParseDate(person.ZLZRQ);
|
var lzrq = SafeParseDate(person.ZLZRQ);
|
||||||
@@ -302,7 +241,7 @@ public class SyncPersonJob
|
|||||||
remark = rmk,
|
remark = rmk,
|
||||||
native = native,
|
native = native,
|
||||||
sex = sex,
|
sex = sex,
|
||||||
//web = SubString(position?.ZJOBANME, 30), todo
|
web = SubString(position?.Name ?? "", 30),
|
||||||
logdate = DateTime.Now,
|
logdate = DateTime.Now,
|
||||||
isowner = int.Parse(person.ZSTATUS) < 4 ? "T" : "F",
|
isowner = int.Parse(person.ZSTATUS) < 4 ? "T" : "F",
|
||||||
@class = "C",
|
@class = "C",
|
||||||
|
|||||||
Reference in New Issue
Block a user