event_calving.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. )
  6. type EventCalving struct {
  7. Id int64 `json:"id"`
  8. CowId int64 `json:"cowId"`
  9. EarNumber string `json:"earNumber"`
  10. Lact int32 `json:"lact"`
  11. DayAge int32 `json:"dayAge"`
  12. PlanDay string `json:"planDay"`
  13. RealityDay string `json:"realityDay"`
  14. EndDay string `json:"endDay"`
  15. PenId int32 `json:"penId"`
  16. ChildNumber int8 `json:"childNumber"`
  17. BullNumber string `json:"bullNumber"`
  18. PregnancyAge int64 `json:"pregnancyAge"`
  19. CalvingLevel pasturePb.CalvingLevel_Kind `json:"calvingLevel"`
  20. OperationId int64 `json:"operationId"`
  21. OperationName string `json:"operationName"`
  22. DystociaReason pasturePb.DystociaReason_Kind `json:"dystociaReason"`
  23. Remarks string `json:"remarks"`
  24. CreatedAt int64 `json:"created_at"`
  25. UpdatedAt int64 `json:"updated_at"`
  26. }
  27. func (e *EventCalving) TableName() string {
  28. return "event_calving"
  29. }
  30. func NewEventCalving(cow *Cow, planDay int64) *EventCalving {
  31. return &EventCalving{
  32. CowId: cow.Id,
  33. EarNumber: cow.EarNumber,
  34. Lact: cow.Lact,
  35. PenId: cow.PenId,
  36. BullNumber: cow.LastBullNumber,
  37. PlanDay: time.Unix(planDay, 0).Format(LayoutTime),
  38. }
  39. }
  40. func NewEventCalvingList(cowList []*Cow, planDay int64) []*EventCalving {
  41. eventCalvingList := make([]*EventCalving, 0)
  42. for _, cow := range cowList {
  43. eventCalvingList = append(eventCalvingList, NewEventCalving(cow, planDay))
  44. }
  45. return eventCalvingList
  46. }
  47. type EventCalvingList struct {
  48. EventCalving
  49. PenName string `json:"pen_name"`
  50. StaffMemberName string `json:"staff_member_name"`
  51. }
  52. type EventCalvingListSlice []*EventCalvingList
  53. func (e EventCalvingListSlice) ToPB(req []*CalvingCalf) []*pasturePb.LavingList {
  54. var list []*pasturePb.LavingList
  55. for _, item := range e {
  56. CalfItemList := make([]*pasturePb.CalfItem, 0)
  57. for _, v := range req {
  58. if v.CalvingId != item.Id {
  59. continue
  60. }
  61. CalfItemList = append(CalfItemList, &pasturePb.CalfItem{
  62. EarNumber: v.EarNumber,
  63. Sex: v.Sex,
  64. Weight: float32(v.BirthWeight) / 1000,
  65. IsAdoption: v.IsAdoption,
  66. IsLive: v.IsLive,
  67. CreatedAt: int32(v.CreatedAt),
  68. UpdatedAt: int32(v.UpdatedAt),
  69. PenId: v.PenId,
  70. Remarks: v.Remarks,
  71. MotherId: int32(v.MotherId),
  72. Id: int32(v.Id),
  73. })
  74. }
  75. calvingDay, _ := time.Parse(LayoutTime, item.PlanDay)
  76. list = append(list, &pasturePb.LavingList{
  77. Id: int32(item.Id),
  78. CowId: int32(item.CowId),
  79. Lact: item.Lact,
  80. PenId: item.PenId,
  81. PenName: item.PenName,
  82. CalvingAt: int32(calvingDay.Unix()),
  83. ChildNumber: int32(item.ChildNumber),
  84. DaysPregnant: int32(item.PregnancyAge),
  85. OperationId: int32(item.OperationId),
  86. OperationName: item.OperationName,
  87. CalvingLevel: item.CalvingLevel,
  88. Remarks: item.Remarks,
  89. CreatedAt: int32(item.CreatedAt),
  90. UpdatedAt: int32(item.UpdatedAt),
  91. DystociaReason: item.DystociaReason,
  92. CalfItemList: CalfItemList,
  93. })
  94. }
  95. return list
  96. }