2026-01-06 21:15:02 +08:00
|
|
|
|
namespace WebApi.Controllers.Dto;
|
|
|
|
|
|
|
|
|
|
|
|
public class BudgetDto
|
|
|
|
|
|
{
|
|
|
|
|
|
public long Id { get; set; }
|
|
|
|
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
|
|
public BudgetPeriodType Type { get; set; }
|
|
|
|
|
|
public decimal Limit { get; set; }
|
|
|
|
|
|
public decimal Current { get; set; }
|
|
|
|
|
|
public BudgetCategory Category { get; set; }
|
|
|
|
|
|
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
|
|
|
|
|
|
public bool IsStopped { get; set; }
|
|
|
|
|
|
public string StartDate { get; set; } = string.Empty;
|
|
|
|
|
|
public string Period { get; set; } = string.Empty;
|
2026-01-07 19:19:53 +08:00
|
|
|
|
public DateTime? PeriodStart { get; set; }
|
|
|
|
|
|
public DateTime? PeriodEnd { get; set; }
|
2026-01-06 21:15:02 +08:00
|
|
|
|
|
2026-01-08 16:03:20 +08:00
|
|
|
|
public string Description { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
public static BudgetDto FromEntity(
|
|
|
|
|
|
BudgetRecord entity,
|
|
|
|
|
|
decimal currentAmount = 0,
|
|
|
|
|
|
DateTime? referenceDate = null,
|
|
|
|
|
|
string description = "")
|
2026-01-06 21:15:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
var date = referenceDate ?? DateTime.Now;
|
|
|
|
|
|
var (start, end) = BudgetService.GetPeriodRange(entity.StartDate, entity.Type, date);
|
2026-01-08 16:03:20 +08:00
|
|
|
|
|
2026-01-06 21:15:02 +08:00
|
|
|
|
return new BudgetDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = entity.Id,
|
|
|
|
|
|
Name = entity.Name,
|
|
|
|
|
|
Type = entity.Type,
|
|
|
|
|
|
Limit = entity.Limit,
|
|
|
|
|
|
Current = currentAmount,
|
|
|
|
|
|
Category = entity.Category,
|
2026-01-08 16:03:20 +08:00
|
|
|
|
SelectedCategories = string.IsNullOrEmpty(entity.SelectedCategories)
|
|
|
|
|
|
? Array.Empty<string>()
|
2026-01-06 21:15:02 +08:00
|
|
|
|
: entity.SelectedCategories.Split(','),
|
|
|
|
|
|
IsStopped = entity.IsStopped,
|
|
|
|
|
|
StartDate = entity.StartDate.ToString("yyyy-MM-dd"),
|
2026-01-07 17:33:50 +08:00
|
|
|
|
Period = entity.Type switch
|
|
|
|
|
|
{
|
|
|
|
|
|
BudgetPeriodType.Year => $"{start:yy}年",
|
|
|
|
|
|
BudgetPeriodType.Month => $"{start:yy}年第{start.Month}月",
|
|
|
|
|
|
_ => $"{start:yyyy-MM-dd} ~ {end:yyyy-MM-dd}"
|
2026-01-07 19:19:53 +08:00
|
|
|
|
},
|
|
|
|
|
|
PeriodStart = start,
|
2026-01-08 16:03:20 +08:00
|
|
|
|
PeriodEnd = end,
|
|
|
|
|
|
Description = description
|
2026-01-06 21:15:02 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class CreateBudgetDto
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
|
|
public BudgetPeriodType Type { get; set; } = BudgetPeriodType.Month;
|
|
|
|
|
|
public decimal Limit { get; set; }
|
|
|
|
|
|
public BudgetCategory Category { get; set; }
|
|
|
|
|
|
public string[] SelectedCategories { get; set; } = Array.Empty<string>();
|
|
|
|
|
|
public DateTime? StartDate { get; set; }
|
|
|
|
|
|
}
|
2026-01-07 17:33:50 +08:00
|
|
|
|
|
|
|
|
|
|
public class UpdateBudgetDto : CreateBudgetDto
|
|
|
|
|
|
{
|
|
|
|
|
|
public long Id { get; set; }
|
|
|
|
|
|
public bool IsStopped { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|