neck_ring_health_warning.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. ) []*pasturePb.HealthWarningItem {
  58. res := make([]*pasturePb.HealthWarningItem, len(n))
  59. for i, v := range n {
  60. levelName := ""
  61. if ln, ok := warningHealthLevelMap[v.Level]; ok {
  62. levelName = ln
  63. }
  64. data := &pasturePb.HealthWarningItem{
  65. Id: int32(v.Id),
  66. CowId: int32(v.CowId),
  67. EarNumber: v.EarNumber,
  68. PenId: 0,
  69. PenName: "",
  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. }
  82. if cow, ok := cowMap[v.CowId]; ok {
  83. data.PenId = cow.PenId
  84. data.PenName = cow.PenName
  85. data.Lact = cow.Lact
  86. }
  87. if desc, ok := eventLogMap[v.CowId]; ok {
  88. data.LastBreedEventDetails = desc
  89. }
  90. res[i] = data
  91. }
  92. return res
  93. }