182 lines
6.1 KiB
C#
182 lines
6.1 KiB
C#
using Application.Dto.Statistics;
|
||
using Application;
|
||
|
||
namespace WebApi.Controllers;
|
||
|
||
/// <summary>
|
||
/// 交易统计控制器
|
||
/// </summary>
|
||
[ApiController]
|
||
[Route("api/[controller]/[action]")]
|
||
public class TransactionStatisticsController(
|
||
ITransactionStatisticsApplication statisticsApplication
|
||
) : ControllerBase
|
||
{
|
||
// ===== 新统一接口(推荐使用) =====
|
||
|
||
/// <summary>
|
||
/// 按日期范围获取每日统计(新统一接口)
|
||
/// </summary>
|
||
/// <param name="startDate">开始日期(包含)</param>
|
||
/// <param name="endDate">结束日期(不包含)</param>
|
||
/// <param name="savingClassify">储蓄分类(可选,不传则使用系统配置)</param>
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<DailyStatisticsDto>>> GetDailyStatisticsByRangeAsync(
|
||
[FromQuery] DateTime startDate,
|
||
[FromQuery] DateTime endDate,
|
||
[FromQuery] string? savingClassify = null
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetDailyStatisticsByRangeAsync(startDate, endDate, savingClassify);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按日期范围获取汇总统计(新统一接口)
|
||
/// </summary>
|
||
/// <param name="startDate">开始日期(包含)</param>
|
||
/// <param name="endDate">结束日期(不包含)</param>
|
||
[HttpGet]
|
||
public async Task<BaseResponse<Service.Transaction.MonthlyStatistics>> GetSummaryByRangeAsync(
|
||
[FromQuery] DateTime startDate,
|
||
[FromQuery] DateTime endDate
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetSummaryByRangeAsync(startDate, endDate);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按日期范围获取分类统计(新统一接口)
|
||
/// </summary>
|
||
/// <param name="startDate">开始日期(包含)</param>
|
||
/// <param name="endDate">结束日期(不包含)</param>
|
||
/// <param name="type">交易类型</param>
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<Service.Transaction.CategoryStatistics>>> GetCategoryStatisticsByRangeAsync(
|
||
[FromQuery] DateTime startDate,
|
||
[FromQuery] DateTime endDate,
|
||
[FromQuery] TransactionType type
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetCategoryStatisticsByRangeAsync(startDate, endDate, type);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取趋势统计数据
|
||
/// </summary>
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<Service.Transaction.TrendStatistics>>> GetTrendStatisticsAsync(
|
||
[FromQuery] int startYear,
|
||
[FromQuery] int startMonth,
|
||
[FromQuery] int monthCount = 6
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetTrendStatisticsAsync(startYear, startMonth, monthCount);
|
||
return result.Ok();
|
||
}
|
||
|
||
// ===== 旧接口(保留用于向后兼容,已标记为过时) =====
|
||
|
||
/// <summary>
|
||
/// 获取累积余额统计数据(用于余额卡片图表)
|
||
/// </summary>
|
||
[Obsolete("请使用 GetDailyStatisticsByRangeAsync 并在前端计算累积余额")]
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<BalanceStatisticsDto>>> GetBalanceStatisticsAsync(
|
||
[FromQuery] int year,
|
||
[FromQuery] int month
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetBalanceStatisticsAsync(year, month);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取指定月份每天的消费统计
|
||
/// </summary>
|
||
[Obsolete("请使用 GetDailyStatisticsByRangeAsync")]
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<DailyStatisticsDto>>> GetDailyStatisticsAsync(
|
||
[FromQuery] int year,
|
||
[FromQuery] int month
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetDailyStatisticsAsync(year, month);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取周统计数据
|
||
/// </summary>
|
||
[Obsolete("请使用 GetDailyStatisticsByRangeAsync")]
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<DailyStatisticsDto>>> GetWeeklyStatisticsAsync(
|
||
[FromQuery] DateTime startDate,
|
||
[FromQuery] DateTime endDate
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetWeeklyStatisticsAsync(startDate, endDate);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取指定日期范围的统计汇总数据
|
||
/// </summary>
|
||
[Obsolete("请使用 GetSummaryByRangeAsync")]
|
||
[HttpGet]
|
||
public async Task<BaseResponse<Service.Transaction.MonthlyStatistics>> GetRangeStatisticsAsync(
|
||
[FromQuery] DateTime startDate,
|
||
[FromQuery] DateTime endDate
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetRangeStatisticsAsync(startDate, endDate);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取月度统计数据
|
||
/// </summary>
|
||
[Obsolete("请使用 GetSummaryByRangeAsync")]
|
||
[HttpGet]
|
||
public async Task<BaseResponse<Service.Transaction.MonthlyStatistics>> GetMonthlyStatisticsAsync(
|
||
[FromQuery] int year,
|
||
[FromQuery] int month
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetMonthlyStatisticsAsync(year, month);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取分类统计数据
|
||
/// </summary>
|
||
[Obsolete("请使用 GetCategoryStatisticsByRangeAsync")]
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<Service.Transaction.CategoryStatistics>>> GetCategoryStatisticsAsync(
|
||
[FromQuery] int year,
|
||
[FromQuery] int month,
|
||
[FromQuery] TransactionType type
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetCategoryStatisticsAsync(year, month, type);
|
||
return result.Ok();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按日期范围获取分类统计数据
|
||
/// </summary>
|
||
[Obsolete("请使用 GetCategoryStatisticsByRangeAsync(DateTime 参数版本)")]
|
||
[HttpGet]
|
||
public async Task<BaseResponse<List<Service.Transaction.CategoryStatistics>>> GetCategoryStatisticsByDateRangeAsync(
|
||
[FromQuery] string startDate,
|
||
[FromQuery] string endDate,
|
||
[FromQuery] TransactionType type
|
||
)
|
||
{
|
||
var result = await statisticsApplication.GetCategoryStatisticsByDateRangeAsync(startDate, endDate, type);
|
||
return result.Ok();
|
||
}
|
||
}
|