event_estrus.go 4.0 KB

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