From 5c2d40d1804a2daa34e11bbc07210d5cbefb3727 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 21 Feb 2024 17:53:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.ScheduledTask/Packs/JobPack.cs | 6 +++++- .../SyncSapInfo/Job/SyncOrganizationJob.cs | 16 +--------------- .../SyncSapInfo/Job/SyncPersonJob.cs | 2 +- .../SyncSapInfo/Job/SyncPositionJob.cs | 10 ++-------- .../Services/Implements/JinkoSapService.cs | 3 +-- 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs index c297f580..49f75fff 100644 --- a/Src/Dlhis.ScheduledTask/Packs/JobPack.cs +++ b/Src/Dlhis.ScheduledTask/Packs/JobPack.cs @@ -18,11 +18,15 @@ public class JobPack : BaseAppPack TimeZone = TimeZoneInfo.Local }); - RecurringJob.AddOrUpdate("SyncServerDateTime", s => s.RunAsync(), "0 0 0/1 * * ?", new RecurringJobOptions + RecurringJob.AddOrUpdate("SyncPerson", s => s.RunAsync(), "0 0 3 * * ?", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); + RecurringJob.AddOrUpdate("SyncServerDateTime", s => s.RunAsync(), "0 0 0/1 * * ?", new RecurringJobOptions + { + TimeZone = TimeZoneInfo.Local + }); RecurringJob.AddOrUpdate("CreateGetAttendance", s => s.RunAsync(), "0 0/1 * * * ?", new RecurringJobOptions { diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncOrganizationJob.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncOrganizationJob.cs index fb5a652f..66df77bc 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncOrganizationJob.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncOrganizationJob.cs @@ -1,5 +1,4 @@ using Dlhis.Entity.Basic.Entity; -using Dlhis.ScheduledTask.SyncSapInfo.Comparers; using Dlhis.ScheduledTask.SyncSapInfo.Dto; using Dlhis.ScheduledTask.SyncSapInfo.Services; using Hangfire; @@ -12,7 +11,6 @@ namespace Dlhis.ScheduledTask.SyncSapInfo.Job; /// public class SyncOrganizationJob { - private List lastUpdatedOrgList = new(); private readonly IDbContext _dbContext; private readonly IJinkoSapService _jinkoSapService; @@ -28,23 +26,11 @@ public class SyncOrganizationJob if (orgResult.Org != null && orgResult.Org.Items.Count > 0) { - //var modifiedOrgList = GetModifiedOrg(orgResult.Org.Items); await SaveOrg(orgResult.Org.Items); } var syncPositionJob = BackgroundJob.Enqueue(job => job.SyncPositionInfo()); - BackgroundJob.ContinueJobWith(syncPositionJob, job => job.SyncPersonInfo(), JobContinuationOptions.OnlyOnSucceededState); - } - - private List GetModifiedOrg(List sapList) - { - if (lastUpdatedOrgList.Count <= 0) - { - return sapList; - } - - var needRemove = sapList.Intersect(lastUpdatedOrgList, new SapOrganizationComparer()); - return sapList.Except(needRemove, new SapOrganizationComparer()).ToList(); + BackgroundJob.ContinueJobWith(syncPositionJob, job => job.RunAsync(), JobContinuationOptions.OnlyOnSucceededState); } private async Task SaveOrg(List modifiedOrgList) diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs index 27c9e6d2..4bf792b5 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPersonJob.cs @@ -23,7 +23,7 @@ public class SyncPersonJob _jinkoSapService = jinkoSapService; } - public async Task SyncPersonInfo() + public async Task RunAsync() { var personResp = await _jinkoSapService.GetPersonsAsync(); var persons = personResp.Person.Items; diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPositionJob.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPositionJob.cs index 6be2f7f9..3a5e182e 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPositionJob.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Job/SyncPositionJob.cs @@ -31,9 +31,6 @@ public class SyncPositionJob private async Task SaveOrg(List modifiedPostList) { - var addItems = new List(); - var updateItems = new List(); - foreach (var item in modifiedPostList) { var position = await _dbContext.Queryable().Where(x => x.No == item.ZJOBID).FirstAsync(); @@ -47,7 +44,7 @@ public class SyncPositionJob Grade = item.ZZWID }; - addItems.Add(position); + await _dbContext.InsertAsync(position); } else { @@ -55,11 +52,8 @@ public class SyncPositionJob position.DepartmentNo = item.ZDEPID; position.Grade = item.ZZWID; - updateItems.Add(position); + await _dbContext.UpdateAsync(position); } } - - await _dbContext.InsertAsync(addItems); - await _dbContext.UpdateAsync(updateItems); } } diff --git a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs index 3fc2872d..292b8f8e 100644 --- a/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs +++ b/Src/Dlhis.ScheduledTask/SyncSapInfo/Services/Implements/JinkoSapService.cs @@ -87,14 +87,13 @@ public class JinkoSapService : IJinkoSapService T_PERSON = Array.Empty(), T_PNO = Array.Empty(), }; - var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); + var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); var response = await GetHttpClient().PostAsync(apiUrl, content); response.EnsureSuccessStatusCode(); var jsonResponse = await response.Content.ReadAsStringAsync(); - var personResp = JsonConvert.DeserializeObject(jsonResponse); if (personResp?.Person?.Items?.Any() == true) {