calving_calf.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. var CalfDefaultDayAge = int32(60)
  4. type CalvingCalf struct {
  5. Id int64 `json:"id"`
  6. PastureId int64 `json:"pastureId"`
  7. CalvingId int64 `json:"calvingId"`
  8. CowId int64 `json:"cow_id"`
  9. BirthAt int64 `json:"birthAt"`
  10. MotherId int64 `json:"motherId"`
  11. EarNumber string `json:"earNumber"`
  12. Sex pasturePb.Genders_Kind `json:"sex"`
  13. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  14. BirthWeight int64 `json:"birthWeight"`
  15. IsLive pasturePb.IsShow_Kind `json:"isLive"`
  16. IsAdoption pasturePb.IsShow_Kind `json:"isAdoption"`
  17. PenId int32 `json:"penId"`
  18. PenName string `json:"penName"`
  19. WeaningAt int64 `json:"weaningAt"`
  20. CurrentWeight int64 `json:"currentWeight"`
  21. DeathAt int64 `json:"deathAt"`
  22. Remarks string `json:"remarks"`
  23. CreatedAt int64 `json:"createdAt"`
  24. UpdatedAt int64 `json:"updatedAt"`
  25. }
  26. func (c *CalvingCalf) TableName() string {
  27. return "calving_calf"
  28. }
  29. func (c *CalvingCalf) DeathEventUpdate(deathAt int64) {
  30. c.DeathAt = deathAt
  31. c.IsLive = pasturePb.IsShow_No
  32. }
  33. func NewEventCalvingCalf(pastureId, calvingId, calvingAt int64, motherInfo *Cow, penMap map[int32]*Pen, req *pasturePb.CalfItem) *CalvingCalf {
  34. isAdoption := req.IsAdoption
  35. if req.IsLive == pasturePb.IsShow_No {
  36. isAdoption = pasturePb.IsShow_No
  37. }
  38. penId := int32(0)
  39. penName := ""
  40. if req.PenId > 0 {
  41. pen := penMap[req.PenId]
  42. penId = pen.Id
  43. penName = pen.Name
  44. }
  45. return &CalvingCalf{
  46. PastureId: pastureId,
  47. EarNumber: req.EarNumber,
  48. CalvingId: calvingId,
  49. CowId: int64(req.CowId),
  50. BirthAt: calvingAt,
  51. PenId: penId,
  52. PenName: penName,
  53. BirthWeight: int64(req.Weight * 1000),
  54. CurrentWeight: int64(req.Weight * 1000),
  55. Sex: req.Sex,
  56. MotherId: motherInfo.Id,
  57. Remarks: req.Remarks,
  58. IsAdoption: isAdoption,
  59. IsLive: req.IsLive,
  60. CowKind: motherInfo.CowKind,
  61. }
  62. }