event_calving.go 3.5 KB

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