event_calving_calf.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type EventCalvingCalf struct {
  4. Id int64 `json:"id"`
  5. CalvingId int64 `json:"calving_id"`
  6. CowId int64 `json:"cow_id"`
  7. MotherId int64 `json:"mother_id"`
  8. EarNumber string `json:"ear_number"`
  9. Sex pasturePb.Genders_Kind `json:"sex"`
  10. Weight int64 `json:"weight"`
  11. IsLive pasturePb.IsShow_Kind `json:"is_live"`
  12. IsAdoption pasturePb.IsShow_Kind `json:"is_adoption"`
  13. PenId int32 `json:"pen_id"`
  14. Remarks string `json:"remarks"`
  15. CreatedAt int64 `json:"created_at"`
  16. UpdatedAt int64 `json:"updated_at"`
  17. }
  18. func (e *EventCalvingCalf) TableName() string {
  19. return "event_calving_calf"
  20. }
  21. func NewEventCalvingCalf(motherId, calvingId int64, req *pasturePb.CalvingEventRequest) []*EventCalvingCalf {
  22. calvingCalfList := make([]*EventCalvingCalf, 0)
  23. for _, v := range req.CalfItemList {
  24. isAdoption := v.IsAdoption
  25. if v.IsLive == pasturePb.IsShow_No {
  26. isAdoption = pasturePb.IsShow_No
  27. }
  28. calvingCalfList = append(calvingCalfList, &EventCalvingCalf{
  29. EarNumber: v.EarNumber,
  30. CalvingId: calvingId,
  31. PenId: v.PenId,
  32. Weight: int64(v.Weight * 100),
  33. Sex: v.Sex,
  34. MotherId: motherId,
  35. Remarks: v.Remarks,
  36. IsAdoption: isAdoption,
  37. IsLive: v.IsLive,
  38. })
  39. }
  40. return calvingCalfList
  41. }