event_sale_cow.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type EventSaleCow struct {
  4. Id int64 `json:"id"`
  5. PastureId int64 `json:"pastureId"`
  6. SaleId int64 `json:"saleId"`
  7. CowId int64 `json:"cowId"`
  8. CowType pasturePb.CowType_Kind `json:"cowType"`
  9. EarNumber string `json:"earNumber"`
  10. DayAge int32 `json:"dayAge"`
  11. Lact int32 `json:"lact"`
  12. PregnancyAge int32 `json:"pregnancyAge"`
  13. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
  14. LactationAge int32 `json:"lactationAge"`
  15. CalvingAge int32 `json:"calvingAge"`
  16. AdmissionAge int32 `json:"admissionAge"`
  17. CreatedAt int64 `json:"createdAt"`
  18. UpdatedAt int64 `json:"updatedAt"`
  19. }
  20. func (e *EventSaleCow) TableName() string {
  21. return "event_sale_cow"
  22. }
  23. func NewEventSaleCow(pastureId int64, saleId, saleAt int64, cowInfo *Cow) *EventSaleCow {
  24. return &EventSaleCow{
  25. PastureId: pastureId,
  26. SaleId: saleId,
  27. CowId: cowInfo.Id,
  28. Lact: cowInfo.Lact,
  29. EarNumber: cowInfo.EarNumber,
  30. PregnancyAge: cowInfo.PregnancyAge,
  31. BreedStatus: cowInfo.BreedStatus,
  32. LactationAge: cowInfo.LactationAge,
  33. AdmissionAge: cowInfo.AdmissionAge,
  34. DayAge: cowInfo.GetEventDayAge(saleAt),
  35. CowType: cowInfo.CowType,
  36. }
  37. }
  38. func NewEventSaleCowList(pastureId int64, eventSale *EventSale, cowList []*Cow) []*EventSaleCow {
  39. res := make([]*EventSaleCow, 0)
  40. for _, cow := range cowList {
  41. res = append(res, NewEventSaleCow(pastureId, eventSale.Id, eventSale.SaleAt, cow))
  42. }
  43. return res
  44. }