package form import ( "time" db "management/internal/db/sqlc" "management/internal/pkg/convertor" "github.com/jackc/pgx/v5/pgtype" ) type ProjectFileForm struct { Combination string `schema:"-"` ProjectFileItems []*ProjectFileItemForm `schema:"-"` } type ProjectFileItemForm struct { Name string `schema:"-"` Path string `schema:"-"` Combination string `schema:"-"` } type ProjectForm struct { ID int64 `validate:"min=0" comment:"ID"` Name string `validate:"required" comment:"名称"` StartAt time.Time `validate:"required" comment:"开始时间"` EndAt time.Time `validate:"required" comment:"结束时间"` CustomerID int64 `validate:"required" comment:"客户ID"` CustomerName string `comment:"客户名称"` TotalMoney float64 `validate:"required" comment:"总金额"` TotalMoneyF pgtype.Numeric `comment:"总金额"` Description string `comment:"简介"` ApplyAt time.Time `validate:"required" comment:"申请时间"` ApplyUserID int32 `validate:"required" comment:"申请人"` ApplyUserName string `comment:"申请人"` ManagerID int32 `comment:"项目经理"` ManagerName string `comment:"项目经理"` Members string `comment:"项目成员"` MembersName string `comment:"项目成员"` Status int16 `validate:"min=-1" comment:"状态"` Sort int32 `validate:"min=0" comment:"排序"` CreatedAt time.Time `comment:"创建时间"` CreatedName string `comment:"创建人"` UpdatedAt time.Time `comment:"更新时间"` UpdatedName string `comment:"更新人"` ProjectFiles *ProjectFileForm `schema:"-"` } func (f *ProjectForm) ToForm(p *db.Project, pfs []*db.ProjectFile) *ProjectForm { var allCombinationPath string var pfi []*ProjectFileItemForm for _, pf := range pfs { pfi = append(pfi, &ProjectFileItemForm{ Name: pf.Name, Path: pf.Path, Combination: pf.Name + "|" + pf.Path, }) allCombinationPath += pf.Name + "|" + pf.Path + "," } return &ProjectForm{ ID: p.ID, Name: p.Name, StartAt: p.StartAt, EndAt: p.EndAt, CustomerID: p.CustomerID, TotalMoney: convertor.NumericToFloat64(p.TotalMoney), Description: p.Description, ApplyAt: p.ApplyAt, ApplyUserID: p.ApplyUserID, ManagerID: p.ManagerID, Members: p.Members, Status: p.Status, Sort: p.Sort, CreatedAt: p.CreatedAt, UpdatedAt: p.UpdatedAt, ProjectFiles: &ProjectFileForm{ Combination: allCombinationPath, ProjectFileItems: pfi, }, } }