calving_calf.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type CalvingCalf struct {
  4. Id int64 `json:"id"`
  5. CalvingId int64 `json:"calvingId"`
  6. CowId int64 `json:"cow_id"`
  7. MotherId int64 `json:"motherId"`
  8. EarNumber string `json:"earNumber"`
  9. Sex pasturePb.Genders_Kind `json:"sex"`
  10. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  11. BrithWeight int64 `json:"brithWeight"`
  12. IsLive pasturePb.IsShow_Kind `json:"isLive"`
  13. IsAdoption pasturePb.IsShow_Kind `json:"isAdoption"`
  14. PenId int32 `json:"penId"`
  15. WeaningAt int64 `json:"weaningAt"`
  16. CurrentWeight int64 `json:"currentWeight"`
  17. Remarks string `json:"remarks"`
  18. CreatedAt int64 `json:"createdAt"`
  19. UpdatedAt int64 `json:"updatedAt"`
  20. }
  21. func (e *CalvingCalf) TableName() string {
  22. return "calving_calf"
  23. }
  24. func NewEventCalvingCalf(motherId, calvingId int64, req *pasturePb.EventCalving) []*CalvingCalf {
  25. calvingCalfList := make([]*CalvingCalf, 0)
  26. for _, v := range req.CalfItemList {
  27. isAdoption := v.IsAdoption
  28. if v.IsLive == pasturePb.IsShow_No {
  29. isAdoption = pasturePb.IsShow_No
  30. }
  31. calvingCalfList = append(calvingCalfList, &CalvingCalf{
  32. EarNumber: v.EarNumber,
  33. CalvingId: calvingId,
  34. PenId: v.PenId,
  35. BrithWeight: int64(v.Weight * 1000),
  36. CurrentWeight: int64(v.Weight * 1000),
  37. Sex: v.Sex,
  38. MotherId: motherId,
  39. Remarks: v.Remarks,
  40. IsAdoption: isAdoption,
  41. IsLive: v.IsLive,
  42. })
  43. }
  44. return calvingCalfList
  45. }