event_pregnant_check.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventPregnantCheck struct {
  7. Id int64 `json:"id"`
  8. CowId int64 `json:"cowId"`
  9. DayAge int32 `json:"dayAge"`
  10. Lact int8 `json:"lact"`
  11. MatingAge int32 `json:"matingAge"`
  12. PlanDay string `json:"planDay"`
  13. RealityDay string `json:"realityDay"`
  14. EndDay string `json:"endDay"`
  15. PregnantCheckName string `json:"pregnantCheckName"`
  16. PregnantCheckResult pasturePb.PregnantCheckResult_Kind `json:"pregnantCheckResult"`
  17. PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind `json:"pregnantCheckMethod"`
  18. Status pasturePb.IsShow_Kind `json:"status"`
  19. OperationId int64 `json:"operationId"`
  20. OperationName string `json:"operationName"`
  21. Remarks string `json:"remarks"`
  22. CreatedAt int64 `json:"createdAt"`
  23. UpdatedAt int64 `json:"updatedAt"`
  24. }
  25. func (e *EventPregnantCheck) TableName() string {
  26. return "event_pregnant_check"
  27. }
  28. func NewEventPregnantCheck(cow *Cow, pregnantCheckAt int64, pregnantCheckName string) *EventPregnantCheck {
  29. return &EventPregnantCheck{
  30. CowId: cow.Id,
  31. DayAge: cow.GetDayAge(),
  32. Lact: int8(cow.Lact),
  33. PlanDay: time.Unix(pregnantCheckAt, 0).Format(LayoutTime),
  34. EndDay: time.Unix(pregnantCheckAt, 0).Format(LayoutTime),
  35. PregnantCheckName: pregnantCheckName,
  36. Status: pasturePb.IsShow_No,
  37. }
  38. }
  39. func NewEventPregnantCheckList(cowList []*Cow, pregnantCheckAt int64, pregnantCheckName string) []*EventPregnantCheck {
  40. res := make([]*EventPregnantCheck, len(cowList))
  41. for i, cow := range cowList {
  42. if cow.BreedStatus != pasturePb.BreedStatus_Breeding {
  43. continue
  44. }
  45. res[i] = NewEventPregnantCheck(cow, pregnantCheckAt, pregnantCheckName)
  46. }
  47. return res
  48. }
  49. type EventPregnantCheckSlice []*EventPregnantCheck
  50. func (e EventPregnantCheckSlice) ToPB(
  51. pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
  52. pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
  53. ) []*pasturePb.SearchPregnantCheckList {
  54. result := make([]*pasturePb.SearchPregnantCheckList, len(e))
  55. for i, v := range e {
  56. pregnantCheckAt, _ := time.Parse(LayoutTime, v.PlanDay)
  57. result[i] = &pasturePb.SearchPregnantCheckList{
  58. Id: int32(v.Id),
  59. CowId: int32(v.CowId),
  60. DayAge: v.DayAge,
  61. Lact: int32(v.Lact),
  62. PregnantCheckAt: int32(pregnantCheckAt.Unix()),
  63. PregnantCheckResult: v.PregnantCheckResult,
  64. PregnantCheckResultName: pregnantCheckResultMap[v.PregnantCheckResult],
  65. PregnantCheckMethod: v.PregnantCheckMethod,
  66. PregnantCheckMethodName: pregnantCheckMethodMap[v.PregnantCheckMethod],
  67. Remarks: v.Remarks,
  68. OperationId: int32(v.OperationId),
  69. OperationName: v.OperationName,
  70. CreatedAt: int32(v.CreatedAt),
  71. UpdatedAt: int32(v.UpdatedAt),
  72. }
  73. }
  74. return result
  75. }
  76. type PregnantCheckHeader struct {
  77. Id string `json:"id"`
  78. CowId string `json:"cowId"`
  79. CowType string `json:"cowType"`
  80. DayAge string `json:"dayAge"`
  81. Lact string `json:"lact"`
  82. PlanDay string `json:"planDay"`
  83. PenName string `json:"penName"`
  84. CheckName string `json:"checkName"`
  85. }
  86. type PregnantCheckBody struct {
  87. Id int64 `json:"id"`
  88. CowId int64 `json:"cowId"`
  89. CowType pasturePb.CowType_Kind `json:"cowType"`
  90. DayAge int64 `json:"dayAge"`
  91. Lact int32 `json:"lact"`
  92. PlanDay string `json:"planDay"`
  93. PenName string `json:"penName"`
  94. CheckName string `json:"checkName"`
  95. }
  96. func (e EventPregnantCheckSlice) ToPB2() []*PregnantCheckBody {
  97. res := make([]*PregnantCheckBody, len(e))
  98. for i, v := range e {
  99. res[i] = &PregnantCheckBody{
  100. Id: v.Id,
  101. CowId: v.CowId,
  102. DayAge: int64(v.DayAge),
  103. Lact: int32(v.Lact),
  104. PlanDay: v.PlanDay,
  105. CheckName: PregnantCheckNameMap[v.PregnantCheckName],
  106. }
  107. }
  108. return res
  109. }