新增定时账单功能
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 30s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s

This commit is contained in:
孙诚
2025-12-29 15:20:32 +08:00
parent 13bf23a48c
commit 9719c6043a
19 changed files with 2409 additions and 27 deletions

40
WebApi/Expand.cs Normal file
View File

@@ -0,0 +1,40 @@
using Quartz;
namespace WebApi;
public static class Expand
{
public static void AddScheduler(this WebApplicationBuilder builder)
{
builder.Services.AddQuartz(q =>
{
// 配置调度器
q.SchedulerId = "EmailBillScheduler";
// 配置邮件同步任务 - 每10分钟执行一次
var emailJobKey = new JobKey("EmailSyncJob");
q.AddJob<Service.Jobs.EmailSyncJob>(opts => opts.WithIdentity(emailJobKey));
q.AddTrigger(opts => opts
.ForJob(emailJobKey)
.WithIdentity("EmailSyncTrigger")
.WithCronSchedule("0 0/20 * * * ?") // 每20分钟执行
.WithDescription("每20分钟同步一次邮件"));
// 配置周期性账单任务 - 每天早上6点执行
var periodicBillJobKey = new JobKey("PeriodicBillJob");
q.AddJob<Service.Jobs.PeriodicBillJob>(opts => opts.WithIdentity(periodicBillJobKey));
q.AddTrigger(opts => opts
.ForJob(periodicBillJobKey)
.WithIdentity("PeriodicBillTrigger")
.WithCronSchedule("0 0 6 * * ?") // 每天早上6点执行
.WithDescription("每天早上6点执行周期性账单检查"));
});
// 添加 Quartz Hosted Service
builder.Services.AddQuartzHostedService(options =>
{
// 等待任务完成后再关闭
options.WaitForJobsToComplete = true;
});
}
}