event_enter.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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:"batch_number"`
  10. EarNumber string `json:"ear_number"`
  11. CowId int64 `json:"cow_id"`
  12. Sex pasturePb.Genders_Kind `json:"sex"`
  13. BirthAt int64 `json:"birth_at"`
  14. CowSourceId pasturePb.CowSource_Kind `json:"cow_source_id"`
  15. OldEarNumber string `json:"old_ear_number"`
  16. CowType pasturePb.CowType_Kind `json:"cow_type"`
  17. BreedStatus pasturePb.BreedStatus_Kind `json:"breed_status"`
  18. Lact int32 `json:"lact"`
  19. DayAge int32 `json:"day_age"`
  20. PenId int32 `json:"pen_id"`
  21. CowKind pasturePb.CowKind_Kind `json:"cow_kind"`
  22. FatherId int64 `json:"father_id"`
  23. MotherId int64 `json:"mother_id"`
  24. MatingAt int64 `json:"mating_at"`
  25. PregnancyCheckAt int64 `json:"pregnancy_check_at"`
  26. DryMilkAt int64 `json:"dry_milk_at"`
  27. WeaningAt int64 `json:"weaning_at"`
  28. EstrusAt int64 `json:"estrus_at"`
  29. EnterAt int64 `json:"enter_at"`
  30. Remarks string `json:"remarks"`
  31. Weight int64 `json:"weight"`
  32. Price int64 `json:"price"`
  33. OperationId int64 `json:"operation_id"`
  34. StaffMemberId int64 `json:"staff_member_id"`
  35. CreatedAt int64 `json:"created_at"`
  36. UpdatedAt int64 `json:"updated_at"`
  37. }
  38. func (e *EventEnter) TableName() string {
  39. return "event_enter"
  40. }
  41. func NewEventEnter(cowId, operationId int64, req *pasturePb.EventEnterData) *EventEnter {
  42. return &EventEnter{
  43. EarNumber: req.EarNumber,
  44. CowId: cowId,
  45. Sex: req.Sex,
  46. BirthAt: int64(req.BirthAt),
  47. CowSourceId: req.CowSourceId,
  48. CowType: req.CowTypeId,
  49. BreedStatus: req.BreedStatusId,
  50. Lact: req.Lact,
  51. DayAge: int32(math.Floor(float64(int32(time.Now().Unix())-req.BirthAt) / 86400)),
  52. PenId: req.PenId,
  53. CowKind: req.CowKindId,
  54. FatherId: int64(req.FatherId),
  55. MotherId: int64(req.MotherId),
  56. MatingAt: int64(req.MatingAt),
  57. PregnancyCheckAt: int64(req.PregnancyCheckAt),
  58. DryMilkAt: int64(req.DryMilkAt),
  59. WeaningAt: int64(req.WeaningAt),
  60. EstrusAt: int64(req.EstrusAt),
  61. EnterAt: int64(req.EnterAt),
  62. Remarks: req.Remarks,
  63. Weight: int64(req.Weight * 100),
  64. Price: int64(req.Price * 100),
  65. StaffMemberId: int64(req.StaffMemberId),
  66. OperationId: operationId,
  67. }
  68. }
  69. type EventEnterSlice []*EventEnter
  70. func (e EventEnterSlice) ToPB() []*pasturePb.EventEnterData {
  71. res := make([]*pasturePb.EventEnterData, len(e))
  72. for i, d := range e {
  73. res[i] = &pasturePb.EventEnterData{
  74. Id: int32(d.Id),
  75. EarNumber: d.EarNumber,
  76. CowId: int32(d.CowId),
  77. Sex: d.Sex,
  78. BirthAt: int32(d.BirthAt),
  79. CowSourceId: d.CowSourceId,
  80. CowTypeId: d.CowType,
  81. BreedStatusId: d.BreedStatus,
  82. Lact: d.Lact,
  83. PenId: d.PenId,
  84. CowKindId: d.CowKind,
  85. FatherId: int32(d.FatherId),
  86. MotherId: int32(d.MotherId),
  87. MatingAt: int32(d.MatingAt),
  88. PregnancyCheckAt: int32(d.PregnancyCheckAt),
  89. DryMilkAt: int32(d.DryMilkAt),
  90. WeaningAt: int32(d.WeaningAt),
  91. EstrusAt: int32(d.EstrusAt),
  92. EnterAt: int32(d.EnterAt),
  93. Weight: float32(d.Weight) / 100,
  94. Price: float32(d.Price) / 100,
  95. Remarks: d.Remarks,
  96. CreatedAt: int32(d.CreatedAt),
  97. UpdatedAt: int32(d.UpdatedAt),
  98. }
  99. }
  100. return res
  101. }