diff --git a/controller/hardware.go b/controller/hardware.go index eb76fc6..c68eab0 100644 --- a/controller/hardware.go +++ b/controller/hardware.go @@ -43,6 +43,7 @@ func DeleteHardWare(c *gin.Context) { e := model.DeleteHardware(name) if nil != e{ logs.Error(e.Error()) + return } resp.Msg = "OK" resp.Status = 0 diff --git a/db/elasticEngine.go b/db/elasticEngine.go index 57b08bd..7004c9b 100644 --- a/db/elasticEngine.go +++ b/db/elasticEngine.go @@ -43,18 +43,15 @@ func (p *ElkEngine)Create(index string,types string,id string,data interface{}) return nil } -func (p *ElkEngine)Delete(index string,types string,id string) error{ +func (p *ElkEngine)Delete(query elastic.Query,index string) error{ if nil != p{ - res, err := p.cli.Delete().Index(index). - Id(id). + _, err := p.cli.DeleteByQuery().Index(index).Query(query). Do(context.Background()) if err != nil { - print(err) + log.Print(err) return err } - if !res.ForcedRefresh{ - return errors.New(DELETE_ERROR) - } + }else{ return errors.New(ERROR_PTR) } diff --git a/model/hardware.go b/model/hardware.go index fc7b411..bea880b 100644 --- a/model/hardware.go +++ b/model/hardware.go @@ -50,7 +50,7 @@ func (this *Hardware )CreateHardware( ) error{ return errors.New(ERR_COLUMN_EXISTED) } } - e = db.GetElastic().Create("hardware","0","",*this) + e = db.GetElastic().Create("hardware_data","0","",*this) if nil != e{ log.Print("shit1") log.Print(e.Error()) @@ -62,7 +62,7 @@ func (this *Hardware )CreateHardware( ) error{ func GetHardwares(limit int,size int) ([]Hardware,error){ var ret []Hardware - data,ids,e := db.GetElastic().Query("hardware",nil,Hardware{},limit,size) + data,ids,e := db.GetElastic().Query("hardware_data",nil,Hardware{},limit,size) if nil != e{ return nil,e } @@ -77,7 +77,7 @@ func GetHardwares(limit int,size int) ([]Hardware,error){ func QueryHardwares(query elastic.Query,limit int,offset int) ([]Hardware,error){ var ret []Hardware - data,ids,e := db.GetElastic().Query("hardware",query,Hardware{},limit,offset) + data,ids,e := db.GetElastic().Query("hardware_data",query,Hardware{},limit,offset) log.Print(data) if nil != e{ return nil,e @@ -92,17 +92,10 @@ func QueryHardwares(query elastic.Query,limit int,offset int) ([]Hardware,error) } func DeleteHardware(name string) error{ - matchPhraseQuery := elastic.NewMatchQuery("name", "stm32开发板") - existedHardware,e := QueryHardwares(matchPhraseQuery,10,0) - log.Print(e,existedHardware) - - for _,v := range existedHardware{ - if v.Name == name{ - err := db.GetElastic().Delete("hardware","",v.ID) - if err != nil { - return err - } - } + query := elastic.NewTermQuery("name",name) + err := db.GetElastic().Delete(query,"hardware_data") + if err != nil{ + return err } return nil } \ No newline at end of file