neck_ring_health_warning.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. CreatedAt int64 `json:"created"`
  19. UpdatedAt int64 `json:"updated"`
  20. }
  21. func (n *NeckRingHealthWarning) TableName() string {
  22. return "neck_ring_health_warning"
  23. }
  24. func NewNeckRingHealthWarning(pastureId int64, neckRingHealth *NeckRingHealth, cow *Cow, newScore int32) *NeckRingHealthWarning {
  25. level := pasturePb.WarningHealthLevel_Preliminary
  26. if newScore < 60 {
  27. level = pasturePb.WarningHealthLevel_Height
  28. } else if newScore >= 60 && newScore <= 74 {
  29. level = pasturePb.WarningHealthLevel_Moderate
  30. }
  31. return &NeckRingHealthWarning{
  32. NeckRingHealthId: pastureId,
  33. PastureId: neckRingHealth.Id,
  34. CowId: cow.Id,
  35. EarNumber: cow.EarNumber,
  36. NeckRingNumber: cow.NeckRingNumber,
  37. HeatDate: neckRingHealth.HeatDate,
  38. MinHigh: neckRingHealth.MinHigh,
  39. MinChew: neckRingHealth.MinChew,
  40. MinIntake: neckRingHealth.MinInactive,
  41. ChewSum: neckRingHealth.SumChew,
  42. BeforeThreeSumChew: neckRingHealth.BeforeThreeSumChew,
  43. Score: newScore,
  44. Level: level,
  45. }
  46. }
  47. type NeckRingHealthWarningSlice []*NeckRingHealthWarning
  48. func (n NeckRingHealthWarningSlice) ToPB(
  49. warningHealthLevelMap map[pasturePb.WarningHealthLevel_Kind]string,
  50. cowMap map[int64]*Cow,
  51. eventLogMap map[int64]string,
  52. ) []*pasturePb.HealthWarningItem {
  53. res := make([]*pasturePb.HealthWarningItem, len(n))
  54. for i, v := range n {
  55. levelName := ""
  56. if ln, ok := warningHealthLevelMap[v.Level]; ok {
  57. levelName = ln
  58. }
  59. data := &pasturePb.HealthWarningItem{
  60. Id: int32(v.Id),
  61. CowId: int32(v.CowId),
  62. EarNumber: v.EarNumber,
  63. PenId: 0,
  64. PenName: "",
  65. Score: v.Score,
  66. HeatDate: v.HeatDate,
  67. MinHigh: v.MinHigh,
  68. MinChew: v.MinChew,
  69. MinIntake: v.MinIntake,
  70. SumChew: v.ChewSum,
  71. BeforeThreeDaysSumChew: v.BeforeThreeSumChew,
  72. LastBreedEventDetails: "",
  73. Level: v.Level,
  74. LevelName: levelName,
  75. }
  76. if cow, ok := cowMap[v.CowId]; ok {
  77. data.PenId = cow.PenId
  78. data.PenName = cow.PenName
  79. data.Lact = cow.Lact
  80. }
  81. if desc, ok := eventLogMap[v.CowId]; ok {
  82. data.LastBreedEventDetails = desc
  83. }
  84. res[i] = data
  85. }
  86. return res
  87. }