neck_ring_estrus.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package model
  2. import (
  3. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  4. )
  5. type NeckRingEstrus struct {
  6. Id int64 `json:"id"`
  7. PastureId int64 `json:"pastureId"`
  8. CowId int64 `json:"cowId"`
  9. NeckRingNumber string `json:"neckRingNumber"`
  10. EarNumber string `json:"earNumber"`
  11. Lact int32 `json:"lact"`
  12. ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
  13. EstrusStartDate string `json:"estrusStartDate"`
  14. ActiveDate string `json:"activeDate"`
  15. LastEstrusDate string `json:"lastEstrusDate"`
  16. Level pasturePb.EstrusLevel_Kind `json:"level"`
  17. IsPeak pasturePb.IsShow_Kind `json:"isPeak"`
  18. DayHigh int32 `json:"dayHigh"`
  19. MaxHigh int32 `json:"maxHigh"`
  20. CheckResult pasturePb.CheckResult_Kind `json:"checkResult"`
  21. Remarks string `json:"remarks"`
  22. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  23. CreatedAt int64 `json:"createdAt"`
  24. UpdatedAt int64 `json:"updatedAt"`
  25. }
  26. func (n *NeckRingEstrus) TableName() string {
  27. return "neck_ring_estrus"
  28. }
  29. func NewNeckRingEstrus(
  30. pastureId int64,
  31. cow *Cow,
  32. exposeEstrusType pasturePb.ExposeEstrusType_Kind,
  33. level pasturePb.EstrusLevel_Kind,
  34. checkResult pasturePb.CheckResult_Kind,
  35. isShow pasturePb.IsShow_Kind,
  36. ) *NeckRingEstrus {
  37. return &NeckRingEstrus{
  38. PastureId: pastureId,
  39. CowId: cow.Id,
  40. NeckRingNumber: cow.NeckRingNumber,
  41. EarNumber: cow.EarNumber,
  42. Lact: cow.Lact,
  43. ExposeEstrusType: exposeEstrusType,
  44. Level: level,
  45. IsShow: isShow,
  46. CheckResult: checkResult,
  47. }
  48. }
  49. type NeckRingEstrusSlice []*NeckRingEstrus
  50. func (n NeckRingEstrusSlice) ToPB(cowMap map[int64]*Cow, eventLogMap map[int64]string) []*pasturePb.EstrusItems {
  51. res := make([]*pasturePb.EstrusItems, len(n))
  52. for i, v := range n {
  53. cow, ok := cowMap[v.CowId]
  54. if !ok {
  55. cow = &Cow{Id: v.CowId}
  56. }
  57. lastBreedEventDetails := ""
  58. desc, ok := eventLogMap[cow.Id]
  59. if ok {
  60. lastBreedEventDetails = desc
  61. }
  62. res[i] = &pasturePb.EstrusItems{
  63. Id: int32(v.Id),
  64. CowId: int32(v.CowId),
  65. EarNumber: v.EarNumber,
  66. PenId: cow.PenId,
  67. PenName: cow.PenName,
  68. DayAge: cow.DayAge,
  69. MatingTimes: cow.MatingTimes,
  70. Lact: cow.Lact,
  71. CalvingAge: cow.CalvingAge,
  72. AbortionAge: cow.AbortionAge,
  73. OptimumMatingStartTime: "",
  74. OptimumMatingEndTime: "",
  75. LastBreedEventDetails: lastBreedEventDetails,
  76. Level: v.Level,
  77. EstrusInterval: 0,
  78. }
  79. }
  80. return res
  81. }