package model import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" type NeckRingHealthWarning struct { Id int64 `json:"id"` NeckRingHealthId int64 `json:"neckRingHealthId"` PastureId int64 `json:"pastureId"` CowId int64 `json:"cowId"` EarNumber string `json:"earNumber"` NeckRingNumber string `json:"neckRingNumber"` HeatDate string `json:"heatDate"` MinHigh int32 `json:"minHigh"` MinChew int32 `json:"minChew"` MinIntake int32 `json:"minIntake"` ChewSum int32 `json:"chewSum"` BeforeThreeSumChew int32 `json:"beforeThreeSumChew"` Score int32 `json:"score"` Level pasturePb.WarningHealthLevel_Kind `json:"level"` IsShow pasturePb.IsShow_Kind `json:"is_show"` CreatedAt int64 `json:"created"` UpdatedAt int64 `json:"updated"` } func (n *NeckRingHealthWarning) TableName() string { return "neck_ring_health_warning" } func (n *NeckRingHealthWarning) EventDiseaseUpdate() { n.IsShow = pasturePb.IsShow_No } func NewNeckRingHealthWarning(pastureId int64, neckRingHealth *NeckRingHealth, cow *Cow, newScore int32) *NeckRingHealthWarning { level := pasturePb.WarningHealthLevel_Preliminary if newScore < 60 { level = pasturePb.WarningHealthLevel_Height } else if newScore >= 60 && newScore <= 74 { level = pasturePb.WarningHealthLevel_Moderate } return &NeckRingHealthWarning{ NeckRingHealthId: neckRingHealth.Id, PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, NeckRingNumber: cow.NeckRingNumber, HeatDate: neckRingHealth.HeatDate, MinHigh: neckRingHealth.MinHigh, MinChew: neckRingHealth.MinChew, MinIntake: neckRingHealth.MinInactive, ChewSum: neckRingHealth.SumChew, BeforeThreeSumChew: neckRingHealth.BeforeThreeSumChew, Score: newScore, Level: level, IsShow: pasturePb.IsShow_Ok, } } type NeckRingHealthWarningSlice []*NeckRingHealthWarning func (n NeckRingHealthWarningSlice) ToPB( warningHealthLevelMap map[pasturePb.WarningHealthLevel_Kind]string, cowMap map[int64]*Cow, eventLogMap map[int64]string, ) []*pasturePb.HealthWarningItem { res := make([]*pasturePb.HealthWarningItem, len(n)) for i, v := range n { levelName := "" if ln, ok := warningHealthLevelMap[v.Level]; ok { levelName = ln } data := &pasturePb.HealthWarningItem{ Id: int32(v.Id), CowId: int32(v.CowId), EarNumber: v.EarNumber, PenId: 0, PenName: "", Score: v.Score, HeatDate: v.HeatDate, MinHigh: v.MinHigh, MinChew: v.MinChew, MinIntake: v.MinIntake, SumChew: v.ChewSum, BeforeThreeDaysSumChew: v.ChewSum - v.BeforeThreeSumChew, LastBreedEventDetails: "", Level: v.Level, LevelName: levelName, ChangeChewTime: v.ChewSum - v.BeforeThreeSumChew, } if cow, ok := cowMap[v.CowId]; ok { data.PenId = cow.PenId data.PenName = cow.PenName data.Lact = cow.Lact } if desc, ok := eventLogMap[v.CowId]; ok { data.LastBreedEventDetails = desc } res[i] = data } return res }