Files
EmailBill/Repository/BudgetRepository.cs
SunCheng 6f725dbb13 fix: 修复收入预算计算和添加存款计划明细功能
问题1:修复收入预算实际金额计算
- 在 BudgetRepository.cs 中修复 SelectedCategories.Split 逻辑
- 添加 StringSplitOptions.RemoveEmptyEntries 和 StringSplitOptions.TrimEntries 参数
- 添加单元测试验证修复

问题2:添加存款计划明细按钮和弹窗
- 在 BudgetCard.vue 中添加 'show-detail' emit
- 为存款计划卡片(category === 2)添加明细按钮
- 在 SavingsBudgetContent.vue 中实现明细弹窗
- 弹窗显示:收入预算、支出预算、计划存款公式、存款结果

问题3:统一卡片样式
- 修复 BudgetChartAnalysis.vue 的卡片样式
- 使用 16px 圆角、增强阴影和边框
2026-02-14 12:58:26 +08:00

61 lines
2.3 KiB
C#

namespace Repository;
public interface IBudgetRepository : IBaseRepository<BudgetRecord>
{
Task<decimal> GetCurrentAmountAsync(BudgetRecord budget, DateTime startDate, DateTime endDate);
Task UpdateBudgetCategoryNameAsync(string oldName, string newName, TransactionType type);
}
public class BudgetRepository(IFreeSql freeSql) : BaseRepository<BudgetRecord>(freeSql), IBudgetRepository
{
public async Task<decimal> GetCurrentAmountAsync(BudgetRecord budget, DateTime startDate, DateTime endDate)
{
var query = FreeSql.Select<TransactionRecord>()
.Where(t => t.OccurredAt >= startDate && t.OccurredAt <= endDate);
if (!string.IsNullOrEmpty(budget.SelectedCategories))
{
var categoryList = budget.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
query = query.Where(t => categoryList.Contains(t.Classify));
}
if (budget.Category == BudgetCategory.Expense)
{
query = query.Where(t => t.Type == TransactionType.Expense);
}
else if (budget.Category == BudgetCategory.Income)
{
query = query.Where(t => t.Type == TransactionType.Income);
}
return await query.SumAsync(t => t.Amount);
}
public async Task UpdateBudgetCategoryNameAsync(string oldName, string newName, TransactionType type)
{
var records = await FreeSql.Select<BudgetRecord>()
.Where(b => b.SelectedCategories.Contains(oldName) &&
((type == TransactionType.Expense && b.Category == BudgetCategory.Expense) ||
(type == TransactionType.Income && b.Category == BudgetCategory.Income)))
.ToListAsync();
foreach (var record in records)
{
var categories = record.SelectedCategories.Split(',').ToList();
for (var i = 0; i < categories.Count; i++)
{
if (categories[i] == oldName)
{
categories[i] = newName;
}
}
record.SelectedCategories = string.Join(',', categories);
}
await FreeSql.Update<BudgetRecord>()
.SetSource(records)
.ExecuteAffrowsAsync();
}
}