新增不记额收支
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 34s
Docker Build & Deploy / Deploy to Production (push) Successful in 8s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 0s
Docker Build & Deploy / WeChat Notification (push) Successful in 3s

This commit is contained in:
孙诚
2026-01-15 10:53:05 +08:00
parent 12cf1b6323
commit 65f7316c82
9 changed files with 456 additions and 123 deletions

View File

@@ -128,14 +128,18 @@ public class BudgetController(
{
try
{
// 不记额预算的金额强制设为0
var limit = dto.NoLimit ? 0 : dto.Limit;
var budget = new BudgetRecord
{
Name = dto.Name,
Type = dto.Type,
Limit = dto.Limit,
Limit = limit,
Category = dto.Category,
SelectedCategories = dto.SelectedCategories != null ? string.Join(",", dto.SelectedCategories) : string.Empty,
StartDate = dto.StartDate ?? DateTime.Now
StartDate = dto.StartDate ?? DateTime.Now,
NoLimit = dto.NoLimit
};
var varidationError = await ValidateBudgetSelectedCategoriesAsync(budget);
@@ -169,11 +173,15 @@ public class BudgetController(
var budget = await budgetRepository.GetByIdAsync(dto.Id);
if (budget == null) return "预算不存在".Fail();
// 不记额预算的金额强制设为0
var limit = dto.NoLimit ? 0 : dto.Limit;
budget.Name = dto.Name;
budget.Type = dto.Type;
budget.Limit = dto.Limit;
budget.Limit = limit;
budget.Category = dto.Category;
budget.SelectedCategories = dto.SelectedCategories != null ? string.Join(",", dto.SelectedCategories) : string.Empty;
budget.NoLimit = dto.NoLimit;
if (dto.StartDate.HasValue)
{
budget.StartDate = dto.StartDate.Value;
@@ -197,6 +205,12 @@ public class BudgetController(
private async Task<string> ValidateBudgetSelectedCategoriesAsync(BudgetRecord record)
{
// 验证不记额预算必须是年度预算
if (record.NoLimit && record.Type != BudgetPeriodType.Year)
{
return "不记额预算只能设置为年度预算。";
}
var allBudgets = await budgetRepository.GetAllAsync();
var recordSelectedCategories = record.SelectedCategories.Split(',', StringSplitOptions.RemoveEmptyEntries);

View File

@@ -8,6 +8,7 @@ public class CreateBudgetDto
public BudgetCategory Category { get; set; }
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
public DateTime? StartDate { get; set; }
public bool NoLimit { get; set; } = false;
}
public class UpdateBudgetDto : CreateBudgetDto