From 39a16b856032c446d361157deb2fc4e27ce3e10f Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 4 Jul 2024 15:44:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=20trip=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Response/MealSupplementRecordResponse.cs | 4 +- .../Implements/MealSupplementRecordService.cs | 8 ++-- .../Common/Services/IJinkoJIPService.cs | 7 +++- .../Services/Implements/JinkoJIPService.cs | 39 +++++++++++++++++-- .../Jobs/CreateSyncServerDateTimeJob.cs | 13 +++---- .../Jobs/SyncBusinessTripJob.cs | 8 ++-- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs index f0c4ef9d..c8f86168 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Response/MealSupplementRecordResponse.cs @@ -62,4 +62,6 @@ public class MealSupplementRecordResponse /// 状态同步 /// public bool Sync { get; set; } -} + + public DateTime CreateTime { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs index 870ade09..9fe2f9c5 100644 --- a/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs +++ b/Src/Dlhis.Canteen/MealSupplementRecord/Services/Implements/MealSupplementRecordService.cs @@ -1,11 +1,11 @@ using Dlhis.Canteen.MealSupplementRecord.Request; using Dlhis.Canteen.MealSupplementRecord.Response; using Dlhis.Entity.Basic.Entity; -using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Canteen.Entities; using Dlhis.Entity.Canteen.Enums; using Dlhis.Sys.Api; using Kurisu.AspNetCore.Authentication.Abstractions; +using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; @@ -36,9 +36,7 @@ public class MealSupplementRecordService : IMealSupplementRecordService .WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync) .WhereIF(request.Workplace.IsPresent(), x => x.Workplace == request.Workplace) .WhereIF(request.Factory.IsPresent(), x => x.Factory == request.Factory) - .WhereIF(request.DateTimePeriod?.Start.HasValue == true - && request.DateTimePeriod?.End.HasValue == true, - x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End) + .WhereIF(request.DateTimePeriod.HasValue(), x => x.Date >= request.DateTimePeriod.Start && x.Date <= request.DateTimePeriod.End) .WhereIF(request.Search.IsPresent(), (x, ga) => x.Code == request.Search || ga.Name == request.Search) .Select((x, ga) => new MealSupplementRecordResponse { @@ -51,9 +49,9 @@ public class MealSupplementRecordService : IMealSupplementRecordService Sync = x.Sync, UniqueId = x.UniqueId, UserName = ga.Name, - Workplace = x.Workplace, Factory = x.Factory, + CreateTime = x.CreateTime }) .ToPageListAsync(request); diff --git a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs index 038e5ec0..fa504a74 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/IJinkoJIPService.cs @@ -15,9 +15,12 @@ public interface IJinkoJIPService : ISingletonDependency /// /// /// - /// + /// /// - Task GetTravelInfosAsync(DateTime begin, DateTime end, string departmentNo); + Task GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List departmentNos); + + + Task GetTravelInfosByUserCodeAsync(DateTime begin, DateTime end, string userCode); string IssueToken(); } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs index b6722bc9..1cab2eb0 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/Implements/JinkoJIPService.cs @@ -27,7 +27,6 @@ public class JinkoJIPService : IJinkoJIPService { var httpClient = _httpClientFactory.CreateClient(); httpClient.BaseAddress = new Uri(_configuration.GetSection("JinkoOptions:Jip:BaseUrl").Value); - httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", IssueToken()); return httpClient; @@ -96,13 +95,46 @@ public class JinkoJIPService : IJinkoJIPService } - public async Task GetTravelInfosAsync(DateTime begin, DateTime end, string departmentNo) + public async Task GetTravelInfosByDepartmentsAsync(DateTime begin, DateTime end, List departmentNos) { const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO"; var beginDay = begin.ToString("yyyyMMdd"); var endDay = end.ToString("yyyyMMdd"); + var d = departmentNos.Select(x => new + { + IV_ORGID = x + }); + + //IV_GONGH IV_ORGID + //IT_2002GH + var obj = new + { + IV_BEGDA = beginDay, + IV_ENDDA = endDay, + IT_2002OR = d + }; + + var body = obj.ToJson(); + + var content = new StringContent(body, Encoding.UTF8, "application/json"); + var response = await GetHttpClient().PostAsync(apiUrl, content); + response.EnsureSuccessStatusCode(); + + var jsonResponse = await response.Content.ReadAsStringAsync(); + return jsonResponse.ToObject(); + } + + public async Task GetTravelInfosByUserCodeAsync(DateTime begin, DateTime end, string userCode) + { + const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO"; + + var beginDay = begin.ToString("yyyyMMdd"); + var endDay = end.ToString("yyyyMMdd"); + + //IV_GONGH IV_ORGID + //IT_2002GH var obj = new { IV_BEGDA = beginDay, @@ -111,8 +143,7 @@ public class JinkoJIPService : IJinkoJIPService { new { - //IV_GONGH = "" 工号, - IV_ORGID = departmentNo, + IV_GONGH = userCode } } }; diff --git a/Src/Dlhis.ScheduledTask/Jobs/CreateSyncServerDateTimeJob.cs b/Src/Dlhis.ScheduledTask/Jobs/CreateSyncServerDateTimeJob.cs index 2acfe62d..d73ddd51 100644 --- a/Src/Dlhis.ScheduledTask/Jobs/CreateSyncServerDateTimeJob.cs +++ b/Src/Dlhis.ScheduledTask/Jobs/CreateSyncServerDateTimeJob.cs @@ -11,7 +11,6 @@ namespace Dlhis.ScheduledTask.Jobs; [RecurringJob(nameof(CreateSyncServerDateTimeJob), "0 0 0/1 * * ?", Name = "设备时间同步")] public class CreateSyncServerDateTimeJob : BaseJob { - public CreateSyncServerDateTimeJob(IServiceProvider serviceProvider) : base(serviceProvider) { } @@ -20,10 +19,10 @@ public class CreateSyncServerDateTimeJob : BaseJob { var deviceUniqueNos = await DbContext.Queryable() .Where(x => x.Status == DeviceTaskStatusEnumType.Wait || x.Status == DeviceTaskStatusEnumType.Process) - .Where(x => x.Type == DeviceTaskEnumType.SyncDateTime) - .Select(x => x.DeviceUniqueNo) - .Distinct() - .ToListAsync(); + .Where(x => x.Type == DeviceTaskEnumType.SyncDateTime) + .Select(x => x.DeviceUniqueNo) + .Distinct() + .ToListAsync(); var devices = await DbContext.Queryable() .Where(x => !deviceUniqueNos.Contains(x.UniqueNo)) @@ -41,10 +40,8 @@ public class CreateSyncServerDateTimeJob : BaseJob Type = DeviceTaskEnumType.SyncDateTime, DeviceType = x.Type, Priority = 49, - }).ToList(); await DbContext.InsertAsync(tasks); - } -} +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs b/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs index 8930a986..24d38d8e 100644 --- a/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs +++ b/Src/Dlhis.ScheduledTask/Jobs/SyncBusinessTripJob.cs @@ -6,7 +6,7 @@ using Mapster; namespace Dlhis.ScheduledTask.Jobs; -[RecurringJob(nameof(SyncBusinessTripJob), "0 0 0/1 * * ? ", Name = "SAP同步出差信息")] +[RecurringJob(nameof(SyncBusinessTripJob), "0 0 1 1/1 * ? ", Name = "SAP同步出差信息")] public class SyncBusinessTripJob : BaseJob { /// @@ -25,11 +25,11 @@ public class SyncBusinessTripJob : BaseJob var validDepartments = tops.ToList(); tops.ForEach(x => RecursionGetNext(x, departments, validDepartments)); - foreach (var department in validDepartments) + foreach (var departmentNos in validDepartments.Select(x => x.No).Chunk(100)) { try { - var tripResponse = await jipService.GetTravelInfosAsync(today, today, department.No); + var tripResponse = await jipService.GetTravelInfosByDepartmentsAsync(today, today, departmentNos.ToList()); foreach (var tripInfoItem in tripResponse.Items) { if (await DbContext.Queryable().Where(x => x.Code == tripInfoItem.Code && x.BeginDate == tripInfoItem.BeginDate && x.EndDate == tripInfoItem.EndDate) @@ -44,7 +44,7 @@ public class SyncBusinessTripJob : BaseJob } catch (Exception e) { - Logger.LogError(e, "获取部门{departmentNo}{departmentName}出差数据执行失败:{message}", department.No, department.Name, e.Message); + Logger.LogError(e, "获取部门出差数据执行失败:{message}", e.Message); } } }