From 6fa4a3ccd5f14ed8afbb49d3ff8e1eeadeb854da Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 15 Apr 2025 14:46:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=A4=84=E7=90=86=E5=B7=B2=E7=9F=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Dlhis.Basic.Api/ISyncApi.cs | 9 ++- .../Controllers/AppointmentsController.cs | 12 ++++ .../Services/IAppointmentService.cs | 6 ++ .../Services/Implements/AppointmentService.cs | 58 +++++++++++++++++++ .../Response/FactorySettingResponse.cs | 5 ++ .../Implements/FactorySettingService.cs | 3 +- .../Implements/WorkGridScheduleService.cs | 14 ++++- .../Sys/Entities/FactorySettingEntity.cs | 5 ++ .../Jobs/ExternalAutoResignJob.cs | 25 ++++++++ 9 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 Src/Dlhis.ScheduledTask/Jobs/ExternalAutoResignJob.cs diff --git a/Src/Dlhis.Basic.Api/ISyncApi.cs b/Src/Dlhis.Basic.Api/ISyncApi.cs index d4990776..98a45921 100644 --- a/Src/Dlhis.Basic.Api/ISyncApi.cs +++ b/Src/Dlhis.Basic.Api/ISyncApi.cs @@ -28,11 +28,18 @@ public interface ISyncApi [Post("/api/sync/businessTrips")] [RequestContentHandler(typeof(CodeContentHandler))] Task HandlerBusinessTripsAsync(string code); - + /// /// 外包自动离职处理 /// /// [Post("/api/gainfoOutsource/autoResign")] Task OutsourceAutoResignAsync(); + + /// + /// 外部人员自动离职处理 + /// + /// + [Post("/api/appointments/autoResign")] + Task ExternalAutoResignAsync(); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs b/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs index 9de64a85..b3a8c9f6 100644 --- a/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs +++ b/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs @@ -140,4 +140,16 @@ public class AppointmentsController : ControllerBase end = start.Date.AddDays(1).AddMilliseconds(-1); return await _appointmentService.GetSummaryAsync(factory, start, end); } + + + /// + /// 自动离职处理 + /// + [AllowAnonymous] + [HttpPost("autoResign")] + [IgnoreTenant] + public async Task AutoResignAsync() + { + await _appointmentService.AutoResignAsync(); + } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs index d875b375..d447469d 100644 --- a/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs @@ -66,4 +66,10 @@ public interface IAppointmentService : IScopeDependency /// /// Task UpdateFaceAsync(long detailId, string base64); + + /// + /// 自动离职 + /// + /// + Task AutoResignAsync(); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs index 61f45771..c34e9e0f 100644 --- a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs @@ -5,6 +5,7 @@ using Dlhis.Basic.Organization.Services; using Dlhis.Dh.Api; using Dlhis.Dh.Api.Requests; using Dlhis.Entity.Basic.Entity; +using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Visitor.Entity; @@ -26,6 +27,8 @@ public class AppointmentService : IAppointmentService private readonly IDataProtectionProvider _dataProtectionProvider; private readonly ICurrentUser _currentUser; private readonly IDhApi _dhApi; + private readonly IGainfoService _gainfoService; + private readonly IFactorySettingService _factorySettingService; private readonly ILogger _logger; private readonly IGainfoFaceService _gainfoFaceService; @@ -33,6 +36,8 @@ public class AppointmentService : IAppointmentService IDataProtectionProvider dataProtectionProvider, ICurrentUser currentUser, IDhApi dhApi, + IGainfoService gainfoService, + IFactorySettingService factorySettingService, IGainfoFaceService gainfoFaceService, ILogger logger) { @@ -40,6 +45,8 @@ public class AppointmentService : IAppointmentService _dataProtectionProvider = dataProtectionProvider; _currentUser = currentUser; _dhApi = dhApi; + _gainfoService = gainfoService; + _factorySettingService = factorySettingService; _logger = logger; _gainfoFaceService = gainfoFaceService; } @@ -311,6 +318,57 @@ public class AppointmentService : IAppointmentService await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Update, "访客手动上传照片"); } + /// + public async Task AutoResignAsync() + { + var outsources = await _dbContext.Queryable() + .Where(x => x.Type == GainfoUserTypeEnumType.External) + .Select(x => new { x.Id, x.Code, x.Factory, x.CreateTime }) + .ToListAsync(); + + var settings = await _factorySettingService.GetListAsync(false); + //0001/1/1 0:00:00 + var nullDateTime = new DateTime(1, 1, 1); + + foreach (var grp in outsources.GroupBy(x => x.Factory)) + { + var setting = settings.First(x => x.Factory == grp.Key); + if (setting.NoRecordAutoResignExternalDays == 0) + { + continue; + } + + foreach (var outsource in grp) + { + var raiseDateTime = await _dbContext.Queryable() + .Where(x => x.UserUniqueNo == outsource.Code) + .GroupBy(x => x.UserUniqueNo) + .Select(x => SqlFunc.IsNull(SqlFunc.AggregateMax(x.RaiseDateTime), outsource.CreateTime)) + .SingleAsync(); + + raiseDateTime = raiseDateTime == nullDateTime ? outsource.CreateTime : raiseDateTime; + + if (raiseDateTime.AddDays(setting.NoRecordAutoResignExternalDays) < DateTime.Now) + { + try + { + await _gainfoService.ResignAsync(new GainfoResignRequest + { + Id = outsource.Id, + Reason = $"{setting.NoRecordAutoResignExternalDays}天无通行记录", + Date = DateTime.Now, + IsOutsource = true + }); + } + catch (Exception e) + { + _logger.LogError(e, "自动归档外部人员异常:{msg}", e.Message); + } + } + } + } + } + //********************************************************************************************************************* diff --git a/Src/Dlhis.Basic/Organization/Response/FactorySettingResponse.cs b/Src/Dlhis.Basic/Organization/Response/FactorySettingResponse.cs index 55b35f80..22951946 100644 --- a/Src/Dlhis.Basic/Organization/Response/FactorySettingResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/FactorySettingResponse.cs @@ -27,4 +27,9 @@ public class FactorySettingResponse /// 外包自动离职天数(无通行记录) /// public int NoRecordAutoResignOutsourceDays { get; set; } + + /// + /// 外部人员自动离职天数(无通行记录) + /// + public int NoRecordAutoResignExternalDays { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/FactorySettingService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/FactorySettingService.cs index d2a54e5b..32fb28a8 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/FactorySettingService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/FactorySettingService.cs @@ -149,7 +149,8 @@ public class FactorySettingService : IFactorySettingService Level = FaceQualityLevelEnumType.Medium }).ToList() }, - NoRecordAutoResignOutsourceDays = currentSetting?.NoRecordAutoResignOutsourceDays ?? 30 + NoRecordAutoResignOutsourceDays = currentSetting?.NoRecordAutoResignOutsourceDays ?? 30, + NoRecordAutoResignExternalDays = currentSetting?.NoRecordAutoResignExternalDays ?? 0 }; }).ToList(); } diff --git a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs index 9bbb2de4..ee91f759 100644 --- a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs +++ b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridScheduleService.cs @@ -63,7 +63,7 @@ public class WorkGridScheduleService : IWorkGridScheduleService var timeSetting = await _dbContext.Queryable().Where(x => x.Type == request.PeriodType).Select(x => new { x.Start, x.Before }).SingleAsync(); timeSetting.ThrowIfNull("工作网格时间尚未配置,无法操作"); - + var currentLimit = request.Date.ToDateTime(timeSetting.Start.Add(-TimeSpan.FromSeconds(timeSetting.Before))); (DateTime.Now >= currentLimit).ThrowIfTrue("当前时间不可修改排班信息"); @@ -265,7 +265,7 @@ public class WorkGridScheduleService : IWorkGridScheduleService var t = request.IsError.ToString().ToLower(); var filterString = $"{{\"IsError\":{t}"; - return await _dbContext.Queryable() + var r = await _dbContext.Queryable() .LeftJoin((log, d) => log.DeviceUniqueNo == d.UniqueNo) .LeftJoin((log, d, ga) => log.UserUniqueNo == ga.Code) .WhereIF(request.DateTimePeriod.HasValue(), log => log.RaiseDateTime >= request.DateTimePeriod.Start @@ -294,7 +294,15 @@ public class WorkGridScheduleService : IWorkGridScheduleService Status = log.Status, WorkGridInfo = log.WorkGridInfo, }) - .ToPageListAsync(request); + .ToPageListAsync(request.PageIndex, request.PageSize); + + return new Pagination + { + PageIndex = request.PageIndex, + PageSize = request.PageSize, + Total = 0, + Data = r + }; } public async Task> GetAllAttendancePageAsync(WorkGridScheduleAttendancePageRequest request) diff --git a/Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs b/Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs index 2a764e84..b30049fc 100644 --- a/Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs +++ b/Src/Dlhis.Entity/Sys/Entities/FactorySettingEntity.cs @@ -41,6 +41,11 @@ public class FactorySettingEntity : SugarBaseEntity, ITenantId /// public int NoRecordAutoResignOutsourceDays { get; set; } + /// + /// 访客自动离职天数(无通行记录) + /// + public int NoRecordAutoResignExternalDays { get; set; } + [SugarColumn(IsNullable = true, ColumnDataType = "time", ColumnDescription = "工作网格编辑限制时间")] public TimeOnly? WorkGridSetLimit { get; set; } diff --git a/Src/Dlhis.ScheduledTask/Jobs/ExternalAutoResignJob.cs b/Src/Dlhis.ScheduledTask/Jobs/ExternalAutoResignJob.cs new file mode 100644 index 00000000..bde769c7 --- /dev/null +++ b/Src/Dlhis.ScheduledTask/Jobs/ExternalAutoResignJob.cs @@ -0,0 +1,25 @@ +using Dlhis.Basic.Api; +using Dlhis.ScheduledTask.Attributes; + +namespace Dlhis.ScheduledTask.Jobs; + +/// +/// 自动处理外包离职 +/// +[RecurringJob(nameof(ExternalAutoResignJob), "0 0 1 1/1 * ? ", Name = "自动处理外部人员离职")] +public class ExternalAutoResignJob : BaseJob +{ + private readonly ISyncApi _syncApi; + + /// + public ExternalAutoResignJob(IServiceProvider serviceProvider, ISyncApi syncApi) : base(serviceProvider) + { + _syncApi = syncApi; + } + + /// + protected override async Task RunAsync(IServiceProvider serviceProvider) + { + await _syncApi.ExternalAutoResignAsync(); + } +} \ No newline at end of file