Files
jinko.yikatong/Src/Dlhis.ScheduledTask/Jobs/RemoveFacePictureAfterResignedJob.cs
2025-10-23 11:51:51 +08:00

41 lines
1.5 KiB
C#

using Dlhis.Entity.Basic.Entity;
using Dlhis.ScheduledTask.Attributes;
using Kurisu.AspNetCore.Utils.Extensions;
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 = DateTime.Now.AddMonths(-1).Date;
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();
Logger.LogInformation("移除人脸图片,工号列表:{codes}", leaveUserCode.Join(","));
}
}
}