1
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 20s
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
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 20s
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:
@@ -676,17 +676,18 @@ public class BudgetStatsService(
|
|||||||
logger.LogInformation("添加当前年度预算: {BudgetName} - 预算金额: {Limit}, 实际金额: {Current}",
|
logger.LogInformation("添加当前年度预算: {BudgetName} - 预算金额: {Limit}, 实际金额: {Current}",
|
||||||
budget.Name, budget.Limit, currentAmount);
|
budget.Name, budget.Limit, currentAmount);
|
||||||
}
|
}
|
||||||
// 对于月度预算,添加当前及未来月份的预算(标记剩余月份数)
|
// 对于月度预算,仅添加当前月的预算项
|
||||||
else if (budget.Type == BudgetPeriodType.Month)
|
else if (budget.Type == BudgetPeriodType.Month)
|
||||||
{
|
{
|
||||||
var remainingMonths = 12 - now.Month + 1; // 包括当前月
|
// 只计算当前月的实际值
|
||||||
|
var currentAmount = await CalculateCurrentAmountAsync(budget, BudgetPeriodType.Month, referenceDate);
|
||||||
result.Add(new BudgetStatsItem
|
result.Add(new BudgetStatsItem
|
||||||
{
|
{
|
||||||
Id = budget.Id,
|
Id = budget.Id,
|
||||||
Name = budget.Name,
|
Name = budget.Name,
|
||||||
Type = budget.Type,
|
Type = budget.Type,
|
||||||
Limit = budget.Limit,
|
Limit = budget.Limit, // 月度预算的原始限额
|
||||||
Current = 0, // 剩余月份不计算实际值
|
Current = currentAmount, // 当前月的实际值
|
||||||
Category = budget.Category,
|
Category = budget.Category,
|
||||||
SelectedCategories = string.IsNullOrEmpty(budget.SelectedCategories)
|
SelectedCategories = string.IsNullOrEmpty(budget.SelectedCategories)
|
||||||
? []
|
? []
|
||||||
@@ -694,10 +695,37 @@ public class BudgetStatsService(
|
|||||||
NoLimit = budget.NoLimit,
|
NoLimit = budget.NoLimit,
|
||||||
IsMandatoryExpense = budget.IsMandatoryExpense,
|
IsMandatoryExpense = budget.IsMandatoryExpense,
|
||||||
IsArchive = false,
|
IsArchive = false,
|
||||||
RemainingMonths = remainingMonths
|
// 标记这是当前月的月度预算,用于年度限额计算
|
||||||
|
IsCurrentMonth = true
|
||||||
});
|
});
|
||||||
logger.LogInformation("添加当前月度预算(剩余月份): {BudgetName} - 预算金额: {Limit}, 剩余月份: {RemainingMonths}",
|
logger.LogInformation("添加当前月的月度预算: {BudgetName} - 月度限额: {Limit}, 当前月实际值: {Current}",
|
||||||
budget.Name, budget.Limit, remainingMonths);
|
budget.Name, budget.Limit, currentAmount);
|
||||||
|
|
||||||
|
// 如果还有剩余月份(未来月份),再添加一项作为未来的预算占位
|
||||||
|
var remainingMonths = 12 - now.Month;
|
||||||
|
if (remainingMonths > 0)
|
||||||
|
{
|
||||||
|
var futureLimit = budget.Limit * remainingMonths;
|
||||||
|
result.Add(new BudgetStatsItem
|
||||||
|
{
|
||||||
|
Id = budget.Id,
|
||||||
|
Name = budget.Name,
|
||||||
|
Type = budget.Type,
|
||||||
|
Limit = budget.Limit, // 月度预算的原始限额(用于描述时计算)
|
||||||
|
Current = 0, // 未来月份无实际值
|
||||||
|
Category = budget.Category,
|
||||||
|
SelectedCategories = string.IsNullOrEmpty(budget.SelectedCategories)
|
||||||
|
? []
|
||||||
|
: budget.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries),
|
||||||
|
NoLimit = budget.NoLimit,
|
||||||
|
IsMandatoryExpense = budget.IsMandatoryExpense,
|
||||||
|
IsArchive = false,
|
||||||
|
IsCurrentMonth = false,
|
||||||
|
RemainingMonths = remainingMonths
|
||||||
|
});
|
||||||
|
logger.LogInformation("添加未来月份的月度预算: {BudgetName} - 月度限额: {Limit}, 剩余月份: {RemainingMonths}",
|
||||||
|
budget.Name, budget.Limit, remainingMonths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -841,6 +869,12 @@ public class BudgetStatsService(
|
|||||||
itemLimit = budget.Limit;
|
itemLimit = budget.Limit;
|
||||||
algorithmDescription = $"归档月度预算: 直接使用归档限额 {budget.Limit}";
|
algorithmDescription = $"归档月度预算: 直接使用归档限额 {budget.Limit}";
|
||||||
}
|
}
|
||||||
|
// 对于当前月的月度预算,直接使用原始限额
|
||||||
|
else if (budget.IsCurrentMonth)
|
||||||
|
{
|
||||||
|
itemLimit = budget.Limit;
|
||||||
|
algorithmDescription = $"当前月的月度预算: 直接使用月度限额 {budget.Limit}";
|
||||||
|
}
|
||||||
// 对于当前及未来月份的预算,使用剩余月份折算
|
// 对于当前及未来月份的预算,使用剩余月份折算
|
||||||
else if (budget.RemainingMonths > 0)
|
else if (budget.RemainingMonths > 0)
|
||||||
{
|
{
|
||||||
@@ -1082,6 +1116,7 @@ public class BudgetStatsService(
|
|||||||
public bool IsArchive { get; set; }
|
public bool IsArchive { get; set; }
|
||||||
public int ArchiveMonth { get; set; } // 归档月份(1-12),用于标识归档数据来自哪个月
|
public int ArchiveMonth { get; set; } // 归档月份(1-12),用于标识归档数据来自哪个月
|
||||||
public int RemainingMonths { get; set; } // 剩余月份数,用于年度统计时的月度预算折算
|
public int RemainingMonths { get; set; } // 剩余月份数,用于年度统计时的月度预算折算
|
||||||
|
public bool IsCurrentMonth { get; set; } // 标记是否为当前月的预算(用于年度统计中月度预算的计算)
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateMonthlyDescription(List<BudgetStatsItem> budgets, decimal totalLimit, decimal totalCurrent, DateTime referenceDate, BudgetCategory category)
|
private string GenerateMonthlyDescription(List<BudgetStatsItem> budgets, decimal totalLimit, decimal totalCurrent, DateTime referenceDate, BudgetCategory category)
|
||||||
@@ -1198,15 +1233,16 @@ public class BudgetStatsService(
|
|||||||
// 当前月度预算(剩余月份)
|
// 当前月度预算(剩余月份)
|
||||||
if (currentMonthlyBudgets.Any())
|
if (currentMonthlyBudgets.Any())
|
||||||
{
|
{
|
||||||
description.AppendLine($"<h3>当前月度{categoryName}预算(剩余月份)</h3>");
|
description.AppendLine($"<h3>当前月度{categoryName}预算(当前月及未来月)</h3>");
|
||||||
description.AppendLine("""
|
description.AppendLine("""
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>名称</th>
|
<th>名称</th>
|
||||||
<th>单月预算</th>
|
<th>类型</th>
|
||||||
<th>剩余月份</th>
|
<th>计算方式</th>
|
||||||
<th>合计额度</th>
|
<th>合计额度</th>
|
||||||
|
<th>实际金额</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -1215,13 +1251,18 @@ public class BudgetStatsService(
|
|||||||
foreach (var budget in currentMonthlyBudgets)
|
foreach (var budget in currentMonthlyBudgets)
|
||||||
{
|
{
|
||||||
var budgetLimit = CalculateBudgetLimit(budget, BudgetPeriodType.Year, referenceDate);
|
var budgetLimit = CalculateBudgetLimit(budget, BudgetPeriodType.Year, referenceDate);
|
||||||
|
var typeStr = budget.IsCurrentMonth ? "当前月" : "未来月";
|
||||||
|
var calcStr = budget.IsCurrentMonth
|
||||||
|
? $"1月×{budget.Limit:N0}"
|
||||||
|
: $"{budget.RemainingMonths}月×{budget.Limit:N0}";
|
||||||
|
|
||||||
description.AppendLine($"""
|
description.AppendLine($"""
|
||||||
<tr>
|
<tr>
|
||||||
<td>{budget.Name}</td>
|
<td>{budget.Name}</td>
|
||||||
<td>{budget.Limit:N0}</td>
|
<td>{typeStr}</td>
|
||||||
<td>{budget.RemainingMonths}</td>
|
<td>{calcStr}</td>
|
||||||
<td>{budgetLimit:N0}</td>
|
<td>{budgetLimit:N0}</td>
|
||||||
|
<td>{(budget.IsCurrentMonth ? budget.Current.ToString("N1") : "-")}</td>
|
||||||
</tr>
|
</tr>
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
@@ -1282,7 +1323,14 @@ public class BudgetStatsService(
|
|||||||
foreach (var budget in currentMonthlyBudgets)
|
foreach (var budget in currentMonthlyBudgets)
|
||||||
{
|
{
|
||||||
var budgetLimit = CalculateBudgetLimit(budget, BudgetPeriodType.Year, referenceDate);
|
var budgetLimit = CalculateBudgetLimit(budget, BudgetPeriodType.Year, referenceDate);
|
||||||
limitParts.Add($"{budget.Name}(剩余{budget.RemainingMonths}月×{budget.Limit:N0}={budgetLimit:N0})");
|
if (budget.IsCurrentMonth)
|
||||||
|
{
|
||||||
|
limitParts.Add($"{budget.Name}(当前月×{budget.Limit:N0}={budgetLimit:N0})");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
limitParts.Add($"{budget.Name}(剩余{budget.RemainingMonths}月×{budget.Limit:N0}={budgetLimit:N0})");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 年度预算部分
|
// 年度预算部分
|
||||||
|
|||||||
Reference in New Issue
Block a user