event_abortion.go 3.3 KB

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