1
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 23s
Docker Build & Deploy / Deploy to Production (push) Successful in 6s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s

This commit is contained in:
SunCheng
2026-02-19 22:44:26 +08:00
parent 6922dff5a9
commit 2cf19a45e5
14 changed files with 583 additions and 55 deletions

View File

@@ -595,27 +595,46 @@ public class BudgetStatsService(
logger.LogDebug("开始处理当前及未来月份预算");
foreach (var budget in currentBudgetsDict.Values)
{
// 对于年度预算,如果还没有从归档中添加,则添加
if (budget.Type == BudgetPeriodType.Year && !processedBudgetIds.Contains(budget.Id))
// 对于年度预算,需要实时计算当前金额
if (budget.Type == BudgetPeriodType.Year)
{
var currentAmount = await CalculateCurrentAmountAsync(budget, statType, referenceDate);
result.Add(new BudgetStatsItem
// 如果已经从归档中添加过需要更新其Current值为实时计算的金额
if (processedBudgetIds.Contains(budget.Id))
{
Id = budget.Id,
Name = budget.Name,
Type = budget.Type,
Limit = budget.Limit,
Current = currentAmount,
Category = budget.Category,
SelectedCategories = string.IsNullOrEmpty(budget.SelectedCategories)
? []
: budget.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries),
NoLimit = budget.NoLimit,
IsMandatoryExpense = budget.IsMandatoryExpense,
IsArchive = false
});
logger.LogInformation("添加当前年度预算: {BudgetName} - 预算金额: {Limit}, 实际金额: {Current}",
budget.Name, budget.Limit, currentAmount);
var realTimeAmount = await CalculateCurrentAmountAsync(budget, statType, referenceDate);
var existingItem = result.FirstOrDefault(r => r.Id == budget.Id && r.Type == BudgetPeriodType.Year);
if (existingItem != null)
{
// 更新Current为实时金额而不是归档的Actual
result.Remove(existingItem);
result.Add(existingItem with { Current = realTimeAmount, IsArchive = false });
logger.LogInformation("更新年度预算实时金额: {BudgetName} - 归档金额: {ArchiveAmount}, 实时金额: {RealtimeAmount}",
budget.Name, existingItem.Current, realTimeAmount);
}
}
else
{
// 如果没有从归档中添加,则新增
var currentAmount = await CalculateCurrentAmountAsync(budget, statType, referenceDate);
result.Add(new BudgetStatsItem
{
Id = budget.Id,
Name = budget.Name,
Type = budget.Type,
Limit = budget.Limit,
Current = currentAmount,
Category = budget.Category,
SelectedCategories = string.IsNullOrEmpty(budget.SelectedCategories)
? []
: budget.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries),
NoLimit = budget.NoLimit,
IsMandatoryExpense = budget.IsMandatoryExpense,
IsArchive = false
});
logger.LogInformation("添加当前年度预算: {BudgetName} - 预算金额: {Limit}, 实际金额: {Current}",
budget.Name, budget.Limit, currentAmount);
processedBudgetIds.Add(budget.Id);
}
}
// 对于月度预算,仅添加当前月的预算项(如果还没有从归档中添加)
else if (budget.Type == BudgetPeriodType.Month)