event_estrus.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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:"cow_id"`
  6. DayAge int32 `json:"day_age"`
  7. Lact int8 `json:"lact"`
  8. LactationDays int32 `json:"lactation_days"`
  9. EstrusAt int64 `json:"estrus_at"`
  10. Remarks string `json:"remarks"`
  11. StallNumberId int64 `json:"stall_number_id"`
  12. OperationId int64 `json:"operation_id"`
  13. CreatedAt int64 `json:"created_at"`
  14. UpdatedAt int64 `json:"updated_at"`
  15. }
  16. func (e *EventEstrus) TableName() string {
  17. return "event_estrus"
  18. }
  19. func NewEventEstrus(cow *Cow, currentUser *SystemUser, req *pasturePb.EventEstrus) *EventEstrus {
  20. return &EventEstrus{
  21. CowId: cow.Id,
  22. DayAge: cow.GetDayAge(),
  23. Lact: int8(cow.Lact),
  24. LactationDays: cow.GetLactationDays(),
  25. EstrusAt: int64(req.EstrusAt),
  26. Remarks: req.Remarks,
  27. StallNumberId: int64(req.StaffMemberId),
  28. OperationId: currentUser.Id,
  29. }
  30. }
  31. type EstrusSlice []*EventEstrus
  32. func (e EstrusSlice) ToPB(userList []*SystemUser) []*pasturePb.SearchEstrusList {
  33. res := make([]*pasturePb.SearchEstrusList, len(e))
  34. for i, v := range e {
  35. staffMemberName, operationName := "", ""
  36. for _, u := range userList {
  37. if u.Id == v.StallNumberId {
  38. staffMemberName = u.Name
  39. }
  40. if u.Id == v.OperationId {
  41. operationName = u.Name
  42. }
  43. }
  44. res[i] = &pasturePb.SearchEstrusList{
  45. Id: int32(v.Id),
  46. CowId: int32(v.CowId),
  47. DayAge: v.DayAge,
  48. Lact: int32(v.Lact),
  49. EstrusAt: int32(v.EstrusAt),
  50. LactationDays: v.LactationDays,
  51. StaffMemberId: int32(v.StallNumberId),
  52. StaffMemberName: staffMemberName,
  53. Remarks: v.Remarks,
  54. OperationId: int32(v.OperationId),
  55. OperationName: operationName,
  56. CreatedAt: int32(v.CreatedAt),
  57. UpdatedAt: int32(v.UpdatedAt),
  58. }
  59. }
  60. return res
  61. }