fix 同步离职异常问题

This commit is contained in:
2024-06-15 12:08:51 +08:00
parent 7097f2360c
commit 24d4608f72
6 changed files with 49 additions and 121 deletions

View File

@@ -497,7 +497,9 @@ public class BalanceService : IBalanceService
public async Task HainingImportAsync(BalanceHainingImportRequest request)
{
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.UserCode).SingleAsync();
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.UserCode).SingleAsync()
?? await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => x.Code == request.UserCode).SingleAsync();
gainfo.ThrowIfNull($"工号{request.UserCode}不存在");
var gainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == request.UserCode).SingleAsync();
if (gainfoMeal == null)
@@ -558,7 +560,6 @@ public class BalanceService : IBalanceService
DeviceUniqueNo = request.DeviceUniqueNo,
IsDeleted = false,
});
var newBalance = gainfoMeal.Balance += request.Amount;

View File

@@ -1,19 +1,19 @@
namespace Dlhis.ScheduledTask.Common.Dto
{
public class SapPersonDepartmentStatus
{
public string ZWORKCODE { get; set; }
public DateTime BEGDA { get; set; }
public DateTime ENDDA { get; set; }
public string WERKS { get; set; }
/// <summary>
/// 部门号
/// </summary>
public string ORGEH { get; set; }
}
}
// namespace Dlhis.ScheduledTask.Common.Dto
// {
// public class SapPersonDepartmentStatus
// {
// public string ZWORKCODE { get; set; }
//
// public DateTime BEGDA { get; set; }
//
// public DateTime ENDDA { get; set; }
//
// public string WERKS { get; set; }
//
// /// <summary>
// /// 部门号
// /// </summary>
// public string ORGEH { get; set; }
//
// }
// }

View File

@@ -1,16 +1,16 @@
namespace Dlhis.ScheduledTask.Common.Dto
{
public class SapPersonJobStatus
{
public string ZWORKCODE { get; set; }
public DateTime BEGDA { get; set; }
public DateTime ENDDA { get; set; }
/// <summary>
/// 0离职
/// </summary>
public string STAT2 { get; set; }
}
}
// namespace Dlhis.ScheduledTask.Common.Dto
// {
// public class SapPersonJobStatus
// {
// public string ZWORKCODE { get; set; }
//
// public DateTime BEGDA { get; set; }
//
// public DateTime ENDDA { get; set; }
//
// /// <summary>
// /// 0离职
// /// </summary>
// public string STAT2 { get; set; }
// }
// }

View File

@@ -11,16 +11,16 @@ public class SapPersonResponse
[JsonProperty("T_PERSON")]
public SapPerson<SapPersonItem> Person { get; set; }
/// <summary>
/// 离职状态
/// </summary>
[JsonProperty("T_0000")]
public SapPerson<SapPersonJobStatus> JobStatusInfo { get; set; }
/// <summary>
/// 部门变更信息
/// </summary>
[JsonProperty("T_0001")]
public SapPerson<SapPersonDepartmentStatus> DepartmentInfo { get; set; }
// /// <summary>
// /// 离职状态
// /// </summary>
// [JsonProperty("T_0000")]
// public SapPerson<SapPersonJobStatus> JobStatusInfo { get; set; }
//
// /// <summary>
// /// 部门变更信息
// /// </summary>
// [JsonProperty("T_0001")]
// public SapPerson<SapPersonDepartmentStatus> DepartmentInfo { get; set; }
}

View File

