fix 调整代码位置处理
This commit is contained in:
@@ -295,9 +295,9 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
foreach (var userNo in userNos)
|
||||
{
|
||||
before.TryGetValue(userNo, out var beforeTenantDeviceCodes);
|
||||
beforeTenantDeviceCodes ??= new();
|
||||
beforeTenantDeviceCodes ??= new List<UserTenantDeviceCodeDto>();
|
||||
current.TryGetValue(userNo, out var currentTenantDeviceCodes);
|
||||
currentTenantDeviceCodes ??= new();
|
||||
currentTenantDeviceCodes ??= new List<UserTenantDeviceCodeDto>();
|
||||
|
||||
var tenants = new HashSet<string>();
|
||||
foreach (var item in beforeTenantDeviceCodes)
|
||||
@@ -307,8 +307,8 @@ public class DevicePermissionService : IDevicePermissionService
|
||||
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
|
||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new();
|
||||
var currentCodes = currentTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new List<Guid>();
|
||||
var beforeCodes = beforeTenantDeviceCodes.FirstOrDefault(x => x.Tenant == tenant)?.Codes ?? new List<Guid>();
|
||||
|
||||
//被删除
|
||||
var deletedItems = beforeCodes.Where(x => !currentCodes.Contains(x)).ToList();
|
||||
|
||||
@@ -52,25 +52,6 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
|
||||
try
|
||||
{
|
||||
//var pJson = "{\"KOSTL\":\"156020336\",\"ZLZRQ\":\"2023-10-30T00:00:00\",\"ZZ_SFZH\":\"\\\"140105200112051318\n\",\"STELL\":null,\"STELL_NM\":null,\"ZZ_KLX\":\"3\",\"PERNR\":\"00281800\",\"ZWORKCODE\":\"098250\",\"MASSN\":\"ZD\",\"MNTXT\":\"离职\",\"MASSG\":\"41\",\"MGTXT\":\"自离【失效】\",\"ZSTATUS\":\"5\",\"STAT2\":\"0\",\"BEGDA\":\"2023-10-30\",\"ENDDA\":\"9999-12-31\",\"WERKS\":\"1560\",\"PERSG\":\"2\",\"PERSK\":\"30\",\"BTRTL\":\"1560\",\"ANSVH\":\"4\",\"MOABW\":\"29\",\"ORGEH\":\"00210591\",\"PLANS\":\"99999999\",\"ZZ_ZYSF\":\"2\",\"ZZ_AQJB\":\"10\",\"ZZ_ZD\":\"3\",\"ZZ_SJGH\":\"30042938\",\"ZZ_BGZT\":\"2000\",\"Z_ZJ\":\"T0\",\"ZZ_XSQY\":null,\"ZZ_LOC\":\"海宁尖山\",\"ZZ_COUN\":\"中国\",\"ZZ_CITY\":\"海宁\",\"NACHN\":\"岳\",\"VORNA\":\"文超\",\"NAME\":\"岳文超\",\"GESCH\":\"1\",\"GBDAT\":\"2001-12-05T00:00:00\",\"NATIO\":\"CN\",\"ZZ_QFRQ\":\"2019-04-11\",\"ZMOBILE\":\"13773151205\",\"ZEMAIL\":\"wenchao.yue@jinkosolar.com\",\"ZADZH\":null,\"ZRZRQ\":\"2023-05-05T00:00:00\",\"DAT01\":\"2023-05-05\",\"ZCJRQ\":\"2023-05-05\",\"ZZZRQ\":\"2023-08-04\",\"ZXUELI\":\"高中/中专【失效】\",\"ZZ_ZPQD\":\"8\",\"ZZ_COUNNM\":null,\"ZZ_GZDJDNM\":\"海宁基地\",\"ZZ_GZDCQNM\":\"海宁尖山\"}";
|
||||
//var personResp = new SapPersonResponse
|
||||
//{
|
||||
// Person = new SapPerson<SapPersonItem>
|
||||
// {
|
||||
// Items = new List<SapPersonItem>
|
||||
// {
|
||||
// pJson.ToObject<SapPersonItem>()
|
||||
// }
|
||||
// },
|
||||
// DepartmentInfo = new SapPerson<SapPersonDepartmentStatus>()
|
||||
// {
|
||||
// Items = new List<SapPersonDepartmentStatus>()
|
||||
// },
|
||||
// JobStatusInfo = new SapPerson<SapPersonJobStatus>()
|
||||
// {
|
||||
// Items = new List<SapPersonJobStatus>()
|
||||
// }
|
||||
//};
|
||||
var personResp = await _jinkoSapService.GetPersonsByWerkAsync(werk);
|
||||
var persons = personResp.Person.Items;
|
||||
|
||||
@@ -88,10 +69,6 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
|
||||
if (modifiedPersons.Count > 0)
|
||||
{
|
||||
// var d = modifiedPersons.First();
|
||||
// _logger.LogInformation("差异信息:{json}", d.ToJson());
|
||||
// _logger.LogInformation("差异信息:{json}", (await _dbContext.Queryable<GainfoSapEntity>().Where(x => x.ename == d.ZWORKCODE).FirstAsync())?.ToJson());
|
||||
|
||||
await SavePersonAsync(modifiedPersons);
|
||||
}
|
||||
}
|
||||
@@ -155,16 +132,13 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
var originInserts = persons.Where(x => searchCodes.Contains(x.ZWORKCODE)).Where(x => !existsUpdateWorkCodes.Contains(x.ZWORKCODE)).ToList();
|
||||
|
||||
var updates = ToGainfoSap(originUpdates);
|
||||
// _logger.LogWarning("SAP分批更新数:{count}", updates.Count);
|
||||
var inserts = ToGainfoSap(originInserts);
|
||||
//_logger.LogWarning("SAP分批新增数:{count}", inserts.Count);
|
||||
|
||||
foreach (var item in inserts)
|
||||
{
|
||||
try
|
||||
{
|
||||
var no = await InsertPersonAsync(item);
|
||||
//_logger.LogWarning("执行新增成功 工号:{code},姓名:{name}", item.ename, item.gname);
|
||||
await InsertPersonAsync(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -177,27 +151,13 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
try
|
||||
{
|
||||
var no = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.ename).Select(x => x.No).SingleAsync();
|
||||
if (no.IsPresent())
|
||||
if (no.IsEmpty())
|
||||
{
|
||||
var dtoResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List<string> { no });
|
||||
var dto = dtoResult.Data;
|
||||
|
||||
var gainfoNo = await UpdatePersonAsync(item);
|
||||
//_logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname);
|
||||
|
||||
if (gainfoNo.IsPresent())
|
||||
{
|
||||
await _devicePermissionApi.RePermissionUsersInfoAsync(dto);
|
||||
}
|
||||
await InsertPersonAsync(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
no = await UpdatePersonAsync(item);
|
||||
//_logger.LogWarning("执行更新成功 工号:{code},姓名:{name}", item.ename, item.gname);
|
||||
await _gainfoPermissionApi.ResetAsync(new GainfoPermissionResetRequest
|
||||
{
|
||||
UserNo = no
|
||||
});
|
||||
await UpdatePersonAsync(item);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -208,10 +168,9 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> InsertPersonAsync(GainfoSapEntity item)
|
||||
private async Task InsertPersonAsync(GainfoSapEntity item)
|
||||
{
|
||||
await _dbContext.InsertAsync(item);
|
||||
|
||||
var info = GainfoSapToGainfo(item);
|
||||
|
||||
if (item.isowner == "T")
|
||||
@@ -226,16 +185,14 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
[info.No] = new()
|
||||
}
|
||||
});
|
||||
|
||||
return info.No;
|
||||
}
|
||||
|
||||
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
|
||||
else
|
||||
{
|
||||
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
|
||||
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
|
||||
{
|
||||
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private GainfoEntity GainfoSapToGainfo(GainfoSapEntity item)
|
||||
@@ -274,8 +231,9 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
return info;
|
||||
}
|
||||
|
||||
private async Task<string> UpdatePersonAsync(GainfoSapEntity item)
|
||||
private async Task UpdatePersonAsync(GainfoSapEntity item)
|
||||
{
|
||||
var info = GainfoSapToGainfo(item);
|
||||
await _dbContext.Updateable<GainfoSapEntity>().SetColumns(g => new GainfoSapEntity
|
||||
{
|
||||
PERNR = item.PERNR,
|
||||
@@ -302,13 +260,18 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
}).Where(x => x.ename == item.ename).ExecuteCommandAsync();
|
||||
|
||||
//获取当前在职人员
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == item.ename).FirstAsync();
|
||||
if (item.isowner == "T")
|
||||
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)
|
||||
{
|
||||
if (gainfo != null)
|
||||
if (item.isowner == "T")
|
||||
{
|
||||
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;
|
||||
var dtoResult = await _devicePermissionApi.GetPermissionUsersInfoAsync(new List<string> { gainfo.No });
|
||||
var dto = dtoResult.Data;
|
||||
|
||||
await _dbContext.Updateable<GainfoEntity>().SetColumns(g => new GainfoEntity
|
||||
{
|
||||
InternalNo = item.PERNR,
|
||||
@@ -328,19 +291,12 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
Factory = factory,
|
||||
CardType = SafeParseCardType(item.ZZ_KLX)
|
||||
}).Where(x => x.Code == item.ename).ExecuteCommandAsync();
|
||||
|
||||
await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory);
|
||||
|
||||
await _devicePermissionApi.RePermissionUsersInfoAsync(dto);
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = GainfoSapToGainfo(item);
|
||||
await _dbContext.InsertAsync(info);
|
||||
await _identityUserSyncService.SyncAccountAsync(info.Code, info.Name, info.IdNo, info.Factory);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//离职
|
||||
if (gainfo != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -368,17 +324,22 @@ 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
|
||||
{
|
||||
var info = GainfoSapToGainfo(item);
|
||||
if (!await _dbContext.Queryable<GainfoLeaveEntity>().AnyAsync(x => x.Code == item.ename))
|
||||
{
|
||||
await _dbContext.Client.Insertable(info).AS("GainfoLeave").ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
await _dbContext.Updateable<GainfoLeaveEntity>().SetColumns(g => new GainfoLeaveEntity
|
||||
{
|
||||
InternalNo = item.PERNR,
|
||||
@@ -401,8 +362,6 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item.isowner == "T" ? gainfo?.No : null;
|
||||
}
|
||||
|
||||
private async Task<List<SapPersonItem>> GetModifiedPersonAsync(List<SapPersonItem> sapList)
|
||||
|
||||
Reference in New Issue
Block a user