event_estrus.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. DayAge int32 `json:"dayAge"`
  15. CalvingAge int32 `json:"calvingAge"`
  16. ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
  17. LastEstrusDate string `json:"lastEstrusDate"`
  18. IsMating pasturePb.IsShow_Kind `json:"isMating"`
  19. UnMatingReasonsKind pasturePb.UnMatingReasons_Kind `json:"unMatingReasonsKind"`
  20. UnMatingReasonsName string `json:"unMatingReasonsName"`
  21. Remarks string `json:"remarks"`
  22. IsShow pasturePb.IsShow_Kind `json:"isShow"`
  23. OperationId int64 `json:"operationId"`
  24. OperationName string `json:"operationName"`
  25. MessageId int64 `json:"messageId"`
  26. MessageName string `json:"messageName"`
  27. CreatedAt int64 `json:"createdAt"`
  28. UpdatedAt int64 `json:"updatedAt"`
  29. }
  30. func (e *EventEstrus) TableName() string {
  31. return "event_estrus"
  32. }
  33. func NewEventEstrus(
  34. pastureId int64,
  35. cow *Cow,
  36. exposeEstrusType pasturePb.ExposeEstrusType_Kind,
  37. isShow pasturePb.IsShow_Kind,
  38. operationUser, currentUser *SystemUser,
  39. ) *EventEstrus {
  40. return &EventEstrus{
  41. PastureId: pastureId,
  42. CowId: cow.Id,
  43. Lact: cow.Lact,
  44. DayAge: cow.DayAge,
  45. CalvingAge: cow.CalvingAge,
  46. NeckRingNumber: cow.NeckRingNumber,
  47. EarNumber: cow.EarNumber,
  48. ExposeEstrusType: exposeEstrusType,
  49. IsShow: isShow,
  50. OperationId: operationUser.Id,
  51. OperationName: operationUser.Name,
  52. MessageId: currentUser.Id,
  53. MessageName: currentUser.Name,
  54. }
  55. }
  56. type EstrusSlice []*EventEstrus
  57. func (e EstrusSlice) ToPB(
  58. dB *kptstore.DB,
  59. getCowInfo func(dB *kptstore.DB, cowId int64) *Cow,
  60. getCowLastEvent func(DB *kptstore.DB, cowId int64, eventCategoryId pasturePb.EventCategory_Kind) *EventCowLog,
  61. ) []*pasturePb.EstrusItems {
  62. res := make([]*pasturePb.EstrusItems, len(e))
  63. for i, v := range e {
  64. cowInfo := getCowInfo(dB, v.CowId)
  65. lastEventLog := getCowLastEvent(dB, v.CowId, pasturePb.EventCategory_Breed)
  66. planDay, optimumMatingTime := "", ""
  67. lastBreedEventDetails := ""
  68. if lastEventLog != nil {
  69. lastBreedEventDetails = fmt.Sprintf("%s %s", lastEventLog.EventTypeName, lastEventLog.EventDescription)
  70. }
  71. res[i] = &pasturePb.EstrusItems{
  72. Id: int32(v.Id),
  73. CowId: int32(v.CowId),
  74. EarNumber: v.EarNumber,
  75. DayAge: v.DayAge,
  76. Lact: v.Lact,
  77. PenName: cowInfo.PenName,
  78. Status: v.IsShow,
  79. CalvingAge: int32(cowInfo.CalvingAge),
  80. PlanDay: planDay,
  81. MatingTimes: cowInfo.MatingTimes,
  82. OptimumMatingStartTime: optimumMatingTime,
  83. OptimumMatingEndTime: optimumMatingTime,
  84. LastBreedEventDetails: lastBreedEventDetails,
  85. }
  86. }
  87. return res
  88. }