todo
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 23s
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 23s
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:
80
Service/Budget/BudgetSavingsService.cs
Normal file
80
Service/Budget/BudgetSavingsService.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
namespace Service.Budget;
|
||||
|
||||
public interface IBudgetSavingsService
|
||||
{
|
||||
Task<BudgetResult> GetSavingsDtoAsync(
|
||||
BudgetPeriodType periodType,
|
||||
DateTime? referenceDate = null,
|
||||
IEnumerable<BudgetRecord>? existingBudgets = null);
|
||||
}
|
||||
|
||||
public class BudgetSavingsService(
|
||||
IBudgetRepository budgetRepository,
|
||||
IBudgetArchiveRepository budgetArchiveRepository
|
||||
) : IBudgetSavingsService
|
||||
{
|
||||
public async Task<BudgetResult> GetSavingsDtoAsync(
|
||||
BudgetPeriodType periodType,
|
||||
DateTime? referenceDate = null,
|
||||
IEnumerable<BudgetRecord>? existingBudgets = null)
|
||||
{
|
||||
var budgets = existingBudgets;
|
||||
|
||||
if (existingBudgets == null)
|
||||
{
|
||||
budgets = await budgetRepository.GetAllAsync();
|
||||
}
|
||||
|
||||
if (budgets == null)
|
||||
{
|
||||
throw new InvalidOperationException("No budgets found.");
|
||||
}
|
||||
|
||||
budgets = budgets
|
||||
// 排序顺序 1.硬性预算 2.月度->年度 3.实际金额倒叙
|
||||
.OrderBy(b => b.IsMandatoryExpense)
|
||||
.ThenBy(b => b.Type)
|
||||
.ThenByDescending(b => b.Limit);
|
||||
|
||||
var year = referenceDate?.Year ?? DateTime.Now.Year;
|
||||
var month = referenceDate?.Month ?? DateTime.Now.Month;
|
||||
|
||||
if(periodType == BudgetPeriodType.Month)
|
||||
{
|
||||
return await GetForMonthAsync(budgets, year, month);
|
||||
}
|
||||
else if(periodType == BudgetPeriodType.Year)
|
||||
{
|
||||
return await GetForYearAsync(budgets, year);
|
||||
}
|
||||
|
||||
throw new NotSupportedException($"Period type {periodType} is not supported.");
|
||||
}
|
||||
|
||||
private async Task<BudgetResult> GetForMonthAsync(
|
||||
IEnumerable<BudgetRecord> budgets,
|
||||
int year,
|
||||
int month)
|
||||
{
|
||||
var result = new BudgetResult
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
var monthlyBudgets = budgets
|
||||
.Where(b => b.Type == BudgetPeriodType.Month);
|
||||
var yearlyBudgets = budgets
|
||||
.Where(b => b.Type == BudgetPeriodType.Year);
|
||||
|
||||
// var actualAmount = await budgetRepository.GetCurrentAmountAsync(budget, startDate, endDate);
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private async Task<BudgetResult> GetForYearAsync(
|
||||
IEnumerable<BudgetRecord> budgets,
|
||||
int year)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user