event_calving.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. CowType pasturePb.CowType_Kind `json:"cowType"`
  11. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  12. EarNumber string `json:"earNumber"`
  13. Lact int32 `json:"lact"`
  14. DayAge int32 `json:"dayAge"`
  15. PlanDay int64 `json:"planDay"`
  16. RealityDay int64 `json:"realityDay"`
  17. EndDay int64 `json:"endDay"`
  18. PenId int32 `json:"penId"`
  19. ChildNumber int8 `json:"childNumber"`
  20. BullNumber string `json:"bullNumber"`
  21. PregnancyAge int64 `json:"pregnancyAge"`
  22. CalvingLevel pasturePb.CalvingLevel_Kind `json:"calvingLevel"`
  23. OperationId int64 `json:"operationId"`
  24. OperationName string `json:"operationName"`
  25. DystociaReason pasturePb.DystociaReason_Kind `json:"dystociaReason"`
  26. Remarks string `json:"remarks"`
  27. CreatedAt int64 `json:"created_at"`
  28. UpdatedAt int64 `json:"updated_at"`
  29. }
  30. func (e *EventCalving) TableName() string {
  31. return "event_calving"
  32. }
  33. func NewEventCalving(cow *Cow) *EventCalving {
  34. return &EventCalving{
  35. CowId: cow.Id,
  36. CowKind: cow.CowKind,
  37. CowType: cow.CowType,
  38. EarNumber: cow.EarNumber,
  39. Lact: cow.Lact,
  40. PenId: cow.PenId,
  41. BullNumber: cow.LastBullNumber,
  42. PlanDay: util.TimeParseLocalUnix(time.Now().Format(LayoutTime)),
  43. EndDay: util.TimeParseLocalEndUnix(time.Now().Format(LayoutTime)),
  44. }
  45. }
  46. func NewEventCalvingList(cowList []*Cow) []*EventCalving {
  47. eventCalvingList := make([]*EventCalving, 0)
  48. for _, cow := range cowList {
  49. eventCalvingList = append(eventCalvingList, NewEventCalving(cow))
  50. }
  51. return eventCalvingList
  52. }
  53. type EventCalvingList struct {
  54. EventCalving
  55. PenName string `json:"pen_name"`
  56. StaffMemberName string `json:"staff_member_name"`
  57. }
  58. type EventCalvingListSlice []*EventCalvingList
  59. func (e EventCalvingListSlice) ToPB(req []*CalvingCalf) []*pasturePb.LavingList {
  60. var list []*pasturePb.LavingList
  61. for _, item := range e {
  62. CalfItemList := make([]*pasturePb.CalfItem, 0)
  63. for _, v := range req {
  64. if v.CalvingId != item.Id {
  65. continue
  66. }
  67. CalfItemList = append(CalfItemList, &pasturePb.CalfItem{
  68. EarNumber: v.EarNumber,
  69. Sex: v.Sex,
  70. Weight: float32(v.BirthWeight) / 1000,
  71. IsAdoption: v.IsAdoption,
  72. IsLive: v.IsLive,
  73. CreatedAt: int32(v.CreatedAt),
  74. UpdatedAt: int32(v.UpdatedAt),
  75. PenId: v.PenId,
  76. Remarks: v.Remarks,
  77. MotherId: int32(v.MotherId),
  78. Id: int32(v.Id),
  79. })
  80. }
  81. list = append(list, &pasturePb.LavingList{
  82. Id: int32(item.Id),
  83. CowId: int32(item.CowId),
  84. Lact: item.Lact,
  85. PenId: item.PenId,
  86. PenName: item.PenName,
  87. CalvingAt: int32(item.PlanDay),
  88. ChildNumber: int32(item.ChildNumber),
  89. DaysPregnant: int32(item.PregnancyAge),
  90. OperationId: int32(item.OperationId),
  91. OperationName: item.OperationName,
  92. CalvingLevel: item.CalvingLevel,
  93. Remarks: item.Remarks,
  94. CreatedAt: int32(item.CreatedAt),
  95. UpdatedAt: int32(item.UpdatedAt),
  96. DystociaReason: item.DystociaReason,
  97. CalfItemList: CalfItemList,
  98. })
  99. }
  100. return list
  101. }
  102. type EventCalvingSlice []*EventCalving
  103. func (e EventCalvingSlice) ToPB() []*pasturePb.CalvingReportTable {
  104. res := make([]*pasturePb.CalvingReportTable, len(e))
  105. for i, v := range e {
  106. res[i] = &pasturePb.CalvingReportTable{
  107. StatisticMethod: v.Remarks,
  108. Twins: 0,
  109. TwinsRate: 0,
  110. Bulls: 0,
  111. BullsRate: 0,
  112. Cows: 0,
  113. CowsRate: 0,
  114. SurviveCount: 0,
  115. SurviveRate: 0,
  116. DieCount: 0,
  117. DieRate: 0,
  118. BullsDieCount: 0,
  119. BullsDieRate: 0,
  120. CowsDieCount: 0,
  121. CowsDieRate: 0,
  122. AdoptCount: 0,
  123. AdoptRate: 0,
  124. PrematureLaborCount: 0,
  125. PrematureLaborRate: 0,
  126. LateLaborCount: 0,
  127. LateLaborRate: 0,
  128. NormalLaborCount: 0,
  129. }
  130. }
  131. return res
  132. }