feat: Implement scheduled tasks management and budget archiving functionality
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 6s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 6s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s
- Added BudgetArchiveJob for monthly budget archiving. - Created BudgetArchive entity and BudgetArchiveRepository for managing archived budgets. - Introduced JobController for handling job execution, pausing, and resuming. - Developed ScheduledTasksView for displaying and managing scheduled tasks in the frontend. - Updated PeriodicBillJob to improve scope handling. - Enhanced OpenAiService with increased HTTP timeout. - Added archiveBudgets API endpoint for archiving budgets by year and month. - Refactored BudgetController to utilize new repository patterns and improved error handling. - Introduced rich-content styles for better rendering of HTML content in Vue components. - Updated various Vue components to support rich HTML content display.
This commit is contained in:
@@ -4,42 +4,23 @@
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class BudgetController(
|
||||
IBudgetService budgetService,
|
||||
IConfigService configService,
|
||||
IBudgetRepository budgetRepository,
|
||||
ILogger<BudgetController> logger) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取预算列表
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<List<BudgetDto>>> GetListAsync([FromQuery] DateTime? referenceDate = null)
|
||||
public async Task<BaseResponse<List<BudgetResult>>> GetListAsync([FromQuery] DateTime? referenceDate = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var budgets = await budgetService.GetAllAsync();
|
||||
var dtos = new List<BudgetDto?>();
|
||||
|
||||
foreach (var budget in budgets)
|
||||
{
|
||||
var currentAmount = await budgetService.CalculateCurrentAmountAsync(budget, referenceDate);
|
||||
dtos.Add(BudgetDto.FromEntity(budget, currentAmount, referenceDate));
|
||||
}
|
||||
|
||||
// 创造虚拟的存款预算
|
||||
dtos.Add(await GetVirtualSavingsDtoAsync(
|
||||
BudgetPeriodType.Month,
|
||||
referenceDate,
|
||||
budgets));
|
||||
dtos.Add(await GetVirtualSavingsDtoAsync(
|
||||
BudgetPeriodType.Year,
|
||||
referenceDate,
|
||||
budgets));
|
||||
|
||||
return dtos.Where(dto => dto != null).Cast<BudgetDto>().ToList().Ok();
|
||||
return (await budgetService.GetListAsync(referenceDate)).Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取预算列表失败");
|
||||
return $"获取预算列表失败: {ex.Message}".Fail<List<BudgetDto>>();
|
||||
return $"获取预算列表失败: {ex.Message}".Fail<List<BudgetResult>>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,29 +28,23 @@ public class BudgetController(
|
||||
/// 获取单个预算统计信息
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<BudgetDto>> GetStatisticsAsync([FromQuery] long id, [FromQuery] DateTime? referenceDate = null)
|
||||
public async Task<BaseResponse<BudgetResult>> GetStatisticsAsync([FromQuery] long id, [FromQuery] DateTime? referenceDate = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id == -1)
|
||||
var result = await budgetService.GetStatisticsAsync(id, referenceDate);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return (await GetVirtualSavingsDtoAsync(BudgetPeriodType.Year, referenceDate))!.Ok();
|
||||
}
|
||||
if (id == -2)
|
||||
{
|
||||
return (await GetVirtualSavingsDtoAsync(BudgetPeriodType.Month, referenceDate))!.Ok();
|
||||
return "预算不存在".Fail<BudgetResult>();
|
||||
}
|
||||
|
||||
var budget = await budgetService.GetByIdAsync(id);
|
||||
if (budget == null) return "预算不存在".Fail<BudgetDto>();
|
||||
|
||||
var currentAmount = await budgetService.CalculateCurrentAmountAsync(budget, referenceDate);
|
||||
return BudgetDto.FromEntity(budget, currentAmount, referenceDate).Ok();
|
||||
return result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取预算统计失败, Id: {Id}", id);
|
||||
return $"获取预算统计失败: {ex.Message}".Fail<BudgetDto>();
|
||||
return $"获取预算统计失败: {ex.Message}".Fail<BudgetResult>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +56,7 @@ public class BudgetController(
|
||||
{
|
||||
try
|
||||
{
|
||||
var success = await budgetService.DeleteAsync(id);
|
||||
var success = await budgetRepository.DeleteAsync(id);
|
||||
return success ? BaseResponse.Done() : "删除预算失败".Fail();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -115,7 +90,7 @@ public class BudgetController(
|
||||
return varidationError.Fail<long>();
|
||||
}
|
||||
|
||||
var success = await budgetService.AddAsync(budget);
|
||||
var success = await budgetRepository.AddAsync(budget);
|
||||
if (success)
|
||||
{
|
||||
return budget.Id.Ok();
|
||||
@@ -137,7 +112,7 @@ public class BudgetController(
|
||||
{
|
||||
try
|
||||
{
|
||||
var budget = await budgetService.GetByIdAsync(dto.Id);
|
||||
var budget = await budgetRepository.GetByIdAsync(dto.Id);
|
||||
if (budget == null) return "预算不存在".Fail();
|
||||
|
||||
budget.Name = dto.Name;
|
||||
@@ -157,7 +132,7 @@ public class BudgetController(
|
||||
return varidationError.Fail();
|
||||
}
|
||||
|
||||
var success = await budgetService.UpdateAsync(budget);
|
||||
var success = await budgetRepository.UpdateAsync(budget);
|
||||
return success ? BaseResponse.Done() : "更新预算失败".Fail();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -167,132 +142,60 @@ public class BudgetController(
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<BudgetDto?> GetVirtualSavingsDtoAsync(
|
||||
BudgetPeriodType periodType,
|
||||
DateTime? referenceDate = null,
|
||||
List<BudgetRecord>? existingBudgets = null)
|
||||
/// <summary>
|
||||
/// 切换预算暂停状态
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse> ToggleStopAsync([FromQuery] long id)
|
||||
{
|
||||
var allBudgets = existingBudgets;
|
||||
|
||||
if(existingBudgets == null)
|
||||
try
|
||||
{
|
||||
allBudgets = await budgetService.GetAllAsync();
|
||||
var budget = await budgetRepository.GetByIdAsync(id);
|
||||
|
||||
if (budget == null)
|
||||
{
|
||||
return "预算不存在".Fail();
|
||||
}
|
||||
|
||||
budget.IsStopped = !budget.IsStopped;
|
||||
|
||||
var success = await budgetRepository.UpdateAsync(budget);
|
||||
return success ? BaseResponse.Done() : "操作失败".Fail();
|
||||
}
|
||||
|
||||
if(allBudgets == null)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
logger.LogError(ex, "切换预算状态失败, Id: {Id}", id);
|
||||
return $"操作失败: {ex.Message}".Fail();
|
||||
}
|
||||
}
|
||||
|
||||
var date = referenceDate ?? DateTime.Now;
|
||||
|
||||
decimal incomeLimitAtPeriod = 0;
|
||||
decimal expenseLimitAtPeriod = 0;
|
||||
|
||||
var incomeItems = new List<(string Name, decimal Limit, decimal Factor, decimal Total)>();
|
||||
var expenseItems = new List<(string Name, decimal Limit, decimal Factor, decimal Total)>();
|
||||
|
||||
foreach (var b in allBudgets)
|
||||
/// <summary>
|
||||
/// 归档预算
|
||||
/// </summary>
|
||||
[HttpPost("{year}/{month}")]
|
||||
public async Task<BaseResponse> ArchiveBudgetsAsync(int year, int month)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (b.IsStopped || b.Category == BudgetCategory.Savings) continue;
|
||||
var msg = await budgetService.ArchiveBudgetsAsync(year, month);
|
||||
|
||||
// 折算系数:根据当前请求的 periodType (Year 或 Month),将预算 b 的 Limit 折算过来
|
||||
decimal factor = 1.0m;
|
||||
|
||||
if (periodType == BudgetPeriodType.Year)
|
||||
if(!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
factor = b.Type switch
|
||||
{
|
||||
BudgetPeriodType.Month => 12,
|
||||
BudgetPeriodType.Year => 1,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
else if (periodType == BudgetPeriodType.Month)
|
||||
{
|
||||
factor = b.Type switch
|
||||
{
|
||||
BudgetPeriodType.Month => 1,
|
||||
BudgetPeriodType.Year => 0,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
factor = 0; // 其他周期暂不计算虚拟存款
|
||||
}
|
||||
|
||||
if (factor <= 0) continue;
|
||||
|
||||
var subtotal = b.Limit * factor;
|
||||
if (b.Category == BudgetCategory.Income)
|
||||
{
|
||||
incomeLimitAtPeriod += subtotal;
|
||||
incomeItems.Add((b.Name, b.Limit, factor, subtotal));
|
||||
}
|
||||
else if (b.Category == BudgetCategory.Expense)
|
||||
{
|
||||
expenseLimitAtPeriod += subtotal;
|
||||
expenseItems.Add((b.Name, b.Limit, factor, subtotal));
|
||||
return msg.Fail();
|
||||
}
|
||||
|
||||
return BaseResponse.Done();
|
||||
}
|
||||
|
||||
var description = new StringBuilder();
|
||||
description.Append("<h3>预算收入明细</h3>");
|
||||
if (incomeItems.Count == 0) description.Append("<p>无收入预算</p>");
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
description.Append("<table><thead><tr><th>名称</th><th>金额</th><th>折算</th><th>合计</th></tr></thead><tbody>");
|
||||
foreach (var item in incomeItems)
|
||||
{
|
||||
description.Append($"<tr><td>{item.Name}</td><td>{item.Limit:N0}</td><td>x{item.Factor:0.##}</td><td><span class='income-value'>{item.Total:N0}</span></td></tr>");
|
||||
}
|
||||
description.Append("</tbody></table>");
|
||||
logger.LogError(ex, "归档预算失败, 归档日期: {Year}-{Month}", year, month);
|
||||
return $"归档预算失败: {ex.Message}".Fail();
|
||||
}
|
||||
description.Append($"<p>收入合计: <span class='income-value'><strong>{incomeLimitAtPeriod:N0}</strong></span></p>");
|
||||
|
||||
description.Append("<h3>预算支出明细</h3>");
|
||||
if (expenseItems.Count == 0) description.Append("<p>无支出预算</p>");
|
||||
else
|
||||
{
|
||||
description.Append("<table><thead><tr><th>名称</th><th>金额</th><th>折算</th><th>合计</th></tr></thead><tbody>");
|
||||
foreach (var item in expenseItems)
|
||||
{
|
||||
description.Append($"<tr><td>{item.Name}</td><td>{item.Limit:N0}</td><td>x{item.Factor:0.##}</td><td><span class='expense-value'>{item.Total:N0}</span></td></tr>");
|
||||
}
|
||||
description.Append("</tbody></table>");
|
||||
}
|
||||
description.Append($"<p>支出合计: <span class='expense-value'><strong>{expenseLimitAtPeriod:N0}</strong></span></p>");
|
||||
|
||||
description.Append("<h3>存款计划结论</h3>");
|
||||
description.Append($"<p>计划存款 = 收入 <span class='income-value'>{incomeLimitAtPeriod:N0}</span> - 支出 <span class='expense-value'>{expenseLimitAtPeriod:N0}</span></p>");
|
||||
description.Append($"<p>最终目标:<span class='highlight'><strong>{incomeLimitAtPeriod - expenseLimitAtPeriod:N0}</strong></span></p>");
|
||||
|
||||
var savingsCategories = await configService.GetConfigByKeyAsync<string>("SavingsCategories") ?? string.Empty;
|
||||
var virtualBudget = new BudgetRecord
|
||||
{
|
||||
Id = periodType == BudgetPeriodType.Year ? -1 : -2,
|
||||
Name = periodType == BudgetPeriodType.Year ? "年度存款" : "月度存款",
|
||||
Category = BudgetCategory.Savings,
|
||||
Type = periodType,
|
||||
Limit = incomeLimitAtPeriod - expenseLimitAtPeriod,
|
||||
StartDate = periodType == BudgetPeriodType.Year ? new DateTime(date.Year, 1, 1) : new DateTime(date.Year, date.Month, 1),
|
||||
SelectedCategories = savingsCategories
|
||||
};
|
||||
|
||||
// 计算实际发生的 收入 - 支出
|
||||
var incomeHelper = new BudgetRecord { Category = BudgetCategory.Income, Type = periodType, StartDate = virtualBudget.StartDate, SelectedCategories = savingsCategories };
|
||||
var expenseHelper = new BudgetRecord { Category = BudgetCategory.Expense, Type = periodType, StartDate = virtualBudget.StartDate, SelectedCategories = savingsCategories };
|
||||
|
||||
var actualIncome = await budgetService.CalculateCurrentAmountAsync(incomeHelper, date);
|
||||
var actualExpense = await budgetService.CalculateCurrentAmountAsync(expenseHelper, date);
|
||||
|
||||
return BudgetDto.FromEntity(virtualBudget, actualIncome - actualExpense, date, description.ToString());
|
||||
}
|
||||
|
||||
private async Task<string> ValidateBudgetSelectedCategoriesAsync(BudgetRecord record)
|
||||
{
|
||||
var allBudgets = await budgetService.GetAllAsync();
|
||||
var allBudgets = await budgetRepository.GetAllAsync();
|
||||
|
||||
var recordSelectedCategories = record.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var budget in allBudgets)
|
||||
@@ -310,23 +213,4 @@ public class BudgetController(
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换预算暂停状态
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse> ToggleStopAsync([FromQuery] long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var success = await budgetService.ToggleStopAsync(id);
|
||||
return success ? BaseResponse.Done() : "操作失败".Fail();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "切换预算状态失败, Id: {Id}", id);
|
||||
return $"操作失败: {ex.Message}".Fail();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,57 +1,5 @@
|
||||
namespace WebApi.Controllers.Dto;
|
||||
|
||||
public class BudgetDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public BudgetPeriodType Type { get; set; }
|
||||
public decimal Limit { get; set; }
|
||||
public decimal Current { get; set; }
|
||||
public BudgetCategory Category { get; set; }
|
||||
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
|
||||
public bool IsStopped { get; set; }
|
||||
public string StartDate { get; set; } = string.Empty;
|
||||
public string Period { get; set; } = string.Empty;
|
||||
public DateTime? PeriodStart { get; set; }
|
||||
public DateTime? PeriodEnd { get; set; }
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public static BudgetDto FromEntity(
|
||||
BudgetRecord entity,
|
||||
decimal currentAmount = 0,
|
||||
DateTime? referenceDate = null,
|
||||
string description = "")
|
||||
{
|
||||
var date = referenceDate ?? DateTime.Now;
|
||||
var (start, end) = BudgetService.GetPeriodRange(entity.StartDate, entity.Type, date);
|
||||
|
||||
return new BudgetDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
Name = entity.Name,
|
||||
Type = entity.Type,
|
||||
Limit = entity.Limit,
|
||||
Current = currentAmount,
|
||||
Category = entity.Category,
|
||||
SelectedCategories = string.IsNullOrEmpty(entity.SelectedCategories)
|
||||
? Array.Empty<string>()
|
||||
: entity.SelectedCategories.Split(','),
|
||||
IsStopped = entity.IsStopped,
|
||||
StartDate = entity.StartDate.ToString("yyyy-MM-dd"),
|
||||
Period = entity.Type switch
|
||||
{
|
||||
BudgetPeriodType.Year => $"{start:yy}年",
|
||||
BudgetPeriodType.Month => $"{start:yy}年第{start.Month}月",
|
||||
_ => $"{start:yyyy-MM-dd} ~ {end:yyyy-MM-dd}"
|
||||
},
|
||||
PeriodStart = start,
|
||||
PeriodEnd = end,
|
||||
Description = description
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateBudgetDto
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
114
WebApi/Controllers/JobController.cs
Normal file
114
WebApi/Controllers/JobController.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using Quartz;
|
||||
|
||||
namespace WebApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class JobController(ISchedulerFactory schedulerFactory, ILogger<JobController> logger) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<BaseResponse<List<JobStatus>>> GetJobsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var scheduler = await schedulerFactory.GetScheduler();
|
||||
var jobKeys = await scheduler.GetJobKeys(Quartz.Impl.Matchers.GroupMatcher<JobKey>.AnyGroup());
|
||||
var jobStatuses = new List<JobStatus>();
|
||||
|
||||
foreach (var jobKey in jobKeys)
|
||||
{
|
||||
var jobDetail = await scheduler.GetJobDetail(jobKey);
|
||||
var triggers = await scheduler.GetTriggersOfJob(jobKey);
|
||||
var trigger = triggers.FirstOrDefault();
|
||||
|
||||
var status = "Unknown";
|
||||
DateTime? nextFireTime = null;
|
||||
|
||||
if (trigger != null)
|
||||
{
|
||||
var triggerState = await scheduler.GetTriggerState(trigger.Key);
|
||||
status = triggerState.ToString();
|
||||
nextFireTime = trigger.GetNextFireTimeUtc()?.ToLocalTime().DateTime;
|
||||
}
|
||||
|
||||
jobStatuses.Add(new JobStatus
|
||||
{
|
||||
Name = jobKey.Name,
|
||||
JobDescription = jobDetail?.Description ?? jobKey.Name,
|
||||
TriggerDescription = trigger?.Description ?? string.Empty,
|
||||
Status = status,
|
||||
NextRunTime = nextFireTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? "无"
|
||||
});
|
||||
}
|
||||
|
||||
return jobStatuses.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取任务列表失败");
|
||||
return $"获取任务列表失败: {ex.Message}".Fail<List<JobStatus>>();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<bool>> ExecuteAsync([FromBody] JobRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var scheduler = await schedulerFactory.GetScheduler();
|
||||
await scheduler.TriggerJob(new JobKey(request.JobName));
|
||||
return true.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "执行任务失败: {JobName}", request.JobName);
|
||||
return $"执行任务失败: {ex.Message}".Fail<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<bool>> PauseAsync([FromBody] JobRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var scheduler = await schedulerFactory.GetScheduler();
|
||||
await scheduler.PauseJob(new JobKey(request.JobName));
|
||||
return true.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "暂停任务失败: {JobName}", request.JobName);
|
||||
return $"暂停任务失败: {ex.Message}".Fail<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<bool>> ResumeAsync([FromBody] JobRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var scheduler = await schedulerFactory.GetScheduler();
|
||||
await scheduler.ResumeJob(new JobKey(request.JobName));
|
||||
return true.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "恢复任务失败: {JobName}", request.JobName);
|
||||
return $"恢复任务失败: {ex.Message}".Fail<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
public class JobStatus
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string JobDescription { get; set; } = string.Empty;
|
||||
public string TriggerDescription { get; set; } = string.Empty;
|
||||
public string Status { get; set; } = string.Empty;
|
||||
public string NextRunTime { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class JobRequest
|
||||
{
|
||||
public string JobName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,9 @@ public static class Expand
|
||||
|
||||
// 配置邮件同步任务 - 每10分钟执行一次
|
||||
var emailJobKey = new JobKey("EmailSyncJob");
|
||||
q.AddJob<Service.Jobs.EmailSyncJob>(opts => opts.WithIdentity(emailJobKey));
|
||||
q.AddJob<Service.Jobs.EmailSyncJob>(opts => opts
|
||||
.WithIdentity(emailJobKey)
|
||||
.WithDescription("邮件同步任务"));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(emailJobKey)
|
||||
.WithIdentity("EmailSyncTrigger")
|
||||
@@ -22,12 +24,25 @@ public static class Expand
|
||||
|
||||
// 配置周期性账单任务 - 每天早上6点执行
|
||||
var periodicBillJobKey = new JobKey("PeriodicBillJob");
|
||||
q.AddJob<Service.Jobs.PeriodicBillJob>(opts => opts.WithIdentity(periodicBillJobKey));
|
||||
q.AddJob<Service.Jobs.PeriodicBillJob>(opts => opts
|
||||
.WithIdentity(periodicBillJobKey)
|
||||
.WithDescription("周期性账单任务"));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(periodicBillJobKey)
|
||||
.WithIdentity("PeriodicBillTrigger")
|
||||
.WithCronSchedule("0 0 6 * * ?") // 每天早上6点执行
|
||||
.WithDescription("每天早上6点执行周期性账单检查"));
|
||||
.WithDescription("每天早上6点执行周期性账单任务"));
|
||||
|
||||
// 配置预算归档任务 - 每个月1号晚11点执行
|
||||
var budgetArchiveJobKey = new JobKey("BudgetArchiveJob");
|
||||
q.AddJob<Service.Jobs.BudgetArchiveJob>(opts => opts
|
||||
.WithIdentity(budgetArchiveJobKey)
|
||||
.WithDescription("预算归档任务"));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(budgetArchiveJobKey)
|
||||
.WithIdentity("BudgetArchiveTrigger")
|
||||
.WithCronSchedule("0 0 23 1 * ?") // 每个月1号晚11点执行
|
||||
.WithDescription("每个月1号晚11点执行预算归档"));
|
||||
});
|
||||
|
||||
// 添加 Quartz Hosted Service
|
||||
|
||||
Reference in New Issue
Block a user