neck_ring_health_warning.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ) []*pasturePb.HealthWarningItem {
  59. res := make([]*pasturePb.HealthWarningItem, len(n))
  60. for i, v := range n {
  61. levelName := ""
  62. if ln, ok := warningHealthLevelMap[v.Level]; ok {
  63. levelName = ln
  64. }
  65. data := &pasturePb.HealthWarningItem{
  66. Id: int32(v.Id),
  67. CowId: int32(v.CowId),
  68. EarNumber: v.EarNumber,
  69. PenId: 0,
  70. PenName: "",
  71. Score: v.Score,
  72. HeatDate: v.HeatDate,
  73. MinHigh: v.MinHigh,
  74. MinChew: v.MinChew,
  75. MinIntake: v.MinIntake,
  76. SumChew: v.ChewSum,
  77. BeforeThreeDaysSumChew: v.ChewSum - v.BeforeThreeSumChew,
  78. LastBreedEventDetails: "",
  79. Level: v.Level,
  80. LevelName: levelName,
  81. ChangeChewTime: v.ChewSum - v.BeforeThreeSumChew,
  82. }
  83. if cow, ok := cowMap[v.CowId]; ok {
  84. data.PenId = cow.PenId
  85. data.PenName = cow.PenName
  86. data.Lact = cow.Lact
  87. data.HealthStatus = cow.HealthStatus
  88. data.HealthStatusName = healthStatusMap[cow.HealthStatus]
  89. }
  90. if desc, ok := eventLogMap[v.CowId]; ok {
  91. data.LastBreedEventDetails = desc
  92. }
  93. res[i] = data
  94. }
  95. return res
  96. }