package model import ( "time" ) type CowLact struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` CowId int64 `json:"cowId"` EarNumber string `json:"earNumber"` Lact int32 `json:"lact"` StartTime string `json:"startTime"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (c *CowLact) TableName() string { return "cow_lact" } func NewCowLact(pastureId int64, cow *Cow) *CowLact { startTime := "" if cow.Lact == 0 { startTime = time.Unix(cow.AdmissionAt, 0).Local().Format(LayoutDate2) } else { startTime = time.Unix(cow.LastCalvingAt, 0).Local().Format(LayoutDate2) } return &CowLact{ PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, Lact: cow.Lact, StartTime: startTime, } }