event_mating.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type EventMating struct {
  4. Id int64 `json:"id"`
  5. CowId int64 `json:"cow_id"`
  6. DayAge int64 `json:"day_age"`
  7. Lact int8 `json:"lact"`
  8. LactationDays int32 `json:"lactation_days"`
  9. ExposeEstrusType pasturePb.ExposeEstrusType_Kind `json:"expose_estrus_type"`
  10. MatingAt int64 `json:"mating_at"`
  11. BullId string `json:"bull_id"`
  12. FrozenSemenNumber string `json:"frozen_semen_number"`
  13. StallNumberId int64 `json:"stall_number_id"`
  14. OperationId int64 `json:"operation_id"`
  15. Remarks string `json:"remarks"`
  16. CreatedAt int64 `json:"created_at"`
  17. UpdatedAt int64 `json:"updated_at"`
  18. }
  19. func (e *EventMating) TableName() string {
  20. return "event_mating"
  21. }
  22. func NewEventMating(cow *Cow, currentUser *SystemUser, req *pasturePb.EventMating) *EventMating {
  23. return &EventMating{
  24. CowId: cow.Id,
  25. DayAge: int64(cow.GetDayAge()),
  26. Lact: int8(cow.Lact),
  27. LactationDays: cow.GetLactationDays(),
  28. ExposeEstrusType: req.ExposeEstrusType,
  29. MatingAt: int64(req.MatingAt),
  30. BullId: req.BullId,
  31. FrozenSemenNumber: req.FrozenSemenNumber,
  32. StallNumberId: int64(req.StaffMemberId),
  33. OperationId: currentUser.Id,
  34. Remarks: req.Remarks,
  35. }
  36. }
  37. type EventMatingSlice []*EventMating
  38. func (e EventMatingSlice) ToPB(user []*SystemUser, exposeEstrusTypeMap map[pasturePb.ExposeEstrusType_Kind]string) []*pasturePb.SearchMatingList {
  39. res := make([]*pasturePb.SearchMatingList, len(e))
  40. for i, v := range e {
  41. operationName, staffMemberName := "", ""
  42. for _, u := range user {
  43. if v.OperationId == u.Id {
  44. operationName = u.Name
  45. }
  46. if v.StallNumberId == u.Id {
  47. staffMemberName = u.Name
  48. }
  49. }
  50. res[i] = &pasturePb.SearchMatingList{
  51. Id: int32(v.Id),
  52. CowId: int32(v.CowId),
  53. DayAge: int32(v.DayAge),
  54. Lact: int32(v.Lact),
  55. ExposeEstrusType: v.ExposeEstrusType,
  56. ExposeEstrusTypeName: exposeEstrusTypeMap[v.ExposeEstrusType],
  57. MatingAt: int32(v.MatingAt),
  58. BullId: v.BullId,
  59. FrozenSemenNumber: v.FrozenSemenNumber,
  60. LactationDays: v.LactationDays,
  61. StaffMemberId: int32(v.StallNumberId),
  62. StaffMemberName: staffMemberName,
  63. Remarks: v.Remarks,
  64. OperationId: int32(v.OperationId),
  65. OperationName: operationName,
  66. CreatedAt: int32(v.CreatedAt),
  67. UpdatedAt: int32(v.UpdatedAt),
  68. }
  69. }
  70. return res
  71. }