event_pregnant_check.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. MessageId int64 `json:"messageId"`
  27. MessageName string `json:"messageName"`
  28. Remarks string `json:"remarks"`
  29. CreatedAt int64 `json:"createdAt"`
  30. UpdatedAt int64 `json:"updatedAt"`
  31. }
  32. func (e *EventPregnantCheck) TableName() string {
  33. return "event_pregnant_check"
  34. }
  35. func NewEventPregnantCheck(cow *Cow, penMap map[int32]*Pen, pregnantCheckName string) *EventPregnantCheck {
  36. penName := ""
  37. if pen, ok := penMap[cow.PenId]; ok {
  38. penName = pen.Name
  39. }
  40. return &EventPregnantCheck{
  41. CowId: cow.Id,
  42. CowType: cow.CowType,
  43. PenId: cow.PenId,
  44. PenName: penName,
  45. DayAge: cow.GetDayAge(),
  46. Lact: int8(cow.Lact),
  47. PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutDate2)),
  48. EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutDate2)),
  49. PregnantCheckName: pregnantCheckName,
  50. BullId: cow.LastBullNumber,
  51. Status: pasturePb.IsShow_No,
  52. }
  53. }
  54. func NewEventPregnantCheckList(cowList []*Cow, penMap map[int32]*Pen, pregnantCheckName string) []*EventPregnantCheck {
  55. res := make([]*EventPregnantCheck, len(cowList))
  56. for i, cow := range cowList {
  57. if cow.BreedStatus != pasturePb.BreedStatus_Breeding {
  58. continue
  59. }
  60. res[i] = NewEventPregnantCheck(cow, penMap, pregnantCheckName)
  61. }
  62. return res
  63. }
  64. type EventPregnantCheck2 struct {
  65. Cow *Cow
  66. OperationUser *SystemUser
  67. CurrentUser *SystemUser
  68. PregnantCheckAt int64
  69. PregnantCheckMethod pasturePb.PregnantCheckMethod_Kind
  70. PregnantCheckResult pasturePb.PregnantCheckResult_Kind
  71. Remarks string
  72. }
  73. func NewEventPregnantCheck2(req *EventPregnantCheck2, penMap map[int32]*Pen) *EventPregnantCheck {
  74. penName := ""
  75. if pen, ok := penMap[req.Cow.PenId]; ok {
  76. penName = pen.Name
  77. }
  78. return &EventPregnantCheck{
  79. CowId: req.Cow.Id,
  80. CowType: req.Cow.CowType,
  81. PenId: req.Cow.PenId,
  82. PenName: penName,
  83. DayAge: req.Cow.GetDayAge(),
  84. Lact: int8(req.Cow.Lact),
  85. PlanDay: req.PregnantCheckAt,
  86. RealityDay: req.PregnantCheckAt,
  87. EndDay: req.PregnantCheckAt,
  88. PregnantCheckResult: req.PregnantCheckResult,
  89. PregnantCheckMethod: req.PregnantCheckMethod,
  90. PregnantCheckName: PregnantCheckForFirst,
  91. BullId: req.Cow.LastBullNumber,
  92. Status: pasturePb.IsShow_Ok,
  93. OperationId: req.OperationUser.Id,
  94. OperationName: req.OperationUser.Name,
  95. Remarks: req.Remarks,
  96. MessageId: req.CurrentUser.Id,
  97. MessageName: req.CurrentUser.Name,
  98. }
  99. }
  100. type EventPregnantCheckSlice []*EventPregnantCheck
  101. func (e EventPregnantCheckSlice) ToPB(
  102. pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
  103. pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
  104. ) []*pasturePb.SearchPregnantCheckList {
  105. result := make([]*pasturePb.SearchPregnantCheckList, len(e))
  106. for i, v := range e {
  107. result[i] = &pasturePb.SearchPregnantCheckList{
  108. Id: int32(v.Id),
  109. CowId: int32(v.CowId),
  110. DayAge: v.DayAge,
  111. Lact: int32(v.Lact),
  112. PregnantCheckAt: int32(v.PlanDay),
  113. PregnantCheckResult: v.PregnantCheckResult,
  114. PregnantCheckResultName: pregnantCheckResultMap[v.PregnantCheckResult],
  115. PregnantCheckMethod: v.PregnantCheckMethod,
  116. PregnantCheckMethodName: pregnantCheckMethodMap[v.PregnantCheckMethod],
  117. Remarks: v.Remarks,
  118. OperationId: int32(v.OperationId),
  119. OperationName: v.OperationName,
  120. CreatedAt: int32(v.CreatedAt),
  121. UpdatedAt: int32(v.UpdatedAt),
  122. }
  123. }
  124. return result
  125. }
  126. func (e EventPregnantCheckSlice) ToPB3(
  127. pregnantCheckResultMap map[pasturePb.PregnantCheckResult_Kind]string,
  128. pregnantCheckMethodMap map[pasturePb.PregnantCheckMethod_Kind]string,
  129. ) []*pasturePb.PregnancyReportTable {
  130. res := make([]*pasturePb.PregnancyReportTable, len(e))
  131. for i, v := range e {
  132. pregnancyCheckName := ""
  133. if checkName, ok := PregnantCheckNameKeyMap[v.PregnantCheckName]; ok {
  134. pregnancyCheckName = checkName
  135. }
  136. pregnantCheckMethodName := ""
  137. if checkMethodName, ok := pregnantCheckMethodMap[v.PregnantCheckMethod]; ok {
  138. pregnantCheckMethodName = checkMethodName
  139. }
  140. pregnantCheckResultName := ""
  141. if checkResultName, ok := pregnantCheckResultMap[v.PregnantCheckResult]; ok {
  142. pregnantCheckResultName = checkResultName
  143. }
  144. res[i] = &pasturePb.PregnancyReportTable{
  145. Id: int32(v.Id),
  146. CowId: int32(v.CowId),
  147. Lact: int32(v.Lact),
  148. PregnancyCheckName: pregnancyCheckName,
  149. PregnancyCheckAtFormat: time.Unix(v.RealityDay, 0).Format(LayoutDate2),
  150. MatingAge: v.MatingAge,
  151. PregnantCheckMethod: v.PregnantCheckMethod,
  152. PregnantCheckMethodName: pregnantCheckMethodName,
  153. PregnantCheckResult: v.PregnantCheckResult,
  154. PregnantCheckResultName: pregnantCheckResultName,
  155. OperationName: v.OperationName,
  156. }
  157. }
  158. return res
  159. }