no message

master
DESKTOP-4RNDQIC\29019 2021-02-09 23:31:30 +08:00
parent c594771faf
commit 0c8de11e3e
3 changed files with 65 additions and 8 deletions

View File

@ -392,7 +392,48 @@ func CreateBook(c *gin.Context) {
logs.Error(e.Error())
return
}
resp.Data = nil
resp.Data = req
resp.Msg = "OK"
resp.Status = 0
}
func BookCount(c *gin.Context) {
resp := RespBase{"unkown error", -231, nil}
defer func() {
c.JSON(200, resp)
}()
count := 0
db.GetOrm().Model(&model.Book{}).Count(&count)
resp.Data = count
resp.Msg = "OK"
resp.Status = 0
}
func Delbook(c *gin.Context) {
type Req struct{
ID int32 `json:"id"`
}
var req Req
resp := RespBase{"unkown error", -231, nil}
defer func() {
c.JSON(200, resp)
}()
e := c.BindJSON(&req)
if nil != e {
logs.Error(e.Error())
resp.Msg = "wrong input"
return
}
count := 0
e = db.GetOrm().Model(&model.Book{}).Delete(model.Book{ID: int64(req.ID)}).Error
if nil != e{
log.Printf(e.Error())
return
}
resp.Data = count
resp.Msg = "OK"
resp.Status = 0
}
@ -446,6 +487,7 @@ func GetBook(c *gin.Context) {
func GetPageBook(c *gin.Context) {
type ReqGetPageBook struct {
BookName string `json:"book_name"`
}
var req ReqGetPageBook
resp := RespBase{}
@ -472,11 +514,24 @@ func GetPageBook(c *gin.Context) {
return
}
books := []model.Book{}
e = db.GetOrm().Limit(iLmit).Offset(iOffset).Find(&books).Error
if nil != e {
log.Print(e.Error())
return
if req.BookName != ""{
e = db.GetOrm().Model(&model.Book{}).
Where(fmt.Sprintf("book_name like '%%%s%%' ",req.BookName)).
Limit(iLmit).Offset(iOffset).Find(&books).Error
if nil != e {
log.Print(e.Error())
return
}
}else{
e = db.GetOrm().Model(&model.Book{}).
Limit(iLmit).Offset(iOffset).Find(&books).Error
if nil != e {
log.Print(e.Error())
return
}
}
resp.Status = 0
resp.Msg = "OK"
resp.Data = books
@ -627,6 +682,8 @@ func GetMemo(c *gin.Context) {
rsp.Status = 0
rsp.Data = dat
}
func DeleteMemos(c *gin.Context) {
resp := RespBase{"unkown error", -231, nil}
defer func() {

View File

@ -172,7 +172,8 @@ func main() {
api.POST("/book", controller.UpdateBook) //
api.POST("/getbook", controller.GetBook) // 单书籍数据
api.POST("/getbooks", controller.GetPageBook) // 批量书籍
api.POST("/delbook", controller.DeleteMemos) // 删除书籍
api.POST("/delbook", controller.Delbook) // 删除书籍
api.GET("/bookcount", controller.BookCount) // 删除书籍
}

View File

@ -78,7 +78,6 @@ func QueryDocument(query elastic.Query, limit int, offset int) ([]Hardware, erro
return ret, nil
}
func InsertDocToElaticSearch(doc Doc) error {
matchPhraseQuery := elastic.NewMatchQuery("title", doc.Title)
existedHardware, e := QueryHardwares(matchPhraseQuery, 10, 0)
log.Print(e, existedHardware)