大量后端代码格式化
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace Service;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Service;
|
||||
|
||||
public interface IBudgetService
|
||||
{
|
||||
@@ -24,6 +26,7 @@ public interface IBudgetService
|
||||
Task<BudgetResult?> GetSavingsBudgetAsync(int year, int month, BudgetPeriodType type);
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public class BudgetService(
|
||||
IBudgetRepository budgetRepository,
|
||||
IBudgetArchiveRepository budgetArchiveRepository,
|
||||
@@ -79,20 +82,22 @@ public class BudgetService(
|
||||
}
|
||||
|
||||
// 创造虚拟的存款预算
|
||||
dtos.Add(await GetVirtualSavingsDtoAsync(
|
||||
dtos.Add(await GetSavingsDtoAsync(
|
||||
BudgetPeriodType.Month,
|
||||
referenceDate,
|
||||
budgets));
|
||||
dtos.Add(await GetVirtualSavingsDtoAsync(
|
||||
dtos.Add(await GetSavingsDtoAsync(
|
||||
BudgetPeriodType.Year,
|
||||
referenceDate,
|
||||
budgets));
|
||||
|
||||
dtos = dtos
|
||||
.Where(x => x != null)
|
||||
.Cast<BudgetResult>()
|
||||
.OrderByDescending(x => x.IsMandatoryExpense)
|
||||
.ThenBy(x => x.Type)
|
||||
.ThenByDescending(x => x.Current)
|
||||
.ToList();
|
||||
.ToList()!;
|
||||
|
||||
return [.. dtos.Where(dto => dto != null).Cast<BudgetResult>()];
|
||||
}
|
||||
@@ -100,7 +105,7 @@ public class BudgetService(
|
||||
public async Task<BudgetResult?> GetSavingsBudgetAsync(int year, int month, BudgetPeriodType type)
|
||||
{
|
||||
var referenceDate = new DateTime(year, month, 1);
|
||||
return await GetVirtualSavingsDtoAsync(type, referenceDate);
|
||||
return await GetSavingsDtoAsync(type, referenceDate);
|
||||
}
|
||||
|
||||
public async Task<BudgetCategoryStats> GetCategoryStatsAsync(BudgetCategory category, DateTime referenceDate)
|
||||
@@ -128,7 +133,7 @@ public class BudgetService(
|
||||
_ => TransactionType.None
|
||||
};
|
||||
|
||||
if (transactionType == TransactionType.None) return new List<UncoveredCategoryDetail>();
|
||||
if (transactionType == TransactionType.None) return [];
|
||||
|
||||
// 1. 获取所有预算
|
||||
var budgets = (await budgetRepository.GetAllAsync()).ToList();
|
||||
@@ -205,7 +210,7 @@ public class BudgetService(
|
||||
totalLimit += itemLimit;
|
||||
|
||||
// 当前值累加
|
||||
var selectedCategories = budget.SelectedCategories != null ? string.Join(',', budget.SelectedCategories) : string.Empty;
|
||||
var selectedCategories = string.Join(',', budget.SelectedCategories);
|
||||
var currentAmount = await CalculateCurrentAmountAsync(new()
|
||||
{
|
||||
Name = budget.Name,
|
||||
@@ -246,7 +251,7 @@ public class BudgetService(
|
||||
|
||||
if (transactionType != TransactionType.None)
|
||||
{
|
||||
var hasGlobalBudget = relevant.Any(b => b.SelectedCategories == null || b.SelectedCategories.Length == 0);
|
||||
var hasGlobalBudget = relevant.Any(b => b.SelectedCategories.Length == 0);
|
||||
|
||||
var allClassifies = hasGlobalBudget
|
||||
? []
|
||||
@@ -256,7 +261,7 @@ public class BudgetService(
|
||||
.ToList();
|
||||
|
||||
DateTime startDate, endDate;
|
||||
bool groupByMonth = false;
|
||||
bool groupByMonth;
|
||||
|
||||
if (statType == BudgetPeriodType.Month)
|
||||
{
|
||||
@@ -445,7 +450,7 @@ public class BudgetService(
|
||||
.Where(t =>
|
||||
{
|
||||
var dict = (IDictionary<string, object>)t;
|
||||
var classify = dict["Classify"]?.ToString() ?? "";
|
||||
var classify = dict["Classify"].ToString() ?? "";
|
||||
var type = Convert.ToInt32(dict["Type"]);
|
||||
return type == 0 && !budgetedCategories.Contains(classify);
|
||||
})
|
||||
@@ -551,7 +556,8 @@ public class BudgetService(
|
||||
// 返回实际消费和硬性消费累加中的较大值
|
||||
return mandatoryAccumulation;
|
||||
}
|
||||
else if (budget.Type == BudgetPeriodType.Year)
|
||||
|
||||
if (budget.Type == BudgetPeriodType.Year)
|
||||
{
|
||||
// 计算本年的天数(考虑闰年)
|
||||
var daysInYear = DateTime.IsLeapYear(referenceDate.Year) ? 366 : 365;
|
||||
@@ -592,7 +598,7 @@ public class BudgetService(
|
||||
return (start, end);
|
||||
}
|
||||
|
||||
private async Task<BudgetResult?> GetVirtualSavingsDtoAsync(
|
||||
private async Task<BudgetResult?> GetSavingsDtoAsync(
|
||||
BudgetPeriodType periodType,
|
||||
DateTime? referenceDate = null,
|
||||
IEnumerable<BudgetRecord>? existingBudgets = null)
|
||||
@@ -657,7 +663,7 @@ public class BudgetService(
|
||||
if (b.Category == BudgetCategory.Savings) continue;
|
||||
|
||||
processedIds.Add(b.Id);
|
||||
decimal factor = 1.0m;
|
||||
decimal factor;
|
||||
decimal historicalAmount = 0m;
|
||||
var historicalMonths = new List<int>();
|
||||
|
||||
@@ -759,7 +765,6 @@ public class BudgetService(
|
||||
|
||||
foreach (var group in deletedBudgets)
|
||||
{
|
||||
var budgetId = group.Key;
|
||||
var months = group.Select(g => g.Key.Month).OrderBy(m => m).ToList();
|
||||
var totalLimit = group.Sum(g => g.Value.HistoricalLimit);
|
||||
var (_, category, name) = group.First().Value;
|
||||
@@ -862,12 +867,12 @@ public class BudgetService(
|
||||
</thead>
|
||||
<tbody>
|
||||
""");
|
||||
foreach (var (Name, Amount) in noLimitIncomeItems)
|
||||
foreach (var (name, amount) in noLimitIncomeItems)
|
||||
{
|
||||
description.Append($"""
|
||||
<tr>
|
||||
<td>{Name}</td>
|
||||
<td><span class='income-value'>{Amount:N0}</span></td>
|
||||
<td>{name}</td>
|
||||
<td><span class='income-value'>{amount:N0}</span></td>
|
||||
</tr>
|
||||
""");
|
||||
}
|
||||
@@ -953,12 +958,12 @@ public class BudgetService(
|
||||
</thead>
|
||||
<tbody>
|
||||
""");
|
||||
foreach (var (Name, Amount) in noLimitExpenseItems)
|
||||
foreach (var (name, amount) in noLimitExpenseItems)
|
||||
{
|
||||
description.Append($"""
|
||||
<tr>
|
||||
<td>{Name}</td>
|
||||
<td><span class='expense-value'>{Amount:N0}</span></td>
|
||||
<td>{name}</td>
|
||||
<td><span class='expense-value'>{amount:N0}</span></td>
|
||||
</tr>
|
||||
""");
|
||||
}
|
||||
@@ -1080,13 +1085,13 @@ public record BudgetResult
|
||||
public decimal Limit { get; set; }
|
||||
public decimal Current { get; set; }
|
||||
public BudgetCategory Category { get; set; }
|
||||
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
|
||||
public string[] SelectedCategories { get; set; } = [];
|
||||
public string StartDate { get; set; } = string.Empty;
|
||||
public string Period { get; set; } = string.Empty;
|
||||
public DateTime? PeriodStart { get; set; }
|
||||
public DateTime? PeriodEnd { get; set; }
|
||||
public bool NoLimit { get; set; } = false;
|
||||
public bool IsMandatoryExpense { get; set; } = false;
|
||||
public bool NoLimit { get; set; }
|
||||
public bool IsMandatoryExpense { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public static BudgetResult FromEntity(
|
||||
@@ -1107,7 +1112,7 @@ public record BudgetResult
|
||||
Current = currentAmount,
|
||||
Category = entity.Category,
|
||||
SelectedCategories = string.IsNullOrEmpty(entity.SelectedCategories)
|
||||
? Array.Empty<string>()
|
||||
? []
|
||||
: entity.SelectedCategories.Split(','),
|
||||
StartDate = entity.StartDate.ToString("yyyy-MM-dd"),
|
||||
Period = entity.Type switch
|
||||
@@ -1157,7 +1162,7 @@ public class BudgetStatsDto
|
||||
/// <summary>
|
||||
/// 每日/每月累计金额趋势(对应当前周期内的实际发生额累计值)
|
||||
/// </summary>
|
||||
public List<decimal?> Trend { get; set; } = new();
|
||||
public List<decimal?> Trend { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1175,6 +1180,7 @@ public class BudgetCategoryStats
|
||||
/// </summary>
|
||||
public BudgetStatsDto Year { get; set; } = new();
|
||||
}
|
||||
|
||||
public class UncoveredCategoryDetail
|
||||
{
|
||||
public string Category { get; set; } = string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user