12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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"`
- CreatedAt int64 `json:"created"`
- UpdatedAt int64 `json:"updated"`
- }
- func (n *NeckRingHealthWarning) TableName() string {
- return "neck_ring_health_warning"
- }
- 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: pastureId,
- PastureId: neckRingHealth.Id,
- 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,
- }
- }
- 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.BeforeThreeSumChew,
- LastBreedEventDetails: "",
- Level: v.Level,
- LevelName: levelName,
- }
- 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
- }
|