neck_ring_health_warning.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package model
  2. import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  3. type NeckRingHealthWarning struct {
  4. Id int64 `json:"id"`
  5. NeckRingHealthId int64 `json:"neckRingHealthId"`
  6. PastureId int64 `json:"pastureId"`
  7. CowId int64 `json:"cowId"`
  8. EarNumber string `json:"earNumber"`
  9. NeckRingNumber string `json:"neckRingNumber"`
  10. HeatDate string `json:"heatDate"`
  11. MinHigh int32 `json:"minHigh"`
  12. MinChew int32 `json:"minChew"`
  13. MinIntake int32 `json:"minIntake"`
  14. ChewSum int32 `json:"chewSum"`
  15. BeforeThreeSumChew int32 `json:"beforeThreeSumChew"`
  16. Score int32 `json:"score"`
  17. Level pasturePb.WarningHealthLevel_Kind `json:"level"`
  18. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  19. CreatedAt int64 `json:"created"`
  20. UpdatedAt int64 `json:"updated"`
  21. }
  22. func (n *NeckRingHealthWarning) TableName() string {
  23. return "neck_ring_health_warning"
  24. }
  25. func (n *NeckRingHealthWarning) EventDiseaseUpdate() {
  26. n.IsShow = pasturePb.IsShow_No
  27. }
  28. func NewNeckRingHealthWarning(pastureId int64, neckRingHealth *NeckRingHealth, cow *Cow, newScore int32) *NeckRingHealthWarning {
  29. level := pasturePb.WarningHealthLevel_Preliminary
  30. if newScore < 60 {
  31. level = pasturePb.WarningHealthLevel_Height
  32. } else if newScore >= 60 && newScore <= 74 {
  33. level = pasturePb.WarningHealthLevel_Moderate
  34. }
  35. return &NeckRingHealthWarning{
  36. NeckRingHealthId: neckRingHealth.Id,
  37. PastureId: pastureId,
  38. CowId: cow.Id,
  39. EarNumber: cow.EarNumber,
  40. NeckRingNumber: cow.NeckRingNumber,
  41. HeatDate: neckRingHealth.HeatDate,
  42. MinHigh: neckRingHealth.MinHigh,
  43. MinChew: neckRingHealth.MinChew,
  44. MinIntake: neckRingHealth.MinInactive,
  45. ChewSum: neckRingHealth.SumChew,
  46. BeforeThreeSumChew: neckRingHealth.BeforeThreeSumChew,
  47. Score: newScore,
  48. Level: level,
  49. IsShow: pasturePb.IsShow_Ok,
  50. }
  51. }
  52. type NeckRingHealthWarningSlice []*NeckRingHealthWarning
  53. func (n NeckRingHealthWarningSlice) ToPB(
  54. warningHealthLevelMap map[pasturePb.WarningHealthLevel_Kind]string,
  55. cowMap map[int64]*Cow,
  56. eventLogMap map[int64]string,
  57. healthStatusMap map[pasturePb.HealthStatus_Kind]string,
  58. dayData map[int64]*NeckActiveHabit,
  59. ) []*pasturePb.HealthWarningItem {
  60. res := make([]*pasturePb.HealthWarningItem, len(n))
  61. for i, v := range n {
  62. levelName := ""
  63. if ln, ok := warningHealthLevelMap[v.Level]; ok {
  64. levelName = ln
  65. }
  66. data := &pasturePb.HealthWarningItem{
  67. Id: int32(v.Id),
  68. CowId: int32(v.CowId),
  69. EarNumber: v.EarNumber,
  70. Score: v.Score,
  71. HeatDate: v.HeatDate,
  72. MinHigh: v.MinHigh,
  73. MinChew: v.MinChew,
  74. MinIntake: v.MinIntake,
  75. SumChew: v.ChewSum,
  76. BeforeThreeDaysSumChew: v.ChewSum - v.BeforeThreeSumChew,
  77. LastBreedEventDetails: "",
  78. Level: v.Level,
  79. LevelName: levelName,
  80. ChangeChewTime: v.ChewSum - v.BeforeThreeSumChew,
  81. ChangeHigh: float32(dayData[v.CowId].ChangeHigh),
  82. ChangeRumina: float32(dayData[v.CowId].ChangeRumina),
  83. DayRumina: float32(dayData[v.CowId].Rumina),
  84. DayIntake: float32(dayData[v.CowId].Intake),
  85. DayInactive: float32(dayData[v.CowId].Inactive),
  86. DayImmobility: float32(dayData[v.CowId].Active),
  87. }
  88. if cow, ok := cowMap[v.CowId]; ok {
  89. data.PenId = cow.PenId
  90. data.PenName = cow.PenName
  91. data.Lact = cow.Lact
  92. data.HealthStatus = cow.HealthStatus
  93. data.HealthStatusName = healthStatusMap[cow.HealthStatus]
  94. }
  95. if desc, ok := eventLogMap[v.CowId]; ok {
  96. data.LastBreedEventDetails = desc
  97. }
  98. res[i] = data
  99. }
  100. return res
  101. }