cow.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package model
  2. import (
  3. "math"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type Cow struct {
  8. Id int64 `json:"id"`
  9. Sex pasturePb.Genders_Kind `json:"sex"`
  10. NeckRingNumber string `json:"neck_ring_number"`
  11. EarNumber string `json:"ear_number"`
  12. EarOldNumber string `json:"ear_old_number"`
  13. PenId int64 `json:"pen_id"`
  14. Lact int32 `json:"lact"`
  15. TypeId int32 `json:"type_id"`
  16. BreedStatusId int32 `json:"breed_status_id"`
  17. KindId int32 `json:"kind_id"`
  18. BirthWeight int64 `json:"birth_weight"`
  19. CurrentWeight int64 `json:"current_weight"`
  20. SourceId int32 `json:"source_id"`
  21. FatherId int64 `json:"father_id"`
  22. MotherId int64 `json:"mother_id"`
  23. IsRemove pasturePb.IsShow_Kind `json:"is_remove"`
  24. IsPregnant pasturePb.IsShow_Kind `json:"is_pregnant"`
  25. Status int32 `json:"status"`
  26. WeaningAt int64 `json:"weaning_at"`
  27. BirthAt int64 `json:"birth_at"`
  28. FirstMatingAt int64 `json:"first_mating_at"`
  29. LastEstrusAt int64 `json:"last_estrus_at"`
  30. LastCalvingAt int64 `json:"last_calving_at"`
  31. LastMatingAt int64 `json:"last_mating_at"`
  32. LastBullId int64 `json:"last_bull_id"`
  33. LastPregnantCheckAt int64 `json:"last_pregnant_check_at"`
  34. LastDryMilkAt int64 `json:"last_dry_milk_at"`
  35. CreatedAt int64 `json:"created_at"`
  36. UpdatedAt int64 `json:"updated_at"`
  37. }
  38. func (c *Cow) TableName() string {
  39. return "cow"
  40. }
  41. func NewCow(req *pasturePb.SearchEnterData) *Cow {
  42. var (
  43. status int32 = 1
  44. isPregnant pasturePb.IsShow_Kind = pasturePb.IsShow_No
  45. )
  46. if req.BreedStatusId == 4 || req.BreedStatusId == 5 {
  47. isPregnant = pasturePb.IsShow_Ok
  48. status = 4
  49. }
  50. return &Cow{
  51. Sex: req.Sex,
  52. EarNumber: req.EarNumber,
  53. PenId: int64(req.PenId),
  54. Lact: req.Lact,
  55. TypeId: req.CowTypeId,
  56. BreedStatusId: req.BreedStatusId,
  57. KindId: req.CowKindId,
  58. SourceId: req.CowSourceId,
  59. FatherId: int64(req.FatherId),
  60. MotherId: int64(req.MotherId),
  61. IsRemove: pasturePb.IsShow_Ok,
  62. IsPregnant: isPregnant,
  63. Status: status,
  64. WeaningAt: int64(req.WeaningAt),
  65. BirthAt: int64(req.BirthAt),
  66. FirstMatingAt: int64(req.MatingAt),
  67. LastMatingAt: int64(req.MatingAt),
  68. LastPregnantCheckAt: int64(req.PregnancyCheckAt),
  69. }
  70. }
  71. func NewCalfCow(motherId, fatherId int64, calf *EventCalvingCalf) *Cow {
  72. return &Cow{
  73. Sex: calf.Sex,
  74. EarNumber: calf.EarNumber,
  75. PenId: int64(calf.PenId),
  76. TypeId: 6, // 哺乳犊牛 todo 改成enum
  77. BreedStatusId: 1, // 未配 todo 改成enum
  78. KindId: 1, // 荷斯坦 todo 改成enum
  79. BirthWeight: calf.Weight,
  80. SourceId: 2, // 产犊方式 todo 改成enum
  81. FatherId: fatherId,
  82. MotherId: motherId,
  83. IsRemove: pasturePb.IsShow_Ok,
  84. IsPregnant: pasturePb.IsShow_No,
  85. Status: 6, // 哺乳犊牛 todo 改成enum
  86. }
  87. }
  88. func (c *Cow) GetDayAge() int32 {
  89. return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
  90. }
  91. func (c *Cow) GetDaysPregnant() int32 {
  92. return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
  93. }