2020-03-21 11:17:24 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2020-04-01 01:07:32 +08:00
|
|
|
"background/logs"
|
2020-03-25 10:57:25 +08:00
|
|
|
"background/model"
|
2020-08-24 02:08:26 +08:00
|
|
|
|
2020-03-21 11:17:24 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2020-03-25 10:57:25 +08:00
|
|
|
"qiniupkg.com/x/log.v7"
|
2020-03-21 11:17:24 +08:00
|
|
|
)
|
2020-06-20 23:15:23 +08:00
|
|
|
|
2020-08-24 02:08:26 +08:00
|
|
|
func AddHardware(c *gin.Context) {
|
|
|
|
resp := RespBase{"unkown error", -231, nil}
|
2020-03-21 11:17:24 +08:00
|
|
|
defer func() {
|
2020-08-24 02:08:26 +08:00
|
|
|
c.JSON(200, resp)
|
2020-03-21 11:17:24 +08:00
|
|
|
}()
|
2020-03-25 10:57:25 +08:00
|
|
|
var hardware model.Hardware
|
|
|
|
|
|
|
|
e := c.BindJSON(&hardware)
|
2020-08-24 02:08:26 +08:00
|
|
|
if nil != e {
|
2020-03-25 10:57:25 +08:00
|
|
|
log.Print(e)
|
|
|
|
print(e)
|
|
|
|
return
|
|
|
|
}
|
2020-08-24 02:08:26 +08:00
|
|
|
e = hardware.CreateHardware()
|
|
|
|
if nil != e {
|
2020-04-01 01:07:32 +08:00
|
|
|
resp.Status = -100
|
|
|
|
resp.Msg = e.Error()
|
2020-03-30 02:10:18 +08:00
|
|
|
log.Print(e)
|
2020-03-25 10:57:25 +08:00
|
|
|
return
|
|
|
|
}
|
2020-03-25 00:30:55 +08:00
|
|
|
resp.Data = nil
|
2020-03-21 11:17:24 +08:00
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
2020-03-25 00:30:55 +08:00
|
|
|
}
|
|
|
|
|
2020-08-24 02:08:26 +08:00
|
|
|
func DeleteHardWare(c *gin.Context) {
|
|
|
|
resp := RespBase{"unkown error", -231, nil}
|
2020-04-01 01:07:32 +08:00
|
|
|
defer func() {
|
2020-08-24 02:08:26 +08:00
|
|
|
c.JSON(200, resp)
|
2020-04-01 01:07:32 +08:00
|
|
|
}()
|
|
|
|
name := c.Query("name")
|
2020-08-24 02:08:26 +08:00
|
|
|
if name == "" {
|
2020-04-01 01:07:32 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
e := model.DeleteHardware(name)
|
2020-08-24 02:08:26 +08:00
|
|
|
if nil != e {
|
2020-04-01 01:07:32 +08:00
|
|
|
logs.Error(e.Error())
|
2020-04-26 14:11:36 +08:00
|
|
|
return
|
2020-04-01 01:07:32 +08:00
|
|
|
}
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
resp.Data = nil
|
2020-03-25 00:30:55 +08:00
|
|
|
}
|
|
|
|
|
2021-02-06 01:46:59 +08:00
|
|
|
func SearchDoc(c *gin.Context){
|
|
|
|
type ReqSearch struct{
|
|
|
|
Content string `json:"content"`
|
|
|
|
}
|
|
|
|
resp := RespBase{"unkown error", -231, nil}
|
|
|
|
defer func() {
|
|
|
|
c.JSON(200, resp)
|
|
|
|
}()
|
|
|
|
req := ReqSearch{}
|
|
|
|
e := c.BindJSON(&req)
|
|
|
|
if nil != e {
|
|
|
|
log.Print(e)
|
|
|
|
print(e)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resp.Data = nil
|
|
|
|
resp.Msg = "OK"
|
|
|
|
resp.Status = 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-24 02:08:26 +08:00
|
|
|
func UpdateHardWare(c *gin.Context) {
|
2020-03-25 00:30:55 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-24 02:08:26 +08:00
|
|
|
func ReadHardWare(c *gin.Context) {
|
|
|
|
rsp := RespBase{"ERR", -1, nil}
|
2020-03-26 00:30:07 +08:00
|
|
|
defer func() {
|
2020-08-24 02:08:26 +08:00
|
|
|
c.JSON(200, rsp)
|
2020-03-26 00:30:07 +08:00
|
|
|
}()
|
2020-03-28 00:00:46 +08:00
|
|
|
|
2020-08-24 02:08:26 +08:00
|
|
|
limit, offset := GetPageParaFromQuery(c)
|
|
|
|
log.Print(limit, offset)
|
|
|
|
hardware, e := model.GetHardwares(limit, offset)
|
|
|
|
if nil != e {
|
2020-03-26 00:30:07 +08:00
|
|
|
return
|
|
|
|
}
|
2020-03-26 13:17:20 +08:00
|
|
|
rsp.Data = hardware
|
|
|
|
rsp.Msg = "OK"
|
|
|
|
rsp.Status = 0
|
2020-03-25 00:30:55 +08:00
|
|
|
}
|