功能实现,硬件管理

master
a7458969 2020-03-21 11:17:24 +08:00
parent eba983e8b2
commit 3f2d6707f5
3 changed files with 69 additions and 7 deletions

View File

@ -288,6 +288,8 @@ func DeleteArticle(c *gin.Context) {
rsp.Status = 0 rsp.Status = 0
rsp.Msg = "OK" rsp.Msg = "OK"
} }
func ArticlesTypes(c *gin.Context) { func ArticlesTypes(c *gin.Context) {
resp := RespBase{"unkown error",-231,nil} resp := RespBase{"unkown error",-231,nil}
defer func() { defer func() {

27
controller/hardware.go Normal file
View File

@ -0,0 +1,27 @@
package controller
import (
"github.com/gin-gonic/gin"
"time"
)
// this api is based on elasticsearch
type Hardware struct {
ID int32 `json:"id"`
BuyDate time.Time `json:"buy_date"` //购入时间
Name string `json:"name"` // 名字
Desc string `json:"desc"` // 描述
Pic string `json:"pic"` // 图片
Doc string `json:"doc"` //文档资料
}
func AddHardware(c *gin.Context) {
resp := RespBase{"unkown error",-231,nil}
defer func() {
c.JSON(200,resp)
}()
resp.Data = docTypes
resp.Msg = "OK"
resp.Status = 0
}

View File

@ -48,6 +48,7 @@ func (p *ElkEngine)Create(index string,types string,id string,data interface{})
return errors.New(CREATED_ERROR) return errors.New(CREATED_ERROR)
} }
if err != nil { if err != nil {
print(err)
return err return err
} }
}else{ }else{
@ -66,18 +67,50 @@ func (p *ElkEngine)Delete(index string,types string,id string) error{
Id(id). Id(id).
Do() Do()
if err != nil { if err != nil {
print(err)
return err return err
} }
if !res.Found{ if !res.Found{
return errors.New(DELETE_ERROR) return errors.New(DELETE_ERROR)
} }
}else{ }else{
return errors.New(ERROR_PTR) return errors.New(ERROR_PTR)
} }
return nil
} }
func (p *ElkEngine)Search(index string,types string,id string) (interface{},error){ /*
return nil,nil */
func (p *ElkEngine)Query(index string,types string,query elastic.Query,data interface{}) ([]interface{},error) {
if nil != p{
res, err := p.cli.
Search(index).
Type(types).
Query(query).
Do()
if err != nil {
print(err)
return nil,err
}
//var typ Employee
typ := reflect.TypeOf(data)
return res.Each(typ),nil
}else{
return nil,errors.New(ERROR_PTR)
}
}
func (p *ElkEngine)Update(index string,types string,id string,data map[string]interface{}) error {
if nil != p {
_, err := p.cli.Update().
Index(index).
Type(types).
Id(id).
Doc(data).
Do()
if err != nil {
println(err.Error())
return err
}
}
return errors.New(ERROR_PTR)
} }