event_enter.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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().Local().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. BatchNumber: req.BatchNumber,
  74. }
  75. }
  76. type EventEnterSlice []*EventEnter
  77. func (e EventEnterSlice) ToPB(
  78. penMap map[int32]*Pen,
  79. breedStatusMap map[pasturePb.BreedStatus_Kind]string,
  80. cowSourceMap map[pasturePb.CowSource_Kind]string,
  81. cowTypeMap map[pasturePb.CowType_Kind]string,
  82. cowKindMap map[pasturePb.CowKind_Kind]string,
  83. ) []*pasturePb.EventEnterRequest {
  84. res := make([]*pasturePb.EventEnterRequest, len(e))
  85. for i, d := range e {
  86. penName := ""
  87. if pen, ok := penMap[d.PenId]; ok {
  88. penName = pen.Name
  89. }
  90. res[i] = &pasturePb.EventEnterRequest{
  91. Id: int32(d.Id),
  92. EarNumber: d.EarNumber,
  93. CowId: int32(d.CowId),
  94. Sex: d.Sex,
  95. BirthAt: int32(d.BirthAt),
  96. CowSource: d.CowSource,
  97. CowSourceName: cowSourceMap[d.CowSource],
  98. CowType: d.CowType,
  99. CowTypeName: cowTypeMap[d.CowType],
  100. BreedStatus: d.BreedStatus,
  101. BreedStatusName: breedStatusMap[d.BreedStatus],
  102. Lact: d.Lact,
  103. PenId: d.PenId,
  104. PenName: penName,
  105. CowKind: d.CowKind,
  106. CowKindName: cowKindMap[d.CowKind],
  107. FatherNumber: d.FatherNumber,
  108. MotherNumber: d.MotherNumber,
  109. MatingAt: int32(d.MatingAt),
  110. PregnancyCheckAt: int32(d.PregnancyCheckAt),
  111. DryMilkAt: int32(d.DryMilkAt),
  112. WeaningAt: int32(d.WeaningAt),
  113. EstrusAt: int32(d.EstrusAt),
  114. EnterAt: int32(d.EnterAt),
  115. Weight: float32(d.Weight) / 1000,
  116. Price: float32(d.Price) / 100,
  117. Remarks: d.Remarks,
  118. MessengerId: int32(d.MessengerId),
  119. MessengerName: d.MessengerName,
  120. OperationId: int32(d.OperationId),
  121. OperationName: d.OperationName,
  122. CreatedAt: int32(d.CreatedAt),
  123. UpdatedAt: int32(d.UpdatedAt),
  124. }
  125. }
  126. return res
  127. }
  128. type HistoryBatchNumberResponse struct {
  129. Code int32 `json:"code"`
  130. Msg string `json:"msg"`
  131. Data []string `json:"data"`
  132. }
  133. type GenerateBatchNumberResponse struct {
  134. Code int32 `json:"code"`
  135. Msg string `json:"msg"`
  136. Data string `json:"data"`
  137. }