event_pregnant_check.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package model
  2. import (
  3. "kpt-pasture/util"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type EventPregnantCheck struct {
  8. Id int64 `json:"id"`
  9. CowId int64 `json:"cowId"`
  10. DayAge int32 `json:"dayAge"`
  11. Lact int8 `json:"lact"`
  12. MatingAge int32 `json:"matingAge"`
  13. PlanDay int64 `json:"planDay"`
  14. RealityDay int64 `json:"realityDay"`
  15. EndDay int64 `json:"endDay"`
  16. PregnantCheckName string `json:"pregnantCheckName"`
  17. PregnantCheckResult pasturePb.PregnantCheckResult_Kind `json:"pregnantCheckResult"`
  18. PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind `json:"pregnantCheckMethod"`
  19. Status pasturePb.IsShow_Kind `json:"status"`
  20. OperationId int64 `json:"operationId"`
  21. OperationName string `json:"operationName"`
  22. Remarks string `json:"remarks"`
  23. CreatedAt int64 `json:"createdAt"`
  24. UpdatedAt int64 `json:"updatedAt"`
  25. }
  26. func (e *EventPregnantCheck) TableName() string {
  27. return "event_pregnant_check"
  28. }
  29. func NewEventPregnantCheck(cow *Cow, pregnantCheckName string) *EventPregnantCheck {
  30. return &EventPregnantCheck{
  31. CowId: cow.Id,
  32. DayAge: cow.GetDayAge(),
  33. Lact: int8(cow.Lact),
  34. PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutDate2)),
  35. EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutDate2)),
  36. PregnantCheckName: pregnantCheckName,
  37. Status: pasturePb.IsShow_No,
  38. }
  39. }
  40. func NewEventPregnantCheckList(cowList []*Cow, pregnantCheckName string) []*EventPregnantCheck {
  41. res := make([]*EventPregnantCheck, len(cowList))
  42. for i, cow := range cowList {
  43. if cow.BreedStatus != pasturePb.BreedStatus_Breeding {
  44. continue
  45. }
  46. res[i] = NewEventPregnantCheck(cow, pregnantCheckName)
  47. }
  48. return res
  49. }
  50. type EventPregnantCheckSlice []*EventPregnantCheck
  51. func (e EventPregnantCheckSlice) ToPB(
  52. pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
  53. pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
  54. ) []*pasturePb.SearchPregnantCheckList {
  55. result := make([]*pasturePb.SearchPregnantCheckList, len(e))
  56. for i, v := range e {
  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(v.PlanDay),
  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: time.Unix(v.PlanDay, 0).Format(LayoutDate2),
  105. CheckName: PregnantCheckNameMap[v.PregnantCheckName],
  106. }
  107. }
  108. return res
  109. }