package mqtt import ( "kpt-pasture/model" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) // NeckRingIsBind 脖环是否绑定 func (e *Entry) NeckRingIsBind(number string) bool { var count int64 = 0 if err := e.DB.Model(new(model.NeckRing)).Where("number = ?", number). Where("status != ?", pasturePb.NeckRingStatus_Unbind). Count(&count).Error; err != nil { return false } if count > 0 { return true } return false } func (e *Entry) GetCowInfoByImei(imei string) *model.Cow { res := &model.Cow{} if err := e.DB.Model(new(model.Cow)).Where("neck_ring_number = ?", imei).First(res).Error; err != nil { return nil } return res } func (e *Entry) GetSystemConfigure(name string) *model.SystemConfigure { res := &model.SystemConfigure{} if err := e.DB.Model(new(model.SystemConfigure)). Where("name = ?", name). Where("is_show = ?", pasturePb.IsShow_Ok). First(res).Error; err != nil { return nil } return res } func (e *Entry) IsExistNeckActiveHabit(neckRingNumber, heatDate string, frameId int32) (*model.NeckActiveHabit, int64) { count := int64(0) res := &model.NeckActiveHabit{} if err := e.DB.Model(new(model.NeckActiveHabit)). Where("neck_ring_number = ?", neckRingNumber). Where("heat_date = ?", heatDate). Where("frameid = ?", frameId). Count(&count). First(res). Error; err != nil { return nil, 0 } return res, count }