feat: 添加分类统计功能,支持获取月度和年度预算统计信息
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 22s
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

This commit is contained in:
孙诚
2026-01-09 15:42:59 +08:00
parent b41121400d
commit 2244d08b43
9 changed files with 524 additions and 177 deletions

View File

@@ -15,7 +15,14 @@ public class BudgetController(
{
try
{
return (await budgetService.GetListAsync(referenceDate)).Ok();
return (await budgetService.GetListAsync(referenceDate))
.OrderBy(b => b.IsStopped)
.OrderBy(b => b.Category)
.ThenBy(b => b.Type)
.ThenByDescending(b => b.Current / b.Limit)
.ThenBy(b => b.Name)
.ToList()
.Ok();
}
catch (Exception ex)
{
@@ -48,6 +55,24 @@ public class BudgetController(
}
}
/// <summary>
/// 获取分类统计信息(月度和年度)
/// </summary>
[HttpGet]
public async Task<BaseResponse<BudgetCategoryStats>> GetCategoryStatsAsync([FromQuery] BudgetCategory category, [FromQuery] DateTime? referenceDate = null)
{
try
{
var result = await budgetService.GetCategoryStatsAsync(category, referenceDate);
return result.Ok();
}
catch (Exception ex)
{
logger.LogError(ex, "获取分类统计失败, Category: {Category}", category);
return $"获取分类统计失败: {ex.Message}".Fail<BudgetCategoryStats>();
}
}
/// <summary>
/// 删除预算
/// </summary>