接口修改,size为0,获取全部硬件信息

master
a7458969 2020-03-26 13:17:20 +08:00
parent cb08c725ca
commit 6baf8c4546
4 changed files with 42 additions and 19 deletions

View File

@ -48,6 +48,9 @@ func ReadHardWare(c *gin.Context) {
log.Error(e.Error()) log.Error(e.Error())
return return
} }
//limit,offset := GetPageParaFromQuery(c) limit,offset := GetPageParaFromQuery(c)
hardware,e := model.GetHardwares(limit,offset)
rsp.Data = hardware
rsp.Msg = "OK"
rsp.Status = 0
} }

View File

@ -70,17 +70,32 @@ func (p *ElkEngine)Query(index string,
types string,query elastic.Query,data interface{}, types string,query elastic.Query,data interface{},
limit int,offset int) ([]interface{},error) { limit int,offset int) ([]interface{},error) {
if nil != p{ if nil != p{
res, err := p.cli. if(limit == 0){
Search(index). res, err := p.cli.
Type(types). Search(index).
Query(query).Size(limit).From(limit*offset).Do() Type(types).
if err != nil { Query(query).Do()
print(err) if err != nil {
return nil,err print(err)
return nil,err
}
//var typ Employee
typ := reflect.TypeOf(data)
return res.Each(typ),nil
}else{
res, err := p.cli.
Search(index).
Type(types).
Query(query).Size(limit).From(limit*offset).Do()
if err != nil {
print(err)
return nil,err
}
//var typ Employee
typ := reflect.TypeOf(data)
return res.Each(typ),nil
} }
//var typ Employee
typ := reflect.TypeOf(data)
return res.Each(typ),nil
}else{ }else{
return nil,errors.New(ERROR_PTR) return nil,errors.New(ERROR_PTR)
} }
@ -150,7 +165,5 @@ func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMappin
// Not acknowledged // Not acknowledged
return errors.New("create mapping fail, esIndexName:" + esIndexName + ", esTypeName:" + esTypeName + ", not Ack nowledged") return errors.New("create mapping fail, esIndexName:" + esIndexName + ", esTypeName:" + esTypeName + ", not Ack nowledged")
} }
return err return err
} }

View File

@ -126,7 +126,7 @@ func main() {
api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型 api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型
api.POST("/hardware",controller.AddHardware) // 新增硬件 api.POST("/hardware",controller.AddHardware) // 新增硬件
api.GET("/hardware",controller.ReadHardWare) // 新增硬件 api.GET("/hardware",controller.ReadHardWare) // 读取硬件
} }

View File

@ -35,7 +35,7 @@ func (this *Hardware )CreateHardware( ) error{
if nil == this{ if nil == this{
return errors.New("null pointer") return errors.New("null pointer")
} }
e := db.GetElastic().Create("hardware","0","sdfasdfasd",*this) e := db.GetElastic().Create("hardware","0","",*this)
if nil != e{ if nil != e{
log.Print(e.Error()) log.Print(e.Error())
return e return e
@ -43,7 +43,14 @@ func (this *Hardware )CreateHardware( ) error{
return nil; return nil;
} }
func (this *Hardware)Hardwares() ([]Hardware,error){ func GetHardwares(limit int,size int) ([]Hardware,error){
var ret []Hardware
return nil,nil data,e := db.GetElastic().Query("hardware","0",nil,Hardware{},limit,size)
if nil != e{
return nil,e
}
for _,v := range data{
ret = append(ret,v.(Hardware))
}
return ret,nil
} }