2026-02-10 17:49:19 +08:00
|
|
|
using Application;
|
|
|
|
|
using Application.Dto;
|
2026-01-19 13:39:59 +08:00
|
|
|
|
|
|
|
|
namespace WebApi.Controllers;
|
2026-01-06 21:15:02 +08:00
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
public class BudgetController(
|
2026-02-10 17:49:19 +08:00
|
|
|
IBudgetApplication budgetApplication
|
|
|
|
|
) : ControllerBase
|
2026-01-06 21:15:02 +08:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取预算列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse<List<BudgetResponse>>> GetListAsync([FromQuery] DateTime referenceDate)
|
2026-01-06 21:15:02 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var result = await budgetApplication.GetListAsync(referenceDate);
|
|
|
|
|
return result.Ok();
|
2026-01-06 21:15:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-01-12 22:29:39 +08:00
|
|
|
/// 获取分类统计信息(月度和年度)
|
2026-01-06 21:15:02 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse<BudgetCategoryStatsResponse>> GetCategoryStatsAsync([FromQuery] BudgetCategory category, [FromQuery] DateTime referenceDate)
|
2026-01-06 21:15:02 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var result = await budgetApplication.GetCategoryStatsAsync(category, referenceDate);
|
|
|
|
|
return result.Ok();
|
2026-01-06 21:15:02 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 15:42:59 +08:00
|
|
|
/// <summary>
|
2026-01-12 22:29:39 +08:00
|
|
|
/// 获取未被预算覆盖的分类统计信息
|
2026-01-09 15:42:59 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse<List<UncoveredCategoryResponse>>> GetUncoveredCategoriesAsync([FromQuery] BudgetCategory category, [FromQuery] DateTime? referenceDate = null)
|
2026-01-09 15:42:59 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var result = await budgetApplication.GetUncoveredCategoriesAsync(category, referenceDate);
|
|
|
|
|
return result.Ok();
|
2026-01-09 15:42:59 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-11 12:33:12 +08:00
|
|
|
/// <summary>
|
2026-01-12 22:29:39 +08:00
|
|
|
/// 获取归档总结
|
2026-01-11 12:33:12 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2026-01-12 22:29:39 +08:00
|
|
|
public async Task<BaseResponse<string?>> GetArchiveSummaryAsync([FromQuery] DateTime referenceDate)
|
2026-01-11 12:33:12 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var result = await budgetApplication.GetArchiveSummaryAsync(referenceDate);
|
|
|
|
|
return result.Ok<string?>();
|
2026-01-12 22:29:39 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-15 20:00:41 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 获取指定周期的存款预算信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse<BudgetResponse?>> GetSavingsBudgetAsync(int year, int month, BudgetPeriodType type)
|
2026-01-15 20:00:41 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var result = await budgetApplication.GetSavingsBudgetAsync(year, month, type);
|
|
|
|
|
return result.Ok();
|
2026-01-15 20:00:41 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-07 19:19:53 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 删除预算
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public async Task<BaseResponse> DeleteByIdAsync(long id)
|
|
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
await budgetApplication.DeleteByIdAsync(id);
|
|
|
|
|
return BaseResponse.Done();
|
2026-01-07 19:19:53 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-06 21:15:02 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 创建预算
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse<long>> CreateAsync([FromBody] CreateBudgetRequest request)
|
2026-01-06 21:15:02 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
var budgetId = await budgetApplication.CreateAsync(request);
|
|
|
|
|
return budgetId.Ok();
|
2026-01-06 21:15:02 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-07 17:33:50 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 更新预算
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
2026-02-10 17:49:19 +08:00
|
|
|
public async Task<BaseResponse> UpdateAsync([FromBody] UpdateBudgetRequest request)
|
2026-01-07 17:33:50 +08:00
|
|
|
{
|
2026-02-10 17:49:19 +08:00
|
|
|
await budgetApplication.UpdateAsync(request);
|
|
|
|
|
return BaseResponse.Done();
|
2026-01-07 19:19:53 +08:00
|
|
|
}
|
2026-01-06 21:15:02 +08:00
|
|
|
}
|