@@ -22,8 +22,6 @@ public class GainfoUpdateService : IGainfoUpdateService
private readonly IJinkoSapService _jinkoSapService;
private List<TenantResponse> _tenants;
private List<SapPersonDepartmentStatus> _departmentChanges;
private List<SapPersonJobStatus> _jobChanges;
public GainfoUpdateService(IDbContext dbContext,
ILogger<GainfoUpdateService> logger,
@@ -72,8 +70,6 @@ public class GainfoUpdateService : IGainfoUpdateService
//};
var personResp = await _jinkoSapService.GetPersonsByWerkAsync(werk);
var persons = personResp.Person.Items;
_departmentChanges = personResp.DepartmentInfo.Items;
_jobChanges = personResp.JobStatusInfo.Items;
werkInfo.HandleMessage = "SAP人员数量" + persons.Count;
werkInfo.Total = persons.Count;
@@ -118,8 +114,6 @@ public class GainfoUpdateService : IGainfoUpdateService
var personResp = await _jinkoSapService.GetPersonsByCodeAsync(code);
var persons = personResp.Person.Items;
_departmentChanges = personResp.DepartmentInfo.Items;
_jobChanges = personResp.JobStatusInfo.Items;
_logger.LogInformation("获取SAP人员数量为:{count}", persons.Count);
if (persons.Count > 0)
@@ -392,33 +386,6 @@ public class GainfoUpdateService : IGainfoUpdateService
return sapList;
}
var now = DateTime.Now;
foreach (var item in sapList)
{
var a = _jobChanges.OrderByDescending(x => x.BEGDA).FirstOrDefault(x => x.ZWORKCODE == item.ZWORKCODE);
if (a != null)
{
if (a.BEGDA >= now && a.ENDDA <= now)
{
if (a.STAT2 == "0")
{
item.STAT2 = "0";
item.ZSTATUS = "5";
}
}
}
var b = _departmentChanges.OrderByDescending(x => x.BEGDA).FirstOrDefault(x => x.ZWORKCODE == item.ZWORKCODE);
if (b != null)
{
if (b.BEGDA >= now && b.ENDDA <= now)
{
item.ORGEH = b.ORGEH;
item.WERKS = b.WERKS;
}
}
}
var needRemove = sapList.Intersect(last, new SapPersonComparer()).ToList();
return sapList.Except(needRemove, new SapPersonComparer()).ToList();
}

View File

@@ -95,37 +95,17 @@ public class JinkoSapService : IJinkoSapService
var personResp = JsonConvert.DeserializeObject<SapPersonResponse>(jsonResponse);
List<SapPersonItem> persons = new();
List<SapPersonJobStatus> jobInfos = new();
List<SapPersonDepartmentStatus> departmentInfos = new();
if (personResp?.Person?.Items?.Any() == true)
{
persons.AddRange(personResp.Person.Items);
}
if (personResp?.JobStatusInfo?.Items?.Any() == true)
{
jobInfos.AddRange(personResp.JobStatusInfo.Items);
}
if (personResp?.DepartmentInfo?.Items?.Any() == true)
{
departmentInfos.AddRange(personResp.DepartmentInfo.Items);
}
return new SapPersonResponse()
{
Person = new SapPerson<SapPersonItem>
{
Items = persons
},
JobStatusInfo = new SapPerson<SapPersonJobStatus>
{
Items = jobInfos,
},
DepartmentInfo = new SapPerson<SapPersonDepartmentStatus>
{
Items = departmentInfos
}
};
}
@@ -160,37 +140,17 @@ public class JinkoSapService : IJinkoSapService
var personResp = JsonConvert.DeserializeObject<SapPersonResponse>(jsonResponse);
List<SapPersonItem> persons = new();
List<SapPersonJobStatus> jobInfos = new();
List<SapPersonDepartmentStatus> departmentInfos = new();
if (personResp?.Person?.Items?.Any() == true)
{
persons.AddRange(personResp.Person.Items);
}
if (personResp?.JobStatusInfo?.Items?.Any() == true)
{
jobInfos.AddRange(personResp.JobStatusInfo.Items);
}
if (personResp?.DepartmentInfo?.Items?.Any() == true)
{
departmentInfos.AddRange(personResp.DepartmentInfo.Items);
}
return new SapPersonResponse()
{
Person = new SapPerson<SapPersonItem>
{
Items = persons
},
JobStatusInfo = new SapPerson<SapPersonJobStatus>
{
Items = jobInfos,
},
DepartmentInfo = new SapPerson<SapPersonDepartmentStatus>
{
Items = departmentInfos
}
};
}