event_pregnant_check.go 5.9 KB

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