event_abortion.go 2.9 KB

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