fix
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 22s
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
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 22s
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:
@@ -876,12 +876,26 @@ public class BudgetSavingsService(
|
||||
UpdateTime = dateTimeProvider.Now
|
||||
};
|
||||
|
||||
return BudgetResult.FromEntity(
|
||||
// 生成明细数据
|
||||
var details = GenerateYearlyDetails(
|
||||
currentMonthlyIncomeItems,
|
||||
currentYearlyIncomeItems,
|
||||
currentMonthlyExpenseItems,
|
||||
currentYearlyExpenseItems,
|
||||
archiveIncomeItems,
|
||||
archiveExpenseItems,
|
||||
new DateTime(year, 1, 1)
|
||||
);
|
||||
|
||||
var result = BudgetResult.FromEntity(
|
||||
record,
|
||||
currentActual,
|
||||
new DateTime(year, 1, 1),
|
||||
description.ToString()
|
||||
);
|
||||
result.Details = details;
|
||||
|
||||
return result;
|
||||
|
||||
void AddOrIncCurrentItem(
|
||||
long id,
|
||||
@@ -1116,4 +1130,166 @@ public class BudgetSavingsService(
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成年度存款明细数据
|
||||
/// </summary>
|
||||
private SavingsDetail GenerateYearlyDetails(
|
||||
List<(long id, string name, decimal limit, int factor, decimal current, bool isMandatory)> currentMonthlyIncomeItems,
|
||||
List<(long id, string name, decimal limit, int factor, decimal current, bool isMandatory)> currentYearlyIncomeItems,
|
||||
List<(long id, string name, decimal limit, int factor, decimal current, bool isMandatory)> currentMonthlyExpenseItems,
|
||||
List<(long id, string name, decimal limit, int factor, decimal current, bool isMandatory)> currentYearlyExpenseItems,
|
||||
List<(long id, string name, int[] months, decimal limit, decimal current)> archiveIncomeItems,
|
||||
List<(long id, string name, int[] months, decimal limit, decimal current)> archiveExpenseItems,
|
||||
DateTime referenceDate)
|
||||
{
|
||||
var incomeDetails = new List<BudgetDetailItem>();
|
||||
var expenseDetails = new List<BudgetDetailItem>();
|
||||
|
||||
// 处理已归档的收入预算
|
||||
foreach (var item in archiveIncomeItems)
|
||||
{
|
||||
incomeDetails.Add(new BudgetDetailItem
|
||||
{
|
||||
Id = item.id,
|
||||
Name = item.name,
|
||||
Type = BudgetPeriodType.Month,
|
||||
BudgetLimit = item.limit,
|
||||
ActualAmount = item.current,
|
||||
EffectiveAmount = item.current,
|
||||
CalculationNote = $"已归档 ({string.Join(", ", item.months)}月)",
|
||||
IsOverBudget = false,
|
||||
IsArchived = true,
|
||||
ArchivedMonths = item.months
|
||||
});
|
||||
}
|
||||
|
||||
// 处理当前月度收入预算
|
||||
foreach (var item in currentMonthlyIncomeItems)
|
||||
{
|
||||
// 年度预算中,月度预算按 factor 倍率计算有效金额
|
||||
var effectiveAmount = item.limit == 0 ? item.current : item.limit * item.factor;
|
||||
var note = item.limit == 0
|
||||
? "不记额(使用实际)"
|
||||
: $"预算 {item.limit:N0} × {item.factor}月 = {effectiveAmount:N0}";
|
||||
|
||||
incomeDetails.Add(new BudgetDetailItem
|
||||
{
|
||||
Id = item.id,
|
||||
Name = item.name,
|
||||
Type = BudgetPeriodType.Month,
|
||||
BudgetLimit = item.limit,
|
||||
ActualAmount = item.current,
|
||||
EffectiveAmount = effectiveAmount,
|
||||
CalculationNote = note,
|
||||
IsOverBudget = item.current > 0 && item.current < item.limit,
|
||||
IsArchived = false
|
||||
});
|
||||
}
|
||||
|
||||
// 处理当前年度收入预算
|
||||
foreach (var item in currentYearlyIncomeItems)
|
||||
{
|
||||
// 年度预算:硬性预算或不记额预算使用实际值,否则使用预算值
|
||||
var effectiveAmount = item.isMandatory || item.limit == 0 ? item.current : item.limit;
|
||||
var note = item.isMandatory
|
||||
? "硬性(使用实际)"
|
||||
: (item.limit == 0 ? "不记额(使用实际)" : "使用预算");
|
||||
|
||||
incomeDetails.Add(new BudgetDetailItem
|
||||
{
|
||||
Id = item.id,
|
||||
Name = item.name,
|
||||
Type = BudgetPeriodType.Year,
|
||||
BudgetLimit = item.limit,
|
||||
ActualAmount = item.current,
|
||||
EffectiveAmount = effectiveAmount,
|
||||
CalculationNote = note,
|
||||
IsOverBudget = false,
|
||||
IsArchived = false
|
||||
});
|
||||
}
|
||||
|
||||
// 处理已归档的支出预算
|
||||
foreach (var item in archiveExpenseItems)
|
||||
{
|
||||
expenseDetails.Add(new BudgetDetailItem
|
||||
{
|
||||
Id = item.id,
|
||||
Name = item.name,
|
||||
Type = BudgetPeriodType.Month,
|
||||
BudgetLimit = item.limit,
|
||||
ActualAmount = item.current,
|
||||
EffectiveAmount = item.current,
|
||||
CalculationNote = $"已归档 ({string.Join(", ", item.months)}月)",
|
||||
IsOverBudget = false,
|
||||
IsArchived = true,
|
||||
ArchivedMonths = item.months
|
||||
});
|
||||
}
|
||||
|
||||
// 处理当前月度支出预算
|
||||
foreach (var item in currentMonthlyExpenseItems)
|
||||
{
|
||||
var effectiveAmount = item.limit == 0 ? item.current : item.limit * item.factor;
|
||||
var note = item.limit == 0
|
||||
? "不记额(使用实际)"
|
||||
: $"预算 {item.limit:N0} × {item.factor}月 = {effectiveAmount:N0}";
|
||||
|
||||
expenseDetails.Add(new BudgetDetailItem
|
||||
{
|
||||
Id = item.id,
|
||||
Name = item.name,
|
||||
Type = BudgetPeriodType.Month,
|
||||
BudgetLimit = item.limit,
|
||||
ActualAmount = item.current,
|
||||
EffectiveAmount = effectiveAmount,
|
||||
CalculationNote = note,
|
||||
IsOverBudget = item.current > item.limit,
|
||||
IsArchived = false
|
||||
});
|
||||
}
|
||||
|
||||
// 处理当前年度支出预算
|
||||
foreach (var item in currentYearlyExpenseItems)
|
||||
{
|
||||
var effectiveAmount = item.isMandatory || item.limit == 0 ? item.current : item.limit;
|
||||
var note = item.isMandatory
|
||||
? "硬性(使用实际)"
|
||||
: (item.limit == 0 ? "不记额(使用实际)" : "使用预算");
|
||||
|
||||
expenseDetails.Add(new BudgetDetailItem
|
||||
{
|
||||
Id = item.id,
|
||||
Name = item.name,
|
||||
Type = BudgetPeriodType.Year,
|
||||
BudgetLimit = item.limit,
|
||||
ActualAmount = item.current,
|
||||
EffectiveAmount = effectiveAmount,
|
||||
CalculationNote = note,
|
||||
IsOverBudget = item.current > item.limit,
|
||||
IsArchived = false
|
||||
});
|
||||
}
|
||||
|
||||
// 计算汇总
|
||||
var totalIncome = incomeDetails.Sum(i => i.EffectiveAmount);
|
||||
var totalExpense = expenseDetails.Sum(e => e.EffectiveAmount);
|
||||
var plannedSavings = totalIncome - totalExpense;
|
||||
|
||||
var formula = $"收入 {totalIncome:N0} - 支出 {totalExpense:N0} = {plannedSavings:N0}";
|
||||
|
||||
return new SavingsDetail
|
||||
{
|
||||
IncomeItems = incomeDetails,
|
||||
ExpenseItems = expenseDetails,
|
||||
Summary = new SavingsCalculationSummary
|
||||
{
|
||||
TotalIncomeBudget = totalIncome,
|
||||
TotalExpenseBudget = totalExpense,
|
||||
PlannedSavings = plannedSavings,
|
||||
CalculationFormula = formula
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user