cow_calving.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type CowCalving struct {
  4. Id int32 `json:"id"`
  5. PastureId int64 `json:"pastureId"`
  6. DateTime string `json:"dateTime"`
  7. CowId int64 `json:"cowId"`
  8. Lact int32 `json:"lact"`
  9. EarNumber string `json:"earNumber"`
  10. NeckRingNumber string `json:"neckRingNumber"`
  11. CowType pasturePb.CowType_Kind `json:"cowType"`
  12. CowKind pasturePb.CowKind_Kind `json:"cowKind"`
  13. CalvingAge int32 `json:"calvingAge"`
  14. MatingAge int32 `json:"matingAge"`
  15. IsMating pasturePb.IsShow_Kind `json:"isMating"`
  16. IsPregnantCheck pasturePb.IsShow_Kind `json:"isPregnantCheck"`
  17. PregnantCheckDate string `json:"pregnantCheckDate"`
  18. IsAbortion pasturePb.IsShow_Kind `json:"isAbortion"`
  19. IsDeparture pasturePb.IsShow_Kind `json:"isDeparture"`
  20. IsForbidden pasturePb.IsShow_Kind `json:"isForbidden"`
  21. CreatedAt int64 `json:"createdAt"`
  22. UpdatedAt int64 `json:"updatedAt"`
  23. }
  24. func (e *CowCalving) TableName() string {
  25. return "cow_calving"
  26. }
  27. func NewEveryDayCalving(pastureId int64, dateTime string, cowInfo *Cow) *CowCalving {
  28. isMating, isPregnantCheck, isAbortion, isDeparture, isForbidden := pasturePb.IsShow_No, pasturePb.IsShow_No, pasturePb.IsShow_No, pasturePb.IsShow_No, pasturePb.IsShow_No
  29. switch cowInfo.BreedStatus {
  30. case pasturePb.BreedStatus_Abort:
  31. isAbortion = pasturePb.IsShow_Ok
  32. case pasturePb.BreedStatus_Breeding:
  33. isMating = pasturePb.IsShow_Ok
  34. case pasturePb.BreedStatus_Pregnant, pasturePb.BreedStatus_Empty:
  35. isPregnantCheck = pasturePb.IsShow_Ok
  36. case pasturePb.BreedStatus_No_Mating:
  37. isPregnantCheck = pasturePb.IsShow_Ok
  38. }
  39. if cowInfo.AdmissionStatus != pasturePb.AdmissionStatus_Admission {
  40. isDeparture = pasturePb.IsShow_Ok
  41. }
  42. return &CowCalving{
  43. PastureId: pastureId,
  44. DateTime: dateTime,
  45. CowId: cowInfo.Id,
  46. Lact: cowInfo.Lact,
  47. EarNumber: cowInfo.EarNumber,
  48. NeckRingNumber: cowInfo.NeckRingNumber,
  49. CowType: cowInfo.CowType,
  50. CowKind: cowInfo.CowKind,
  51. CalvingAge: cowInfo.CalvingAge,
  52. MatingAge: cowInfo.MatingAge,
  53. IsMating: isMating,
  54. IsPregnantCheck: isPregnantCheck,
  55. PregnantCheckDate: "",
  56. IsAbortion: isAbortion,
  57. IsDeparture: isDeparture,
  58. IsForbidden: isForbidden,
  59. }
  60. }
  61. func NewEveryDayCalvingList(pastureId int64, dateTime string, cowList []*Cow) []*CowCalving {
  62. res := make([]*CowCalving, 0)
  63. for _, cow := range cowList {
  64. res = append(res, NewEveryDayCalving(pastureId, dateTime, cow))
  65. }
  66. return res
  67. }
  68. type CowCalvingSlice []*CowCalving
  69. func (c CowCalvingSlice) ToPB() []*pasturePb.TwentyOnePregnantItems {
  70. res := make([]*pasturePb.TwentyOnePregnantItems, 0)
  71. for _, v := range c {
  72. res = append(res, &pasturePb.TwentyOnePregnantItems{
  73. CowId: int32(v.CowId),
  74. Lact: v.Lact,
  75. EarNumber: v.EarNumber,
  76. //CowTypeName: v.CowType,
  77. })
  78. }
  79. return res
  80. }