event_pregnant_check.go 7.5 KB

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