event_enter.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. CowTypeId pasturePb.CowType_Kind `json:"cow_type_id"`
  17. BreedStatusId pasturePb.BreedStatus_Kind `json:"breed_status_id"`
  18. Lact int32 `json:"lact"`
  19. DayAge int32 `json:"day_age"`
  20. PenId int32 `json:"pen_id"`
  21. CowKindId pasturePb.CowKind_Kind `json:"cow_kind_id"`
  22. Status pasturePb.CowStatus_Kind `json:"status"`
  23. FatherId int64 `json:"father_id"`
  24. MotherId int64 `json:"mother_id"`
  25. MatingAt int64 `json:"mating_at"`
  26. PregnancyCheckAt int64 `json:"pregnancy_check_at"`
  27. DryMilkAt int64 `json:"dry_milk_at"`
  28. WeaningAt int64 `json:"weaning_at"`
  29. EstrusAt int64 `json:"estrus_at"`
  30. EnterAt int64 `json:"enter_at"`
  31. Remarks string `json:"remarks"`
  32. Weight int64 `json:"weight"`
  33. Price int64 `json:"price"`
  34. OperationId int64 `json:"operation_id"`
  35. StaffMemberId int64 `json:"staff_member_id"`
  36. CreatedAt int64 `json:"created_at"`
  37. UpdatedAt int64 `json:"updated_at"`
  38. }
  39. func (e *EventEnter) TableName() string {
  40. return "event_enter"
  41. }
  42. func NewEventEnter(cowId, operationId int64, req *pasturePb.SearchEnterData) *EventEnter {
  43. return &EventEnter{
  44. EarNumber: req.EarNumber,
  45. CowId: cowId,
  46. Sex: req.Sex,
  47. BirthAt: int64(req.BirthAt),
  48. CowSourceId: req.CowSourceId,
  49. CowTypeId: req.CowTypeId,
  50. BreedStatusId: req.BreedStatusId,
  51. Lact: req.Lact,
  52. DayAge: int32(math.Floor(float64(int32(time.Now().Unix())-req.BirthAt) / 86400)),
  53. PenId: req.PenId,
  54. CowKindId: req.CowKindId,
  55. Status: 1,
  56. FatherId: int64(req.FatherId),
  57. MotherId: int64(req.MotherId),
  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. StaffMemberId: int64(req.StaffMemberId),
  68. OperationId: operationId,
  69. }
  70. }
  71. type EventEnterSlice []*EventEnter
  72. func (e EventEnterSlice) ToPB() []*pasturePb.SearchEnterData {
  73. res := make([]*pasturePb.SearchEnterData, len(e))
  74. for i, d := range e {
  75. res[i] = &pasturePb.SearchEnterData{
  76. Id: int32(d.Id),
  77. EarNumber: d.EarNumber,
  78. CowId: int32(d.CowId),
  79. Sex: d.Sex,
  80. BirthAt: int32(d.BirthAt),
  81. CowSourceId: d.CowSourceId,
  82. CowTypeId: d.CowTypeId,
  83. BreedStatusId: d.BreedStatusId,
  84. Lact: d.Lact,
  85. PenId: d.PenId,
  86. CowKindId: d.CowKindId,
  87. FatherId: int32(d.FatherId),
  88. MotherId: int32(d.MotherId),
  89. MatingAt: int32(d.MatingAt),
  90. PregnancyCheckAt: int32(d.PregnancyCheckAt),
  91. DryMilkAt: int32(d.DryMilkAt),
  92. WeaningAt: int32(d.WeaningAt),
  93. EstrusAt: int32(d.EstrusAt),
  94. EnterAt: int32(d.EnterAt),
  95. Weight: float32(d.Weight) / 100,
  96. Price: float32(d.Price) / 100,
  97. Remarks: d.Remarks,
  98. CreatedAt: int32(d.CreatedAt),
  99. UpdatedAt: int32(d.UpdatedAt),
  100. }
  101. }
  102. return res
  103. }