cow.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 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 = pasturePb.CowStatus_Calving
  44. isPregnant = pasturePb.IsShow_No
  45. )
  46. if req.BreedStatusId == pasturePb.BreedStatus_InCheck_Pregnant ||
  47. req.BreedStatusId == pasturePb.BreedStatus_Recheck_Pregnant {
  48. isPregnant = pasturePb.IsShow_Ok
  49. status = pasturePb.CowStatus_Pregnant
  50. }
  51. return &Cow{
  52. Sex: req.Sex,
  53. EarNumber: req.EarNumber,
  54. PenId: int64(req.PenId),
  55. Lact: req.Lact,
  56. TypeId: req.CowTypeId,
  57. BreedStatusId: req.BreedStatusId,
  58. KindId: req.CowKindId,
  59. SourceId: req.CowSourceId,
  60. FatherId: int64(req.FatherId),
  61. MotherId: int64(req.MotherId),
  62. IsRemove: pasturePb.IsShow_Ok,
  63. IsPregnant: isPregnant,
  64. Status: status,
  65. WeaningAt: int64(req.WeaningAt),
  66. BirthAt: int64(req.BirthAt),
  67. FirstMatingAt: int64(req.MatingAt),
  68. LastMatingAt: int64(req.MatingAt),
  69. LastPregnantCheckAt: int64(req.PregnancyCheckAt),
  70. }
  71. }
  72. func NewCalfCow(motherId, fatherId int64, calf *EventCalvingCalf) *Cow {
  73. return &Cow{
  74. Sex: calf.Sex,
  75. EarNumber: calf.EarNumber,
  76. PenId: int64(calf.PenId),
  77. TypeId: pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
  78. BreedStatusId: pasturePb.BreedStatus_Unmarried, // 未配
  79. KindId: pasturePb.CowKind_HST, // 荷斯坦
  80. BirthWeight: calf.Weight,
  81. SourceId: pasturePb.CowSource_Calving, // 产犊方式
  82. FatherId: fatherId,
  83. MotherId: motherId,
  84. IsRemove: pasturePb.IsShow_Ok,
  85. IsPregnant: pasturePb.IsShow_No,
  86. Status: pasturePb.CowStatus_Calving, // 哺乳犊牛
  87. }
  88. }
  89. func (c *Cow) GetDayAge() int32 {
  90. return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
  91. }
  92. func (c *Cow) GetDaysPregnant() int32 {
  93. return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
  94. }