event_death.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type EventDeath struct {
  4. Id int64 `json:"id"`
  5. PastureId int64 `json:"pastureId"`
  6. EarNumber string `json:"earNumber"`
  7. CowId int64 `json:"cowId"`
  8. Lact int32 `json:"lact"`
  9. DayAge int32 `json:"dayAge"`
  10. PregnancyAge int32 `json:"pregnancyAge"`
  11. CalvingAge int32 `json:"calvingAge"`
  12. AdmissionAge int32 `json:"admissionAge"`
  13. DeathReasonKind pasturePb.DeathReason_Kind `json:"deathReasonKind"`
  14. DeathReasonName string `json:"deathReasonName"`
  15. DeathDestinationKind pasturePb.DeathDestination_Kind `json:"deathDestinationKind"`
  16. DeathDestinationName string `json:"deathDestinationName"`
  17. DeathAt int64 `json:"deathAt"`
  18. Remarks string `json:"remarks"`
  19. Weight int32 `json:"weight"`
  20. OperationId int64 `json:"operationId"`
  21. OperationName string `json:"operationName"`
  22. MessageId int64 `json:"messageId"`
  23. MessageName string `json:"messageName"`
  24. CreatedAt int64 `json:"createdAt"`
  25. UpdatedAt int64 `json:"updatedAt"`
  26. }
  27. func (e *EventDeath) TableName() string {
  28. return "event_death"
  29. }
  30. func NewEventDeath(pastureId int64, cow *Cow, req *pasturePb.EventDeath, currentUser, operationUser *SystemUser) *EventDeath {
  31. return &EventDeath{
  32. PastureId: pastureId,
  33. CowId: cow.Id,
  34. EarNumber: cow.EarNumber,
  35. Lact: cow.Lact,
  36. DayAge: cow.GetDayAge(),
  37. DeathAt: int64(req.DeathAt),
  38. DeathReasonKind: req.DeathReasonKind,
  39. DeathReasonName: req.DeathReasonName,
  40. Remarks: req.Remarks,
  41. Weight: int32(req.Weight * 1000),
  42. DeathDestinationKind: req.DeathDestinationKind,
  43. DeathDestinationName: req.DeathDestinationName,
  44. OperationId: operationUser.Id,
  45. OperationName: operationUser.Name,
  46. MessageId: currentUser.Id,
  47. MessageName: currentUser.Name,
  48. }
  49. }
  50. type EventDeathSlice []*EventDeath
  51. func (e EventDeathSlice) ToPB() []*pasturePb.EventDeath {
  52. res := make([]*pasturePb.EventDeath, len(e))
  53. for i, v := range e {
  54. res[i] = &pasturePb.EventDeath{
  55. Id: int32(v.Id),
  56. EarNumber: v.EarNumber,
  57. DeathReasonKind: v.DeathReasonKind,
  58. DeathReasonName: v.DeathReasonName,
  59. DeathAt: int32(v.DeathAt),
  60. OperationId: int32(v.OperationId),
  61. OperationName: v.OperationName,
  62. Remarks: v.Remarks,
  63. Weight: float32(v.Weight / 1000),
  64. DeathDestinationKind: v.DeathDestinationKind,
  65. DeathDestinationName: v.DeathDestinationName,
  66. CreatedAt: int32(v.CreatedAt),
  67. UpdatedAt: int32(v.UpdatedAt),
  68. }
  69. }
  70. return res
  71. }
  72. type EventDeathModel struct {
  73. Cow *Cow
  74. EventDeath *EventDeath
  75. NeckRing *NeckRing
  76. }