fix 处理已知问题

This commit is contained in:
2025-04-15 14:46:29 +08:00
parent 5c0e8584da
commit 6fa4a3ccd5
9 changed files with 132 additions and 5 deletions

View File

@@ -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<AppointmentService> _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<AppointmentService> 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, "访客手动上传照片");
}
/// <inheritdoc />
public async Task AutoResignAsync()
{
var outsources = await _dbContext.Queryable<GainfoEntity>()
.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<DeviceUploadLogEntity>()
.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);
}
}
}
}
}
//*********************************************************************************************************************