event_pregnant_check.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. CowType pasturePb.CowType_Kind `json:"cowType"`
  11. PenId int32 `json:"penId"`
  12. PenName string `json:"penName"`
  13. DayAge int32 `json:"dayAge"`
  14. Lact int8 `json:"lact"`
  15. MatingAge int32 `json:"matingAge"`
  16. PlanDay int64 `json:"planDay"`
  17. RealityDay int64 `json:"realityDay"`
  18. EndDay int64 `json:"endDay"`
  19. PregnantCheckName string `json:"pregnantCheckName"`
  20. PregnantCheckResult pasturePb.PregnantCheckResult_Kind `json:"pregnantCheckResult"`
  21. PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind `json:"pregnantCheckMethod"`
  22. BullId string `json:"bullId"`
  23. Status pasturePb.IsShow_Kind `json:"status"`
  24. OperationId int64 `json:"operationId"`
  25. OperationName string `json:"operationName"`
  26. Remarks string `json:"remarks"`
  27. CreatedAt int64 `json:"createdAt"`
  28. UpdatedAt int64 `json:"updatedAt"`
  29. }
  30. func (e *EventPregnantCheck) TableName() string {
  31. return "event_pregnant_check"
  32. }
  33. func NewEventPregnantCheck(cow *Cow, penMap map[int32]*Pen, pregnantCheckName string) *EventPregnantCheck {
  34. return &EventPregnantCheck{
  35. CowId: cow.Id,
  36. CowType: cow.CowType,
  37. PenId: cow.PenId,
  38. PenName: penMap[cow.PenId].Name,
  39. DayAge: cow.GetDayAge(),
  40. Lact: int8(cow.Lact),
  41. PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutDate2)),
  42. EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutDate2)),
  43. PregnantCheckName: pregnantCheckName,
  44. BullId: cow.LastBullNumber,
  45. Status: pasturePb.IsShow_No,
  46. }
  47. }
  48. func NewEventPregnantCheckList(cowList []*Cow, penMap map[int32]*Pen, pregnantCheckName string) []*EventPregnantCheck {
  49. res := make([]*EventPregnantCheck, len(cowList))
  50. for i, cow := range cowList {
  51. if cow.BreedStatus != pasturePb.BreedStatus_Breeding {
  52. continue
  53. }
  54. res[i] = NewEventPregnantCheck(cow, penMap, pregnantCheckName)
  55. }
  56. return res
  57. }
  58. type EventPregnantCheckSlice []*EventPregnantCheck
  59. func (e EventPregnantCheckSlice) ToPB(
  60. pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
  61. pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
  62. ) []*pasturePb.SearchPregnantCheckList {
  63. result := make([]*pasturePb.SearchPregnantCheckList, len(e))
  64. for i, v := range e {
  65. result[i] = &pasturePb.SearchPregnantCheckList{
  66. Id: int32(v.Id),
  67. CowId: int32(v.CowId),
  68. DayAge: v.DayAge,
  69. Lact: int32(v.Lact),
  70. PregnantCheckAt: int32(v.PlanDay),
  71. PregnantCheckResult: v.PregnantCheckResult,
  72. PregnantCheckResultName: pregnantCheckResultMap[v.PregnantCheckResult],
  73. PregnantCheckMethod: v.PregnantCheckMethod,
  74. PregnantCheckMethodName: pregnantCheckMethodMap[v.PregnantCheckMethod],
  75. Remarks: v.Remarks,
  76. OperationId: int32(v.OperationId),
  77. OperationName: v.OperationName,
  78. CreatedAt: int32(v.CreatedAt),
  79. UpdatedAt: int32(v.UpdatedAt),
  80. }
  81. }
  82. return result
  83. }
  84. func (e EventPregnantCheckSlice) ToPB3(
  85. pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
  86. pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
  87. ) []*pasturePb.PregnancyReportTable {
  88. res := make([]*pasturePb.PregnancyReportTable, len(e))
  89. for i, v := range e {
  90. pregnancyCheckName := ""
  91. if checkName, ok := PregnantCheckNameMap[v.PregnantCheckName]; ok {
  92. pregnancyCheckName = checkName
  93. }
  94. pregnantCheckMethodName := ""
  95. if checkMethodName, ok := pregnantCheckMethodMap[v.PregnantCheckMethod]; ok {
  96. pregnantCheckMethodName = checkMethodName
  97. }
  98. pregnantCheckResultName := ""
  99. if checkResultName, ok := pregnantCheckResultMap[v.PregnantCheckResult]; ok {
  100. pregnantCheckResultName = checkResultName
  101. }
  102. res[i] = &pasturePb.PregnancyReportTable{
  103. Id: int32(v.Id),
  104. CowId: int32(v.CowId),
  105. Lact: int32(v.Lact),
  106. PregnancyCheckName: pregnancyCheckName,
  107. PregnancyCheckAtFormat: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
  108. MatingAge: v.MatingAge,
  109. PregnantCheckMethod: v.PregnantCheckMethod,
  110. PregnantCheckMethodName: pregnantCheckMethodName,
  111. PregnantCheckResult: v.PregnantCheckResult,
  112. PregnantCheckResultName: pregnantCheckResultName,
  113. OperationName: v.OperationName,
  114. }
  115. }
  116. return res
  117. }