event_estrus.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. EstrusAt int64 `json:"estrusAt"`
  10. Remarks string `json:"remarks"`
  11. OperationId int64 `json:"operationId"`
  12. OperationName string `json:"operationName"`
  13. MessageId int64 `json:"messageId"`
  14. MessageName string `json:"messageName"`
  15. CreatedAt int64 `json:"createdAt"`
  16. UpdatedAt int64 `json:"updatedAt"`
  17. }
  18. func (e *EventEstrus) TableName() string {
  19. return "event_estrus"
  20. }
  21. func NewEventEstrus(cow *Cow, currentUser *SystemUser, req *pasturePb.EventEstrus) *EventEstrus {
  22. return &EventEstrus{
  23. CowId: cow.Id,
  24. DayAge: cow.GetDayAge(),
  25. Lact: int8(cow.Lact),
  26. LactationDays: cow.GetLactationDays(),
  27. EstrusAt: int64(req.EstrusAt),
  28. Remarks: req.Remarks,
  29. MessageId: currentUser.Id,
  30. MessageName: currentUser.Name,
  31. OperationId: int64(req.OperationId),
  32. OperationName: req.OperationName,
  33. }
  34. }
  35. type EstrusSlice []*EventEstrus
  36. func (e EstrusSlice) ToPB() []*pasturePb.SearchEstrusList {
  37. res := make([]*pasturePb.SearchEstrusList, len(e))
  38. for i, v := range e {
  39. res[i] = &pasturePb.SearchEstrusList{
  40. Id: int32(v.Id),
  41. CowId: int32(v.CowId),
  42. DayAge: v.DayAge,
  43. Lact: int32(v.Lact),
  44. EstrusAt: int32(v.EstrusAt),
  45. LactationDays: v.LactationDays,
  46. MessengerId: int32(v.MessageId),
  47. MessengerName: v.MessageName,
  48. Remarks: v.Remarks,
  49. OperationId: int32(v.OperationId),
  50. OperationName: v.OperationName,
  51. CreatedAt: int32(v.CreatedAt),
  52. UpdatedAt: int32(v.UpdatedAt),
  53. }
  54. }
  55. return res
  56. }