fix 增加恢复处理
This commit is contained in:
@@ -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")]
|
||||
|
||||
@@ -74,4 +74,6 @@ public interface IAppointmentService : IScopeDependency
|
||||
Task AutoResignAsync();
|
||||
|
||||
Task<List<string>> GetVisitorDevicesAsync(long detailId);
|
||||
|
||||
Task RecoverAsync();
|
||||
}
|
||||
@@ -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<GainfoLeaveEntity>()
|
||||
.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<GainfoEntity>();
|
||||
gainfo.Id = gainfo.IdentityUserId;
|
||||
await _dbContext.InsertAsync(gainfo);
|
||||
await _dbContext.DeleteReallyAsync(gainfoLeave);
|
||||
|
||||
var detail = await _dbContext.Queryable<VisitorAppointmentDetailEntity>().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<List<string>> GetVisitorDevicesAsync(long detailId)
|
||||
{
|
||||
var detail = await _dbContext.Queryable<VisitorAppointmentDetailEntity>().Where(x => x.Id == detailId).SingleAsync();
|
||||
|
||||
Reference in New Issue
Block a user