cow.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. LastPregnantCheckAt int64 `json:"last_pregnant_check_at"`
  33. LastDryMilkAt int64 `json:"last_dry_milk_at"`
  34. CreatedAt int64 `json:"created_at"`
  35. UpdatedAt int64 `json:"updated_at"`
  36. }
  37. func (c *Cow) TableName() string {
  38. return "cow"
  39. }
  40. func NewCow(req *pasturePb.SearchEnterData) *Cow {
  41. var (
  42. status int32 = 1
  43. isPregnant pasturePb.IsShow_Kind = pasturePb.IsShow_No
  44. )
  45. if req.BreedStatusId == 4 || req.BreedStatusId == 5 {
  46. isPregnant = pasturePb.IsShow_Ok
  47. status = 4
  48. }
  49. return &Cow{
  50. Sex: req.Sex,
  51. EarNumber: req.EarNumber,
  52. PenId: int64(req.PenId),
  53. Lact: req.Lact,
  54. TypeId: req.CowTypeId,
  55. BreedStatusId: req.BreedStatusId,
  56. KindId: req.CowKindId,
  57. SourceId: req.CowSourceId,
  58. FatherId: req.FatherId,
  59. MotherId: req.MotherId,
  60. IsRemove: pasturePb.IsShow_Ok,
  61. IsPregnant: isPregnant,
  62. Status: status,
  63. WeaningAt: int64(req.WeaningAt),
  64. BirthAt: int64(req.BirthAt),
  65. FirstMatingAt: int64(req.MatingAt),
  66. LastMatingAt: int64(req.MatingAt),
  67. LastPregnantCheckAt: int64(req.PregnancyCheckAt),
  68. }
  69. }
  70. func (c *Cow) GetDayAge() int32 {
  71. return int32(math.Floor(float64(time.Now().Unix()-c.BirthAt) / 86400))
  72. }