feat: 实现订阅自动化定时任务系统
新增定时任务 (Scheduler Module): - SubscriptionAutoRenewalJob: 自动续费账单生成 - SubscriptionRenewalReminderJob: 续费提醒发送 (7/3/1天) - SubscriptionExpiryCheckJob: 到期检查与宽限期处理 新增 Command/Handler: - ProcessAutoRenewalCommand: 处理自动续费逻辑 - ProcessRenewalRemindersCommand: 处理续费提醒逻辑 - ProcessSubscriptionExpiryCommand: 处理订阅到期逻辑 配置项 (SubscriptionAutomationOptions): - AutoRenewalDaysBeforeExpiry: 到期前N天生成续费账单 - ReminderDaysBeforeExpiry: 提醒天数数组 - GracePeriodDays: 宽限期天数 - 各任务执行小时配置 Repository 增强: - ISubscriptionRepository: 新增自动化查询方法 - ITenantBillingRepository: 新增账单创建方法 - ITenantNotificationRepository: 新增通知创建方法 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using TakeoutSaaS.Application.App.Subscriptions.Commands;
|
||||
using TakeoutSaaS.Module.Scheduler.Options;
|
||||
|
||||
namespace TakeoutSaaS.Module.Scheduler.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 订阅续费提醒任务:到期前 7/3/1 天发送站内提醒。
|
||||
/// </summary>
|
||||
public sealed class SubscriptionRenewalReminderJob(
|
||||
IMediator mediator,
|
||||
IOptionsMonitor<SubscriptionAutomationOptions> optionsMonitor,
|
||||
ILogger<SubscriptionRenewalReminderJob> logger)
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行续费提醒扫描与发送。
|
||||
/// </summary>
|
||||
public async Task ExecuteAsync()
|
||||
{
|
||||
// 1. 读取配置并执行续费提醒
|
||||
var options = optionsMonitor.CurrentValue;
|
||||
var result = await mediator.Send(new ProcessRenewalRemindersCommand
|
||||
{
|
||||
ReminderDaysBeforeExpiry = options.ReminderDaysBeforeExpiry
|
||||
});
|
||||
|
||||
// 2. 记录执行结果
|
||||
logger.LogInformation(
|
||||
"定时任务:续费提醒处理完成,候选 {CandidateCount},创建 {CreatedReminderCount}",
|
||||
result.CandidateCount,
|
||||
result.CreatedReminderCount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user