event_enter.go 5.0 KB

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