event_estrus.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type EventEstrus struct {
  4. Id int64 `json:"id"`
  5. CowId int64 `json:"cowId"`
  6. DayAge int32 `json:"dayAge"`
  7. Lact int8 `json:"lact"`
  8. LactationDays int32 `json:"lactationDays"`
  9. ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"exposeEstrusType"`
  10. EstrusAt int64 `json:"estrusAt"`
  11. UnMatingReasons pasturePb.UnMatingReasons_Kind `json:"unMatingReasons"`
  12. UnMatingReasonsName string `json:"unMatingReasonsName"`
  13. IsMating pasturePb.IsShow_Kind `json:"isMating"`
  14. Remarks string `json:"remarks"`
  15. OperationId int64 `json:"operationId"`
  16. OperationName string `json:"operationName"`
  17. MessageId int64 `json:"messageId"`
  18. MessageName string `json:"messageName"`
  19. CreatedAt int64 `json:"createdAt"`
  20. UpdatedAt int64 `json:"updatedAt"`
  21. }
  22. func (e *EventEstrus) TableName() string {
  23. return "event_estrus"
  24. }
  25. func NewEventEstrus(exposeEstrusType pasturePb.ExposeEstrusType_Kind, cow *Cow, currentUser *SystemUser, operation *SystemUser, req *pasturePb.EventEstrus) *EventEstrus {
  26. return &EventEstrus{
  27. CowId: cow.Id,
  28. DayAge: cow.GetDayAge(),
  29. Lact: int8(cow.Lact),
  30. LactationDays: cow.GetLactationDays(),
  31. EstrusAt: int64(req.EstrusAt),
  32. Remarks: req.Remarks,
  33. IsMating: req.IsMathing,
  34. UnMatingReasons: req.UnMatingReasons,
  35. MessageId: currentUser.Id,
  36. MessageName: currentUser.Name,
  37. OperationId: operation.Id,
  38. OperationName: operation.Name,
  39. ExposeEstrusType: exposeEstrusType,
  40. }
  41. }
  42. type EstrusSlice []*EventEstrus
  43. func (e EstrusSlice) ToPB() []*pasturePb.SearchEstrusList {
  44. res := make([]*pasturePb.SearchEstrusList, len(e))
  45. for i, v := range e {
  46. res[i] = &pasturePb.SearchEstrusList{
  47. Id: int32(v.Id),
  48. CowId: int32(v.CowId),
  49. DayAge: v.DayAge,
  50. Lact: int32(v.Lact),
  51. EstrusAt: int32(v.EstrusAt),
  52. IsMathing: v.IsMating,
  53. UnMatingReasonsName: v.UnMatingReasonsName,
  54. LactationDays: v.LactationDays,
  55. MessengerId: int32(v.MessageId),
  56. MessengerName: v.MessageName,
  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. }