feat: 添加预算类别名称更新功能,优化相关控制器逻辑
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:
孙诚
2026-01-07 19:55:00 +08:00
parent 35a856c6e3
commit fa1389401a
7 changed files with 40 additions and 8 deletions

View File

@@ -3,6 +3,8 @@
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
@@ -33,4 +35,31 @@ public class BudgetRepository(IFreeSql freeSql) : BaseRepository<BudgetRecord>(f
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) ||
(type == TransactionType.None && b.Category == BudgetCategory.Savings)))
.ToListAsync();
foreach (var record in records)
{
var categories = record.SelectedCategories.Split(',').ToList();
for (int 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();
}
}