event_abortion.go 2.8 KB

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