Files
EmailBill/Service/Jobs/BudgetArchiveJob.cs
SunCheng 44d9fbb0f6
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 23s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
todo
2026-01-19 13:39:59 +08:00

46 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Quartz;
using Service.Budget;
namespace Service.Jobs;
/// <summary>
/// 预算归档定时任务
/// </summary>
[DisallowConcurrentExecution]
public class BudgetArchiveJob(
IServiceProvider serviceProvider,
ILogger<BudgetArchiveJob> logger) : IJob
{
public async Task Execute(IJobExecutionContext context)
{
try
{
logger.LogInformation("开始执行预算归档任务");
// 每个月1号执行归档上个月的数据
var targetDate = DateTime.Now.AddMonths(-1);
var year = targetDate.Year;
var month = targetDate.Month;
using var scope = serviceProvider.CreateScope();
var budgetService = scope.ServiceProvider.GetRequiredService<IBudgetService>();
// 归档月度数据
var result = await budgetService.ArchiveBudgetsAsync(year, month);
if (string.IsNullOrEmpty(result))
{
logger.LogInformation("归档 {Year}年{Month}月 预算任务执行成功", year, month);
}
else
{
logger.LogWarning("归档 {Year}年{Month}月 预算任务提示: {Result}", year, month, result);
}
}
catch (Exception ex)
{
logger.LogError(ex, "预算归档任务执行出错");
}
}
}