Files
EmailBill/Application/Dto/BudgetDto.cs
SunCheng 4cc205fc25 feat(budget): 实现存款明细计算核心逻辑
- 添加 BudgetItemCalculator 辅助类,实现明细项计算规则
  - 收入:实际>0取实际,否则取预算
  - 支出:取MAX(预算, 实际)
  - 硬性支出未发生:按天数折算
  - 归档数据:直接使用实际值

- 实现月度和年度存款核心公式
  - 月度:收入预算 + 本月年度收入 - 支出预算 - 本月年度支出
  - 年度:归档已实收 + 未来收入预算 - 归档已实支 - 未来支出预算

- 定义存款明细数据结构
  - SavingsDetail: 包含收入/支出明细列表和汇总
  - BudgetDetailItem: 预算明细项(含计算用金额、计算说明等)
  - SavingsCalculationSummary: 计算汇总信息

- 新增单元测试
  - BudgetItemCalculatorTest: 11个测试覆盖所有计算规则
  - BudgetSavingsCalculationTest: 6个测试验证核心公式

测试结果:所有测试通过 (366 passed, 0 failed)
2026-02-20 16:26:04 +08:00

130 lines
3.8 KiB
C#

namespace Application.Dto;
/// <summary>
/// 预算响应
/// </summary>
public record BudgetResponse
{
public long Id { get; init; }
public string Name { get; init; } = string.Empty;
public BudgetPeriodType Type { get; init; }
public decimal Limit { get; init; }
public decimal Current { get; init; }
public BudgetCategory Category { get; init; }
public string[] SelectedCategories { get; init; } = [];
public DateTime StartDate { get; init; }
public bool NoLimit { get; init; }
public bool IsMandatoryExpense { get; init; }
public decimal UsagePercentage { get; init; }
}
/// <summary>
/// 创建预算请求
/// </summary>
public record CreateBudgetRequest
{
public string Name { get; init; } = string.Empty;
public BudgetPeriodType Type { get; init; } = BudgetPeriodType.Month;
public decimal Limit { get; init; }
public BudgetCategory Category { get; init; }
public string[] SelectedCategories { get; init; } = [];
public DateTime? StartDate { get; init; }
public bool NoLimit { get; init; }
public bool IsMandatoryExpense { get; init; }
}
/// <summary>
/// 更新预算请求
/// </summary>
public record UpdateBudgetRequest
{
public long Id { get; init; }
public string Name { get; init; } = string.Empty;
public BudgetPeriodType Type { get; init; } = BudgetPeriodType.Month;
public decimal Limit { get; init; }
public BudgetCategory Category { get; init; }
public string[] SelectedCategories { get; init; } = [];
public DateTime? StartDate { get; init; }
public bool NoLimit { get; init; }
public bool IsMandatoryExpense { get; init; }
}
/// <summary>
/// 分类统计响应
/// </summary>
public record BudgetCategoryStatsResponse
{
public BudgetStatsDetail Month { get; init; } = new();
public BudgetStatsDetail Year { get; init; } = new();
}
/// <summary>
/// 统计详情
/// </summary>
public record BudgetStatsDetail
{
public decimal Limit { get; init; }
public decimal Current { get; init; }
public decimal Remaining { get; init; }
public decimal UsagePercentage { get; init; }
public List<decimal?> Trend { get; init; } = [];
public string Description { get; init; } = string.Empty;
}
/// <summary>
/// 未覆盖分类响应
/// </summary>
public record UncoveredCategoryResponse
{
public string Category { get; init; } = string.Empty;
public decimal Amount { get; init; }
public int Count { get; init; }
}
/// <summary>
/// 更新归档总结请求
/// </summary>
public record UpdateArchiveSummaryRequest
{
public DateTime ReferenceDate { get; init; }
public string? Summary { get; init; }
}
/// <summary>
/// 存款明细数据
/// </summary>
public record SavingsDetail
{
public List<BudgetDetailItem> IncomeItems { get; init; } = new();
public List<BudgetDetailItem> ExpenseItems { get; init; } = new();
public SavingsCalculationSummary Summary { get; init; } = new();
}
/// <summary>
/// 预算明细项
/// </summary>
public record BudgetDetailItem
{
public long Id { get; init; }
public string Name { get; init; } = string.Empty;
public BudgetPeriodType Type { get; init; }
public decimal BudgetLimit { get; init; }
public decimal ActualAmount { get; init; }
public decimal EffectiveAmount { get; init; }
public string CalculationNote { get; init; } = string.Empty;
public bool IsOverBudget { get; init; }
public bool IsArchived { get; init; }
public int[]? ArchivedMonths { get; init; }
}
/// <summary>
/// 存款计算汇总
/// </summary>
public record SavingsCalculationSummary
{
public decimal TotalIncomeBudget { get; init; }
public decimal TotalExpenseBudget { get; init; }
public decimal PlannedSavings { get; init; }
public string CalculationFormula { get; init; } = string.Empty;
}