feat sap出差信息获取,海宁余额上传tenantId问题
This commit is contained in:
63
Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs
Normal file
63
Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Visitor.Entity;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
using Dlhis.ScheduledTask.Common.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
[RecurringJob(nameof(SyncBusinessTripJob), "0 0 0/1 * * ? ", Name = "SAP同步出差信息")]
|
||||
public class SyncBusinessTripJob : BaseJob
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public SyncBusinessTripJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var jipService = serviceProvider.GetService<IJinkoJIPService>();
|
||||
var today = DateTime.Today;
|
||||
|
||||
var departments = await DbContext.Queryable<DepartmentEntity>().ToListAsync();
|
||||
var tops = departments.Where(x => x.PNo == "00001000").ToList();
|
||||
var validDepartments = tops.ToList();
|
||||
tops.ForEach(x => RecursionGetNext(x, departments, validDepartments));
|
||||
|
||||
foreach (var department in validDepartments)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tripResponse = await jipService.GetTravelInfosAsync(today, today, department.No);
|
||||
foreach (var tripInfoItem in tripResponse.Items)
|
||||
{
|
||||
if (await DbContext.Queryable<BusinessTripEntity>().Where(x => x.Code == tripInfoItem.Code && x.BeginDate == tripInfoItem.BeginDate && x.EndDate == tripInfoItem.EndDate)
|
||||
.AnyAsync())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var entity = tripInfoItem.Adapt<BusinessTripEntity>();
|
||||
await DbContext.InsertAsync(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError(e, "获取部门{departmentNo}{departmentName}出差数据执行失败:{message}", department.No, department.Name, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//************************************************************************************************************************************************
|
||||
|
||||
private static void RecursionGetNext(DepartmentEntity current, List<DepartmentEntity> data, List<DepartmentEntity> result)
|
||||
{
|
||||
var next = data.Where(x => x.PNo == current.No).ToList();
|
||||
foreach (var item in next)
|
||||
{
|
||||
result.Add(item);
|
||||
RecursionGetNext(item, data, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user