calving_calf.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. BirthAt int64 `json:"birthAt"`
  8. MotherId int64 `json:"motherId"`
  9. EarNumber string `json:"earNumber"`
  10. Sex pasturePb.Genders_Kind `json:"sex"`
  11. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  12. BirthWeight int64 `json:"birthWeight"`
  13. IsLive pasturePb.IsShow_Kind `json:"isLive"`
  14. IsAdoption pasturePb.IsShow_Kind `json:"isAdoption"`
  15. PenId int32 `json:"penId"`
  16. WeaningAt int64 `json:"weaningAt"`
  17. CurrentWeight int64 `json:"currentWeight"`
  18. Remarks string `json:"remarks"`
  19. CreatedAt int64 `json:"createdAt"`
  20. UpdatedAt int64 `json:"updatedAt"`
  21. }
  22. func (e *CalvingCalf) TableName() string {
  23. return "calving_calf"
  24. }
  25. func NewEventCalvingCalf(motherId, calvingId int64, req *pasturePb.EventCalving) []*CalvingCalf {
  26. calvingCalfList := make([]*CalvingCalf, 0)
  27. for _, v := range req.CalfItemList {
  28. isAdoption := v.IsAdoption
  29. if v.IsLive == pasturePb.IsShow_No {
  30. isAdoption = pasturePb.IsShow_No
  31. }
  32. calvingCalfList = append(calvingCalfList, &CalvingCalf{
  33. EarNumber: v.EarNumber,
  34. CalvingId: calvingId,
  35. CowId: int64(v.CowId),
  36. BirthAt: int64(req.CalvingAt),
  37. PenId: v.PenId,
  38. BirthWeight: int64(v.Weight * 1000),
  39. CurrentWeight: int64(v.Weight * 1000),
  40. Sex: v.Sex,
  41. MotherId: motherId,
  42. Remarks: v.Remarks,
  43. IsAdoption: isAdoption,
  44. IsLive: v.IsLive,
  45. })
  46. }
  47. return calvingCalfList
  48. }