event_abortion.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package model
  2. import (
  3. "strings"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventAbortion struct {
  7. Id int64 `json:"id"`
  8. PastureId int64 `json:"pastureId"`
  9. CowId int64 `json:"cowId"`
  10. Lact int32 `json:"lact"`
  11. CowType pasturePb.CowType_Kind `json:"cowType"`
  12. DayAge int32 `json:"dayAge"`
  13. PregnantAge int32 `json:"pregnantAge"`
  14. AbortionAt int64 `json:"abortionAt"`
  15. IsAfterbirth pasturePb.IsShow_Kind `json:"isAfterbirth"`
  16. Photos string `json:"photos"`
  17. AbortionReasons pasturePb.AbortionReasons_Kind `json:"abortionReasons"`
  18. AbortionReasonsName string `json:"abortionReasonsName"`
  19. Remarks string `json:"remarks"`
  20. OperationId int64 `json:"operationId"`
  21. OperationName string `json:"operationName"`
  22. CreatedAt int64 `json:"createdAt"`
  23. UpdatedAt int64 `json:"updatedAt"`
  24. }
  25. func (e *EventAbortion) TableName() string {
  26. return "event_abortion"
  27. }
  28. func NewEventAbortion(pastureId int64, cow *Cow, req *pasturePb.EventAbortionRequest, abortionReasonMap map[pasturePb.AbortionReasons_Kind]string) *EventAbortion {
  29. return &EventAbortion{
  30. PastureId: pastureId,
  31. CowId: int64(req.CowId),
  32. Lact: cow.Lact,
  33. CowType: cow.CowType,
  34. PregnantAge: cow.GetDaysPregnant(),
  35. DayAge: cow.DayAge,
  36. AbortionAt: int64(req.AbortionAt),
  37. IsAfterbirth: req.IsAfterbirth,
  38. Photos: strings.Join(req.Photos, ","),
  39. AbortionReasons: req.AbortionReasons,
  40. AbortionReasonsName: abortionReasonMap[req.AbortionReasons],
  41. Remarks: req.Remarks,
  42. OperationId: int64(req.OperationId),
  43. OperationName: req.OperationName,
  44. }
  45. }
  46. type AbortionSlice []*EventAbortion
  47. func (a AbortionSlice) ToPB() []*pasturePb.EventAbortionRequest {
  48. res := make([]*pasturePb.EventAbortionRequest, len(a))
  49. for i, v := range a {
  50. res[i] = &pasturePb.EventAbortionRequest{
  51. Id: int32(v.Id),
  52. CowId: int32(v.CowId),
  53. DayAge: v.DayAge,
  54. Lact: v.Lact,
  55. AbortionAt: int32(v.AbortionAt),
  56. IsAfterbirth: v.IsAfterbirth,
  57. Photos: strings.Split(v.Photos, ","),
  58. AbortionReasons: v.AbortionReasons,
  59. AbortionReasonsName: v.AbortionReasonsName,
  60. PregnancyAge: v.PregnantAge,
  61. Remarks: v.Remarks,
  62. OperationId: int32(v.OperationId),
  63. OperationName: v.OperationName,
  64. CreatedAt: int32(v.CreatedAt),
  65. UpdatedAt: int32(v.UpdatedAt),
  66. }
  67. }
  68. return res
  69. }