event_death.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. CowType pasturePb.CowType_Kind `json:"cowType"`
  10. DayAge int32 `json:"dayAge"`
  11. PregnancyAge int32 `json:"pregnancyAge"`
  12. CalvingAge int32 `json:"calvingAge"`
  13. AdmissionAge int32 `json:"admissionAge"`
  14. DeathReasonKind pasturePb.DeathReason_Kind `json:"deathReasonKind"`
  15. DeathReasonName string `json:"deathReasonName"`
  16. DeathDestinationKind pasturePb.DeathDestination_Kind `json:"deathDestinationKind"`
  17. DeathDestinationName string `json:"deathDestinationName"`
  18. DeathAt int64 `json:"deathAt"`
  19. Remarks string `json:"remarks"`
  20. Weight int32 `json:"weight"`
  21. OperationId int64 `json:"operationId"`
  22. OperationName string `json:"operationName"`
  23. MessageId int64 `json:"messageId"`
  24. MessageName string `json:"messageName"`
  25. CreatedAt int64 `json:"createdAt"`
  26. UpdatedAt int64 `json:"updatedAt"`
  27. }
  28. func (e *EventDeath) TableName() string {
  29. return "event_death"
  30. }
  31. func NewEventDeath(pastureId int64, cow *Cow, req *pasturePb.EventDeath, currentUser, operationUser *SystemUser) *EventDeath {
  32. return &EventDeath{
  33. PastureId: pastureId,
  34. CowId: cow.Id,
  35. EarNumber: cow.EarNumber,
  36. Lact: cow.Lact,
  37. CowType: cow.CowType,
  38. DayAge: cow.GetEventDayAge(int64(req.DeathAt)),
  39. DeathAt: int64(req.DeathAt),
  40. DeathReasonKind: req.DeathReasonKind,
  41. DeathReasonName: req.DeathReasonName,
  42. Remarks: req.Remarks,
  43. Weight: int32(req.Weight * 1000),
  44. DeathDestinationKind: req.DeathDestinationKind,
  45. DeathDestinationName: req.DeathDestinationName,
  46. OperationId: operationUser.Id,
  47. OperationName: operationUser.Name,
  48. MessageId: currentUser.Id,
  49. MessageName: currentUser.Name,
  50. }
  51. }
  52. type EventDeathSlice []*EventDeath
  53. func (e EventDeathSlice) ToPB() []*pasturePb.EventDeath {
  54. res := make([]*pasturePb.EventDeath, len(e))
  55. for i, v := range e {
  56. res[i] = &pasturePb.EventDeath{
  57. Id: int32(v.Id),
  58. EarNumber: v.EarNumber,
  59. DeathReasonKind: v.DeathReasonKind,
  60. DeathReasonName: v.DeathReasonName,
  61. DeathAt: int32(v.DeathAt),
  62. OperationId: int32(v.OperationId),
  63. OperationName: v.OperationName,
  64. Remarks: v.Remarks,
  65. Weight: float32(v.Weight / 1000),
  66. DeathDestinationKind: v.DeathDestinationKind,
  67. DeathDestinationName: v.DeathDestinationName,
  68. CreatedAt: int32(v.CreatedAt),
  69. UpdatedAt: int32(v.UpdatedAt),
  70. }
  71. }
  72. return res
  73. }
  74. type EventDeathModel struct {
  75. Cow *Cow
  76. EventDeath *EventDeath
  77. NeckRing *NeckRing
  78. CalvingCalf *CalvingCalf
  79. }