feat 移除7天内离职人员face图片

This commit is contained in:
2025-10-23 11:24:54 +08:00
parent b03b7b9963
commit a0c0b11b13

View File

@@ -0,0 +1,38 @@
using Dlhis.Entity.Basic.Entity;
using Dlhis.ScheduledTask.Attributes;
using SqlSugar;
namespace Dlhis.ScheduledTask.Jobs;
[RecurringJob(nameof(RemoveFacePictureAfterResignedJob), "0 0 1 * * ? ", Name = "移除7天内离职人员face图片")]
public class RemoveFacePictureAfterResignedJob : BaseJob
{
public RemoveFacePictureAfterResignedJob(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
protected override async Task RunAsync(IServiceProvider serviceProvider)
{
var start = new DateTime(2024, 1, 1);
var now = DateTime.Now.AddDays(-7).Date;
var leaveUserCodes = await DbContext.Queryable<GainfoLeaveEntity>()
.Where(x => SqlFunc.Subqueryable<GainfoEntity>().Where(p => p.Code == x.Code).NotAny())
.Where(x => !string.IsNullOrEmpty(x.No)
&& x.ResignationDate.HasValue
&& x.ResignationDate >= start
&& x.ResignationDate < now
)
.Select(x => x.Code)
.Distinct()
.ToListAsync();
var faceDbContext = DbContext.ChangeDb("face");
foreach (var leaveUserCode in leaveUserCodes.Chunk(10))
{
await faceDbContext.Deleteable<GainfoFaceEntity>()
.Where(x => leaveUserCode.Contains(x.UserCode))
.ExecuteCommandAsync();
}
}
}