event_abortion.go 3.2 KB

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