cow.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 pasturePb.CowType_Kind `json:"type_id"`
  16. BreedStatusId pasturePb.BreedStatus_Kind `json:"breed_status_id"`
  17. KindId pasturePb.CowKind_Kind `json:"kind_id"`
  18. BirthWeight int64 `json:"birth_weight"`
  19. CurrentWeight int64 `json:"current_weight"`
  20. SourceId pasturePb.CowSource_Kind `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 pasturePb.CowStatus_Kind `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. LastWeightAt int64 `json:"last_weight_at"`
  36. CreatedAt int64 `json:"created_at"`
  37. UpdatedAt int64 `json:"updated_at"`
  38. }
  39. func (c *Cow) TableName() string {
  40. return "cow"
  41. }
  42. func NewCow(req *pasturePb.SearchEnterData) *Cow {
  43. var (
  44. status = pasturePb.CowStatus_Calving
  45. isPregnant = pasturePb.IsShow_No
  46. )
  47. if req.BreedStatusId == pasturePb.BreedStatus_InCheck_Pregnant ||
  48. req.BreedStatusId == pasturePb.BreedStatus_Recheck_Pregnant {
  49. isPregnant = pasturePb.IsShow_Ok
  50. status = pasturePb.CowStatus_Pregnant
  51. }
  52. return &Cow{
  53. Sex: req.Sex,
  54. EarNumber: req.EarNumber,
  55. PenId: int64(req.PenId),
  56. Lact: req.Lact,
  57. TypeId: req.CowTypeId,
  58. BreedStatusId: req.BreedStatusId,
  59. KindId: req.CowKindId,
  60. SourceId: req.CowSourceId,
  61. FatherId: int64(req.FatherId),
  62. MotherId: int64(req.MotherId),
  63. IsRemove: pasturePb.IsShow_Ok,
  64. IsPregnant: isPregnant,
  65. Status: status,
  66. WeaningAt: int64(req.WeaningAt),
  67. BirthAt: int64(req.BirthAt),
  68. FirstMatingAt: int64(req.MatingAt),
  69. LastMatingAt: int64(req.MatingAt),
  70. LastPregnantCheckAt: int64(req.PregnancyCheckAt),
  71. }
  72. }
  73. func NewCalfCow(motherId, fatherId int64, calf *EventCalvingCalf) *Cow {
  74. return &Cow{
  75. Sex: calf.Sex,
  76. EarNumber: calf.EarNumber,
  77. PenId: int64(calf.PenId),
  78. TypeId: pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
  79. BreedStatusId: pasturePb.BreedStatus_Unmarried, // 未配
  80. KindId: pasturePb.CowKind_HST, // 荷斯坦
  81. BirthWeight: calf.Weight,
  82. SourceId: pasturePb.CowSource_Calving, // 产犊方式
  83. FatherId: fatherId,
  84. MotherId: motherId,
  85. IsRemove: pasturePb.IsShow_Ok,
  86. IsPregnant: pasturePb.IsShow_No,
  87. Status: pasturePb.CowStatus_Calving, // 哺乳犊牛
  88. }
  89. }
  90. // GetDayAge 日龄
  91. func (c *Cow) GetDayAge() int32 {
  92. return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
  93. }
  94. // GetDaysPregnant 在胎天数
  95. func (c *Cow) GetDaysPregnant() int32 {
  96. if c.Status == pasturePb.CowStatus_Breeding || c.Status == pasturePb.CowStatus_Pregnant {
  97. return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
  98. }
  99. return 0
  100. }
  101. // GetLactationDays 泌乳天数
  102. func (c *Cow) GetLactationDays() int32 {
  103. if c.Status == pasturePb.CowStatus_Calving {
  104. return int32(math.Floor(float64(time.Now().Unix()-c.LastCalvingAt) / 86400))
  105. }
  106. return 0
  107. }