cow.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 int32 `json:"father_id"`
  22. MotherId int32 `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: req.FatherId,
  60. MotherId: 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 (c *Cow) GetDayAge() int32 {
  72. return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
  73. }
  74. func (c *Cow) GetDaysPregnant() int32 {
  75. return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
  76. }