neck_ring_estrus.go 3.3 KB

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