calving_calf.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. PastureId int64 `json:"pastureId"`
  6. CalvingId int64 `json:"calvingId"`
  7. CowId int64 `json:"cow_id"`
  8. BirthAt int64 `json:"birthAt"`
  9. MotherId int64 `json:"motherId"`
  10. EarNumber string `json:"earNumber"`
  11. Sex pasturePb.Genders_Kind `json:"sex"`
  12. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  13. BirthWeight int64 `json:"birthWeight"`
  14. IsLive pasturePb.IsShow_Kind `json:"isLive"`
  15. IsAdoption pasturePb.IsShow_Kind `json:"isAdoption"`
  16. PenId int32 `json:"penId"`
  17. PenName string `json:"penName"`
  18. WeaningAt int64 `json:"weaningAt"`
  19. CurrentWeight int64 `json:"currentWeight"`
  20. Remarks string `json:"remarks"`
  21. CreatedAt int64 `json:"createdAt"`
  22. UpdatedAt int64 `json:"updatedAt"`
  23. }
  24. func (e *CalvingCalf) TableName() string {
  25. return "calving_calf"
  26. }
  27. func NewEventCalvingCalf(pastureId, motherId, calvingId, calvingAt int64, penMap map[int32]*Pen, req *pasturePb.CalfItem) *CalvingCalf {
  28. isAdoption := req.IsAdoption
  29. if req.IsLive == pasturePb.IsShow_No {
  30. isAdoption = pasturePb.IsShow_No
  31. }
  32. penId := int32(0)
  33. penName := ""
  34. if req.PenId > 0 {
  35. pen := penMap[req.PenId]
  36. penId = pen.Id
  37. penName = pen.Name
  38. }
  39. return &CalvingCalf{
  40. PastureId: pastureId,
  41. EarNumber: req.EarNumber,
  42. CalvingId: calvingId,
  43. CowId: int64(req.CowId),
  44. BirthAt: calvingAt,
  45. PenId: penId,
  46. PenName: penName,
  47. BirthWeight: int64(req.Weight * 1000),
  48. CurrentWeight: int64(req.Weight * 1000),
  49. Sex: req.Sex,
  50. MotherId: motherId,
  51. Remarks: req.Remarks,
  52. IsAdoption: isAdoption,
  53. IsLive: req.IsLive,
  54. }
  55. }