fix
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 31s
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-02-01 10:27:04 +08:00
parent 704f58b1a1
commit 61916dc6da
7 changed files with 810 additions and 310 deletions

View File

@@ -426,6 +426,7 @@ public class BudgetSavingsService(
// 归档的预算收入支出明细
var archiveIncomeItems = new List<(long id, string name, int[] months, decimal limit, decimal current)>();
var archiveExpenseItems = new List<(long id, string name, int[] months, decimal limit, decimal current)>();
var archiveSavingsItems = new List<(long id, string name, int[] months, decimal limit, decimal current)>();
// 获取归档数据
var archives = await budgetArchiveRepository.GetArchivesByYearAsync(year);
var archiveBudgetGroups = archives
@@ -440,6 +441,7 @@ public class BudgetSavingsService(
{
BudgetCategory.Income => archiveIncomeItems,
BudgetCategory.Expense => archiveExpenseItems,
BudgetCategory.Savings => archiveSavingsItems,
_ => throw new NotSupportedException($"Category {archive.Category} is not supported.")
};
@@ -663,7 +665,62 @@ public class BudgetSavingsService(
""");
}
#endregion
#region
var archiveSavingsDiff = 0m;
if (archiveSavingsItems.Any())
{
description.AppendLine("<h3>已归档存款明细</h3>");
description.AppendLine("""
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
""");
// 已归档的存款
foreach (var (_, name, months, limit, current) in archiveSavingsItems)
{
description.AppendLine($"""
<tr>
<td>{name}</td>
<td>{(limit == 0 ? "" : limit.ToString("N0"))}</td>
<td>{FormatMonths(months)}</td>
<td>{limit * months.Length:N0}</td>
<td><span class='income-value'>{current:N0}</span></td>
</tr>
""");
}
description.AppendLine("</tbody></table>");
archiveSavingsDiff = archiveSavingsItems.Sum(i => i.current) - archiveSavingsItems.Sum(i => i.limit * i.months.Length);
description.AppendLine($"""
<p>
<span class="highlight">已归档存款总结: </span>
{(archiveSavingsDiff > 0 ? "超额存款" : "未达预期")}:
<span class='{(archiveSavingsDiff > 0 ? "income-value" : "expense-value")}'>
<strong>{archiveSavingsDiff:N0}</strong>
</span>
=
:
<span class='income-value'>
<strong>{archiveSavingsItems.Sum(i => i.current):N0}</strong>
</span>
-
:
<span class='income-value'>
<strong>{archiveSavingsItems.Sum(i => i.limit * i.months.Length):N0}</strong>
</span>
</p>
""");
}
#endregion
#region
description.AppendLine("<h3>预算支出明细</h3>");
description.AppendLine("""
@@ -723,7 +780,10 @@ public class BudgetSavingsService(
#region
var archiveIncomeBudget = archiveIncomeItems.Sum(i => i.limit * i.months.Length);
var archiveExpenseBudget = archiveExpenseItems.Sum(i => i.limit * i.months.Length);
var archiveSavings = archiveIncomeBudget - archiveExpenseBudget + archiveIncomeDiff + archiveExpenseDiff;
// 如果有归档存款数据,直接使用;否则用收入-支出计算
var archiveSavings = archiveSavingsItems.Any()
? archiveSavingsItems.Sum(i => i.current)
: archiveIncomeBudget - archiveExpenseBudget + archiveIncomeDiff + archiveExpenseDiff;
var expectedIncome = currentMonthlyIncomeItems.Sum(i => i.limit == 0 ? i.current : i.limit * i.factor) + currentYearlyIncomeItems.Sum(i => i.isMandatory || i.limit == 0 ? i.current : i.limit);
var expectedExpense = currentMonthlyExpenseItems.Sum(i => i.limit == 0 ? i.current : i.limit * i.factor) + currentYearlyExpenseItems.Sum(i => i.isMandatory || i.limit == 0 ? i.current : i.limit);