2025-03-21 11:05:42 +08:00

54 lines
1.8 KiB
Go

package form
import (
"time"
db "management/internal/db/sqlc"
"management/internal/pkg/convertor"
"github.com/jackc/pgx/v5/pgtype"
)
type BudgetForm struct {
ID int64 `json:"id"`
ProjectID int64 `json:"project_id"`
Name string `json:"name"`
BudgetType int32 `json:"budget_type"`
Category int32 `json:"category"`
StartAt time.Time `json:"start_at"`
EndAt time.Time `json:"end_at"`
Amount float64 `json:"amount"`
AmountF pgtype.Numeric `comment:"预算金额"`
UsedAmount float64 `json:"used_amount"`
UsedAmountF pgtype.Numeric `comment:"已支付金额"`
RemainingAmount float64 `json:"remaining_amount"`
RemainingAmountF pgtype.Numeric `comment:"剩余金额"`
Remark string `json:"remark"`
Status int16 `json:"status"`
Sort int32 `json:"sort"`
CreatedAt time.Time `json:"created_at"`
CreatedName string `comment:"创建人"`
UpdatedAt time.Time `json:"updated_at"`
UpdatedName string `comment:"更新人"`
}
func (f *BudgetForm) ToForm(p *db.Budget) *BudgetForm {
return &BudgetForm{
ID: p.ID,
ProjectID: p.ProjectID,
Name: p.Name,
BudgetType: p.BudgetType,
Category: p.Category,
StartAt: p.StartAt,
EndAt: p.EndAt,
Amount: convertor.NumericToFloat64(p.Amount),
UsedAmount: convertor.NumericToFloat64(p.UsedAmount),
RemainingAmount: convertor.NumericToFloat64(p.RemainingAmount),
Remark: p.Remark,
Status: p.Status,
Sort: p.Sort,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
}
}