fix 人员同步调整
This commit is contained in:
@@ -17,7 +17,7 @@ public class SapPositionComparer : IEqualityComparer<SapPositionItem>
|
||||
&& x.ENDDA == y.ENDDA
|
||||
&& x.LANGU == y.LANGU
|
||||
&& x.ZJOBID == y.ZJOBID
|
||||
&& x.ZJOBANME == y.ZJOBANME
|
||||
&& x.ZJOBNAME == y.ZJOBNAME
|
||||
&& x.ZZWID == y.ZZWID
|
||||
&& x.ZDEPID == y.ZDEPID;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class SapPositionComparer : IEqualityComparer<SapPositionItem>
|
||||
{
|
||||
return obj.BEGDA.SafeGetHashCode() ^ obj.ENDDA.SafeGetHashCode()
|
||||
^ obj.LANGU.SafeGetHashCode() ^ obj.ZJOBID.SafeGetHashCode()
|
||||
^ obj.ZJOBANME.SafeGetHashCode() ^ obj.ZZWID.SafeGetHashCode()
|
||||
^ obj.ZJOBNAME.SafeGetHashCode() ^ obj.ZZWID.SafeGetHashCode()
|
||||
^ obj.ZDEPID.SafeGetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@ public class SyncPersonJob
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ILogger _logger;
|
||||
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;
|
||||
_logger = logger;
|
||||
@@ -29,6 +30,7 @@ public class SyncPersonJob
|
||||
|
||||
if (persons.Count > 0)
|
||||
{
|
||||
_positions = await _dbContext.Queryable<PositionEntity>().ToListAsync();
|
||||
var modifiedPersons = await GetModifiedPersonAsync(persons.OrderByDescending(x => x.ZSTATUS).ThenBy(x => x.ZRZRQ).ToList());
|
||||
if (modifiedPersons.Count > 0)
|
||||
{
|
||||
@@ -39,28 +41,20 @@ public class SyncPersonJob
|
||||
|
||||
private async Task<int> SavePerson(List<SapPersonItem> persons)
|
||||
{
|
||||
|
||||
var failure = 0;
|
||||
var workCodes = persons.Select(x => x.ZWORKCODE).ToList();
|
||||
|
||||
var index = 1;
|
||||
var count = 4000;
|
||||
var failure = 0;
|
||||
var total = persons.Count;
|
||||
|
||||
var searchCodes = workCodes.Skip((index - 1) * count).Take(count).ToList();
|
||||
while (searchCodes.Count > 0)
|
||||
foreach (var searchCodes in workCodes.Chunk(4000))
|
||||
{
|
||||
var existsWorkCodes = _dbContext.Queryable<GainfoEntity>()
|
||||
var existsWorkCodes = await _dbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => searchCodes.Contains(x.Code))
|
||||
.Select(x => x.Code)
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
|
||||
var originUpdates = persons.Where(x => existsWorkCodes.Contains(x.ZWORKCODE)).ToList();
|
||||
var originInserts = persons.Where(x => searchCodes.Contains(x.ZWORKCODE)).Except(originUpdates, new SapPersonComparer()).ToList();
|
||||
|
||||
int i = 0;
|
||||
if (originUpdates.Count + originInserts.Count <= count)
|
||||
{
|
||||
var currentTotal = originUpdates.Count + originInserts.Count;
|
||||
|
||||
var updates = ToGainfoSap(originUpdates);
|
||||
@@ -100,41 +94,10 @@ public class SyncPersonJob
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
persons = persons.Except(originUpdates).Except(originUpdates).ToList();
|
||||
searchCodes = workCodes.Skip((index - 1) * count).Take(count).ToList();
|
||||
}
|
||||
|
||||
return failure;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private async Task SavePerson(GainfoSapEntity item)
|
||||
{
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.idno).FirstAsync();
|
||||
if (gainfo != null)
|
||||
{
|
||||
gainfo.No = item.guestno;
|
||||
gainfo.SapNo = item.ano;
|
||||
gainfo.Type = item.@class;
|
||||
gainfo.Name = item.gname;
|
||||
gainfo.Code = item.ename;
|
||||
gainfo.CountryNo = item.country;
|
||||
gainfo.IdClass = item.idcls;
|
||||
gainfo.Native = item.native;
|
||||
gainfo.Gender = item.sex == "F" ? GenderEnumType.Female : GenderEnumType.Male;
|
||||
gainfo.Birthday = (DateTime)item.birthday;
|
||||
gainfo.Address = item.address;
|
||||
gainfo.DepartmentNo = item.appellation;
|
||||
gainfo.Nation = item.nation;
|
||||
gainfo.Phone = item.phone;
|
||||
gainfo.Degree = item.email;
|
||||
gainfo.Position = item.web;
|
||||
gainfo.Remark = item.remark;
|
||||
gainfo.Werks = item.WERKS;
|
||||
gainfo.Employed = item.isowner; //int.Parse(person.ZSTATUS) < 4 ? "T" : "F", 是否离职
|
||||
await _dbContext.UpdateAsync(gainfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = new GainfoEntity
|
||||
{
|
||||
@@ -164,13 +127,10 @@ public class SyncPersonJob
|
||||
};
|
||||
await _dbContext.InsertAsync(info);
|
||||
}
|
||||
}
|
||||
private async Task UpdatePerson(GainfoSapEntity item)
|
||||
{
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.idno).FirstAsync();
|
||||
if (gainfo != null)
|
||||
{
|
||||
_dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||
{
|
||||
SapNo = item.PERNR,
|
||||
Name = item.gname,
|
||||
@@ -183,29 +143,8 @@ public class SyncPersonJob
|
||||
Degree = item.email,
|
||||
Werks = item.WERKS
|
||||
})
|
||||
.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));
|
||||
}
|
||||
.Where(x => x.Code == item.ename)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
private async Task<List<SapPersonItem>> GetModifiedPersonAsync(List<SapPersonItem> sapList)
|
||||
@@ -259,7 +198,7 @@ public class SyncPersonJob
|
||||
GainfoSapEntity o = null;
|
||||
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 lzrq = SafeParseDate(person.ZLZRQ);
|
||||
@@ -302,7 +241,7 @@ public class SyncPersonJob
|
||||
remark = rmk,
|
||||
native = native,
|
||||
sex = sex,
|
||||
//web = SubString(position?.ZJOBANME, 30), todo
|
||||
web = SubString(position?.Name ?? "", 30),
|
||||
logdate = DateTime.Now,
|
||||
isowner = int.Parse(person.ZSTATUS) < 4 ? "T" : "F",
|
||||
@class = "C",
|
||||
|
||||
Reference in New Issue
Block a user