cow_lact.go 795 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package model
  2. import (
  3. "time"
  4. )
  5. type CowLact struct {
  6. Id int64 `json:"id"`
  7. PastureId int64 `json:"pastureId"`
  8. CowId int64 `json:"cowId"`
  9. EarNumber string `json:"earNumber"`
  10. Lact int32 `json:"lact"`
  11. StartTime string `json:"startTime"`
  12. CreatedAt int64 `json:"createdAt"`
  13. UpdatedAt int64 `json:"updatedAt"`
  14. }
  15. func (c *CowLact) TableName() string {
  16. return "cow_lact"
  17. }
  18. func NewCowLact(pastureId int64, cow *Cow) *CowLact {
  19. startTime := ""
  20. if cow.Lact == 0 {
  21. startTime = time.Unix(cow.AdmissionAt, 0).Local().Format(LayoutDate2)
  22. } else {
  23. startTime = time.Unix(cow.LastCalvingAt, 0).Local().Format(LayoutDate2)
  24. }
  25. return &CowLact{
  26. PastureId: pastureId,
  27. CowId: cow.Id,
  28. EarNumber: cow.EarNumber,
  29. Lact: cow.Lact,
  30. StartTime: startTime,
  31. }
  32. }