event_estrus.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 EventEstrus 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. OperationId int64 `json:"operationId"`
  26. OperationName string `json:"operationName"`
  27. MessageId int64 `json:"messageId"`
  28. MessageName string `json:"messageName"`
  29. CreatedAt int64 `json:"createdAt"`
  30. UpdatedAt int64 `json:"updatedAt"`
  31. }
  32. func (e *EventEstrus) TableName() string {
  33. return "event_estrus"
  34. }
  35. func NewEventEstrus(
  36. pastureId int64,
  37. exposeEstrusType pasturePb.ExposeEstrusType_Kind,
  38. level pasturePb.EstrusLevel_Kind,
  39. checkResult pasturePb.CheckResult_Kind,
  40. isShow, isPerk pasturePb.IsShow_Kind,
  41. lastEstrusDate, activeDate string,
  42. dayHigh, maxHigh int32,
  43. cow *Cow,
  44. ) *EventEstrus {
  45. return &EventEstrus{
  46. PastureId: pastureId,
  47. CowId: cow.Id,
  48. NeckRingNumber: cow.NeckRingNumber,
  49. EarNumber: cow.EarNumber,
  50. Lact: cow.Lact,
  51. ExposeEstrusType: exposeEstrusType,
  52. LastEstrusDate: lastEstrusDate,
  53. ActiveDate: activeDate,
  54. Level: level,
  55. IsShow: isShow,
  56. CheckResult: checkResult,
  57. DayHigh: dayHigh,
  58. MaxHigh: maxHigh,
  59. IsPeak: isPerk,
  60. }
  61. }
  62. type EstrusSlice []*EventEstrus
  63. func (e EstrusSlice) ToPB(
  64. dB *kptstore.DB,
  65. getCowInfo func(dB *kptstore.DB, cowId int64) *Cow,
  66. getCowLastEvent func(DB *kptstore.DB, cowId int64, eventCategoryId pasturePb.EventCategory_Kind) *EventCowLog,
  67. ) []*pasturePb.EstrusItems {
  68. res := make([]*pasturePb.EstrusItems, len(e))
  69. for i, v := range e {
  70. cowInfo := getCowInfo(dB, v.CowId)
  71. lastEventLog := getCowLastEvent(dB, v.CowId, pasturePb.EventCategory_Breed)
  72. planDay, optimumMatingTime := "", ""
  73. lastBreedEventDetails := ""
  74. if lastEventLog != nil {
  75. lastBreedEventDetails = fmt.Sprintf("%s %s", lastEventLog.EventTypeName, lastEventLog.EventDescription)
  76. }
  77. res[i] = &pasturePb.EstrusItems{
  78. Id: int32(v.Id),
  79. CowId: int32(v.CowId),
  80. EarNumber: v.EarNumber,
  81. DayAge: cowInfo.DayAge,
  82. Lact: cowInfo.Lact,
  83. Level: v.Level,
  84. PenName: cowInfo.PenName,
  85. Status: v.IsShow,
  86. CalvingAge: int32(cowInfo.CalvingAge),
  87. PlanDay: planDay,
  88. MatingTimes: cowInfo.MatingTimes,
  89. OptimumMatingStartTime: optimumMatingTime,
  90. OptimumMatingEndTime: optimumMatingTime,
  91. LastBreedEventDetails: lastBreedEventDetails,
  92. }
  93. }
  94. return res
  95. }