event_enter.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package model
  2. import (
  3. "math"
  4. "time"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. )
  7. type EventEnter struct {
  8. Id int64 `json:"id"`
  9. PastureId int64 `json:"pastureId"`
  10. BatchNumber string `json:"batchNumber"`
  11. EarNumber string `json:"earNumber"`
  12. CowId int64 `json:"cowId"`
  13. Sex pasturePb.Genders_Kind `json:"sex"`
  14. BirthAt int64 `json:"birthAt"`
  15. CowSource pasturePb.CowSource_Kind `json:"cowSource"`
  16. OldEarNumber string `json:"oldEarNumber"`
  17. CowType pasturePb.CowType_Kind `json:"cowType"`
  18. BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
  19. Lact int32 `json:"lact"`
  20. DayAge int32 `json:"dayAge"`
  21. PenId int32 `json:"penId"`
  22. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  23. FatherNumber string `json:"fatherNumber"`
  24. MotherNumber string `json:"motherNumber"`
  25. MatingAt int64 `json:"matingAt"`
  26. PregnancyCheckAt int64 `json:"pregnancyCheckAt"`
  27. DryMilkAt int64 `json:"dryMilkAt"`
  28. WeaningAt int64 `json:"weaningAt"`
  29. EstrusAt int64 `json:"estrusAt"`
  30. EnterAt int64 `json:"enterAt"`
  31. Remarks string `json:"remarks"`
  32. Weight int64 `json:"weight"`
  33. Price int64 `json:"price"`
  34. OperationId int64 `json:"operationId"`
  35. OperationName string `json:"operationName"`
  36. MessengerId int64 `json:"messengerId"`
  37. MessengerName string `json:"messengerName"`
  38. CreatedAt int64 `json:"created_at"`
  39. UpdatedAt int64 `json:"updated_at"`
  40. }
  41. func (e *EventEnter) TableName() string {
  42. return "event_enter"
  43. }
  44. func NewEventEnter(pastureId, cowId int64, req *pasturePb.EventEnterRequest) *EventEnter {
  45. return &EventEnter{
  46. PastureId: pastureId,
  47. EarNumber: req.EarNumber,
  48. CowId: cowId,
  49. Sex: req.Sex,
  50. BirthAt: int64(req.BirthAt),
  51. CowSource: req.CowSource,
  52. CowType: req.CowType,
  53. BreedStatus: req.BreedStatus,
  54. Lact: req.Lact,
  55. DayAge: int32(math.Floor(float64(int32(time.Now().Unix())-req.BirthAt) / 86400)),
  56. PenId: req.PenId,
  57. CowKind: req.CowKind,
  58. FatherNumber: req.FatherNumber,
  59. MotherNumber: req.MotherNumber,
  60. MatingAt: int64(req.MatingAt),
  61. PregnancyCheckAt: int64(req.PregnancyCheckAt),
  62. DryMilkAt: int64(req.DryMilkAt),
  63. WeaningAt: int64(req.WeaningAt),
  64. EstrusAt: int64(req.EstrusAt),
  65. EnterAt: int64(req.EnterAt),
  66. Remarks: req.Remarks,
  67. Weight: int64(req.Weight * 1000),
  68. Price: int64(req.Price * 100),
  69. MessengerId: int64(req.MessengerId),
  70. MessengerName: req.MessengerName,
  71. OperationId: int64(req.OperationId),
  72. OperationName: req.OperationName,
  73. }
  74. }
  75. type EventEnterSlice []*EventEnter
  76. func (e EventEnterSlice) ToPB(
  77. penMap map[int32]*Pen,
  78. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  79. cowSourceMap map[pasturePb.CowSource_Kind]string,
  80. cowTypeMap map[pasturePb.CowType_Kind]string,
  81. cowKindMap map[pasturePb.CowKind_Kind]string,
  82. ) []*pasturePb.EventEnterRequest {
  83. res := make([]*pasturePb.EventEnterRequest, len(e))
  84. for i, d := range e {
  85. penName := ""
  86. if pen, ok := penMap[d.PenId]; ok {
  87. penName = pen.Name
  88. }
  89. res[i] = &pasturePb.EventEnterRequest{
  90. Id: int32(d.Id),
  91. EarNumber: d.EarNumber,
  92. CowId: int32(d.CowId),
  93. Sex: d.Sex,
  94. BirthAt: int32(d.BirthAt),
  95. CowSource: d.CowSource,
  96. CowSourceName: cowSourceMap[d.CowSource],
  97. CowType: d.CowType,
  98. CowTypeName: cowTypeMap[d.CowType],
  99. BreedStatus: d.BreedStatus,
  100. BreedStatusName: breedStatusMap[d.BreedStatus],
  101. Lact: d.Lact,
  102. PenId: d.PenId,
  103. PenName: penName,
  104. CowKind: d.CowKind,
  105. CowKindName: cowKindMap[d.CowKind],
  106. FatherNumber: d.FatherNumber,
  107. MotherNumber: d.MotherNumber,
  108. MatingAt: int32(d.MatingAt),
  109. PregnancyCheckAt: int32(d.PregnancyCheckAt),
  110. DryMilkAt: int32(d.DryMilkAt),
  111. WeaningAt: int32(d.WeaningAt),
  112. EstrusAt: int32(d.EstrusAt),
  113. EnterAt: int32(d.EnterAt),
  114. Weight: float32(d.Weight) / 1000,
  115. Price: float32(d.Price) / 100,
  116. Remarks: d.Remarks,
  117. MessengerId: int32(d.MessengerId),
  118. MessengerName: d.MessengerName,
  119. OperationId: int32(d.OperationId),
  120. OperationName: d.OperationName,
  121. CreatedAt: int32(d.CreatedAt),
  122. UpdatedAt: int32(d.UpdatedAt),
  123. }
  124. }
  125. return res
  126. }