fix bugs
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 28s
Docker Build & Deploy / Deploy to Production (push) Successful in 11s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 28s
Docker Build & Deploy / Deploy to Production (push) Successful in 11s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 2s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
This commit is contained in:
@@ -192,6 +192,14 @@ public class BudgetService(
|
|||||||
decimal totalCurrent = 0;
|
decimal totalCurrent = 0;
|
||||||
decimal totalLimit = 0;
|
decimal totalLimit = 0;
|
||||||
|
|
||||||
|
// 是否可以使用趋势统计来计算实际发生额(避免多预算重复计入同一笔账)
|
||||||
|
var transactionType = category switch
|
||||||
|
{
|
||||||
|
BudgetCategory.Expense => TransactionType.Expense,
|
||||||
|
BudgetCategory.Income => TransactionType.Income,
|
||||||
|
_ => TransactionType.None
|
||||||
|
};
|
||||||
|
|
||||||
foreach (var budget in relevant)
|
foreach (var budget in relevant)
|
||||||
{
|
{
|
||||||
// 限额折算
|
// 限额折算
|
||||||
@@ -208,7 +216,7 @@ public class BudgetService(
|
|||||||
}
|
}
|
||||||
totalLimit += itemLimit;
|
totalLimit += itemLimit;
|
||||||
|
|
||||||
// 当前值累加
|
// 先逐预算累加当前值(作为后备值)
|
||||||
var selectedCategories = string.Join(',', budget.SelectedCategories);
|
var selectedCategories = string.Join(',', budget.SelectedCategories);
|
||||||
var currentAmount = await CalculateCurrentAmountAsync(new()
|
var currentAmount = await CalculateCurrentAmountAsync(new()
|
||||||
{
|
{
|
||||||
@@ -220,34 +228,21 @@ public class BudgetService(
|
|||||||
StartDate = new DateTime(referenceDate.Year, referenceDate.Month, 1),
|
StartDate = new DateTime(referenceDate.Year, referenceDate.Month, 1),
|
||||||
IsMandatoryExpense = budget.IsMandatoryExpense
|
IsMandatoryExpense = budget.IsMandatoryExpense
|
||||||
}, referenceDate);
|
}, referenceDate);
|
||||||
|
|
||||||
if (budget.Type == statType)
|
if (budget.Type == statType)
|
||||||
{
|
{
|
||||||
totalCurrent += currentAmount;
|
totalCurrent += currentAmount;
|
||||||
}
|
}
|
||||||
else
|
else if (statType == BudgetPeriodType.Year && budget.Type == BudgetPeriodType.Month)
|
||||||
{
|
{
|
||||||
// 如果周期不匹配
|
// 年度视图下,月度预算计入其当前值(作为对年度目前的贡献)
|
||||||
if (statType == BudgetPeriodType.Year && budget.Type == BudgetPeriodType.Month)
|
|
||||||
{
|
|
||||||
// 在年度视图下,月度预算计入其当前值(作为对年度目前的贡献)
|
|
||||||
totalCurrent += currentAmount;
|
totalCurrent += currentAmount;
|
||||||
}
|
}
|
||||||
// 月度视图下,年度预算的 current 不计入
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Limit = totalLimit;
|
result.Limit = totalLimit;
|
||||||
result.Current = totalCurrent;
|
|
||||||
result.Rate = totalLimit > 0 ? totalCurrent / totalLimit * 100 : 0;
|
|
||||||
|
|
||||||
// 计算每日/每月趋势
|
// 计算每日/每月趋势
|
||||||
var transactionType = category switch
|
|
||||||
{
|
|
||||||
BudgetCategory.Expense => TransactionType.Expense,
|
|
||||||
BudgetCategory.Income => TransactionType.Income,
|
|
||||||
_ => TransactionType.None
|
|
||||||
};
|
|
||||||
|
|
||||||
if (transactionType != TransactionType.None)
|
if (transactionType != TransactionType.None)
|
||||||
{
|
{
|
||||||
var hasGlobalBudget = relevant.Any(b => b.SelectedCategories.Length == 0);
|
var hasGlobalBudget = relevant.Any(b => b.SelectedCategories.Length == 0);
|
||||||
@@ -283,6 +278,7 @@ public class BudgetService(
|
|||||||
groupByMonth);
|
groupByMonth);
|
||||||
|
|
||||||
decimal accumulated = 0;
|
decimal accumulated = 0;
|
||||||
|
decimal lastValidAccumulated = 0;
|
||||||
var now = dateTimeProvider.Now;
|
var now = dateTimeProvider.Now;
|
||||||
|
|
||||||
if (statType == BudgetPeriodType.Month)
|
if (statType == BudgetPeriodType.Month)
|
||||||
@@ -300,6 +296,7 @@ public class BudgetService(
|
|||||||
if (dailyStats.TryGetValue(currentDate.Date, out var amount))
|
if (dailyStats.TryGetValue(currentDate.Date, out var amount))
|
||||||
{
|
{
|
||||||
accumulated += amount;
|
accumulated += amount;
|
||||||
|
lastValidAccumulated = accumulated;
|
||||||
}
|
}
|
||||||
result.Trend.Add(accumulated);
|
result.Trend.Add(accumulated);
|
||||||
}
|
}
|
||||||
@@ -319,11 +316,22 @@ public class BudgetService(
|
|||||||
if (dailyStats.TryGetValue(currentMonthDate, out var amount))
|
if (dailyStats.TryGetValue(currentMonthDate, out var amount))
|
||||||
{
|
{
|
||||||
accumulated += amount;
|
accumulated += amount;
|
||||||
|
lastValidAccumulated = accumulated;
|
||||||
}
|
}
|
||||||
result.Trend.Add(accumulated);
|
result.Trend.Add(accumulated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果有有效的趋势数据,使用去重后的实际发生额(趋势的累计值),避免同一账单被多预算重复计入
|
||||||
|
// 否则使用前面逐预算累加的值(作为后备)
|
||||||
|
if (lastValidAccumulated > 0)
|
||||||
|
{
|
||||||
|
totalCurrent = lastValidAccumulated;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Current = totalCurrent;
|
||||||
|
result.Rate = totalLimit > 0 ? totalCurrent / totalLimit * 100 : 0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1412,7 +1412,6 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
.balance-chart {
|
.balance-chart {
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: rgba(0, 0, 0, 0.02);
|
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
margin: 0 -12px;
|
margin: 0 -12px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user