diff --git a/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs b/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs index 41139c06..ccaba038 100644 --- a/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs +++ b/Src/Dlhis.Basic/Appointment/Controllers/AppointmentsController.cs @@ -152,6 +152,14 @@ public class AppointmentsController : ControllerBase await _appointmentService.AutoResignAsync(); } + [AllowAnonymous] + [HttpPost("recover")] + [IgnoreTenant] + public async Task RecoverAsync() + { + await _appointmentService.RecoverAsync(); + } + [AllowAnonymous] [IgnoreTenant] [HttpGet("visitor-devices")] diff --git a/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs b/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs index 6ce15473..b294a2fc 100644 --- a/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/IAppointmentService.cs @@ -74,4 +74,6 @@ public interface IAppointmentService : IScopeDependency Task AutoResignAsync(); Task> GetVisitorDevicesAsync(long detailId); + + Task RecoverAsync(); } \ 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 a43d8918..9f13fb7e 100644 --- a/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs +++ b/Src/Dlhis.Basic/Appointment/Services/Implements/AppointmentService.cs @@ -19,6 +19,7 @@ using Kurisu.AspNetCore.DataAccess.Dto; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.Utils.Extensions; +using Mapster; using Microsoft.AspNetCore.DataProtection; using SqlSugar; @@ -340,6 +341,39 @@ public class AppointmentService : IAppointmentService await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Update, "访客手动上传照片"); } + public async Task RecoverAsync() + { + var day = new DateTime(2025, 12, 19); + var gainfoLeaves = await _dbContext.Queryable() + .Where(x => x.Type == GainfoUserTypeEnumType.External) + .Where(x => SqlFunc.DateIsSame(x.ResignationDate, day)) + .ToListAsync(); + + foreach (var gainfoLeave in gainfoLeaves) + { + await _dbContext.Client.Ado.BeginTranAsync(); + try + { + var gainfo = gainfoLeave.Adapt(); + gainfo.Id = gainfo.IdentityUserId; + await _dbContext.InsertAsync(gainfo); + await _dbContext.DeleteReallyAsync(gainfoLeave); + + var detail = await _dbContext.Queryable().Where(x => x.UserNo == gainfo.No).SingleAsync(); + detail.ThrowIfNull("数据不存在"); + + await GenerateDeviceTasksAsync(detail, true, DeviceTaskEnumType.Update, "数据恢复"); + + await _dbContext.Client.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + _logger.LogError(ex, "恢复外部人员失败:{userNo}", gainfoLeave.No); + await _dbContext.Client.Ado.RollbackTranAsync(); + } + } + } + public async Task> GetVisitorDevicesAsync(long detailId) { var detail = await _dbContext.Queryable().Where(x => x.Id == detailId).SingleAsync();