修改状态码文档,修改设备处理状态码更改
This commit is contained in:
parent
255dbd9567
commit
2a65a3f675
|
|
@ -3,7 +3,7 @@
|
||||||
# 2.请求状态码
|
# 2.请求状态码
|
||||||
状态码 | 说明
|
状态码 | 说明
|
||||||
---|---
|
---|---
|
||||||
0 | 请求成功
|
0 | 请求成功,处理成功
|
||||||
1 | 请求失败
|
1 | 请求失败
|
||||||
2 | Token失效,未登录
|
2 | Token失效,未登录
|
||||||
3 | Token为空
|
3 | Token为空
|
||||||
|
|
@ -17,3 +17,7 @@
|
||||||
11 | 视频延迟操作失败
|
11 | 视频延迟操作失败
|
||||||
12 | 视频删除失败
|
12 | 视频删除失败
|
||||||
13 | 设备重启失败
|
13 | 设备重启失败
|
||||||
|
14 | 查询数据失败
|
||||||
|
15 | 设备添加失败
|
||||||
|
16 | 设备修改失败
|
||||||
|
17 | 数据库数据操作失败
|
||||||
|
|
@ -62,10 +62,10 @@ func DeleteDevice(c *gin.Context) {
|
||||||
if service.DeleteDevice(req.ID, int(id.(float64))) {
|
if service.DeleteDevice(req.ID, int(id.(float64))) {
|
||||||
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
c.JSON(200, gin.H{"code": 17, "message": "failed"})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
c.JSON(200, gin.H{"code": 9, "message": "failed"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,13 +81,13 @@ func UpdateDevice(c *gin.Context) {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"code": 1,
|
"code": 16,
|
||||||
"message": "failed",
|
"message": "failed",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"code": 1,
|
"code": 9,
|
||||||
"message": "failed",
|
"message": "failed",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +104,7 @@ func SetDeviceStatus(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
c.JSON(200, gin.H{"code": 9, "message": "failed", "data": err.Error()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,20 +117,22 @@ func AddDevice(c *gin.Context) {
|
||||||
device_id := service.AddDevice(req.DeviceName, req.DeviceIP, req.DeviceStatus, req.DeviceInfo, req.DeviceType, req.DeviceLocation, user_id)
|
device_id := service.AddDevice(req.DeviceName, req.DeviceIP, req.DeviceStatus, req.DeviceInfo, req.DeviceType, req.DeviceLocation, user_id)
|
||||||
if device_id != 0 {
|
if device_id != 0 {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"code": 0,
|
"code": 0,
|
||||||
"message": "success",
|
"message": "success",
|
||||||
"device_id": device_id,
|
"data": device_id,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"code": 1,
|
"code": 15,
|
||||||
"message": "failed",
|
"message": "failed",
|
||||||
|
"data": "device add failed",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"code": 1,
|
"code": 9,
|
||||||
"message": "failed",
|
"message": "failed",
|
||||||
|
"data": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +151,7 @@ func RestartDevice(c *gin.Context) {
|
||||||
user_id, _ := c.Get("id")
|
user_id, _ := c.Get("id")
|
||||||
var req DeviceRestartReq
|
var req DeviceRestartReq
|
||||||
if err := c.ShouldBind(&req); err != nil {
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
c.JSON(200, gin.H{"code": 9, "message": "failed", "data": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
device_id := req.ID
|
device_id := req.ID
|
||||||
|
|
@ -160,11 +162,11 @@ func RestartDevice(c *gin.Context) {
|
||||||
if Restart(device.DeviceIP) {
|
if Restart(device.DeviceIP) {
|
||||||
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
c.JSON(200, gin.H{"code": 13, "message": "failed"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
c.JSON(200, gin.H{"code": 14, "message": "failed", "data": string(device_id) + ": device not found"})
|
||||||
}
|
}
|
||||||
} else if req.Option == "all" {
|
} else if req.Option == "all" {
|
||||||
devices := service.GetDeviceList(int(user_id.(float64)))
|
devices := service.GetDeviceList(int(user_id.(float64)))
|
||||||
|
|
@ -172,11 +174,13 @@ func RestartDevice(c *gin.Context) {
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
if device.DeviceIP != "" {
|
if device.DeviceIP != "" {
|
||||||
if !Restart(device.DeviceIP) {
|
if !Restart(device.DeviceIP) {
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
c.JSON(200, gin.H{"code": 13, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
c.JSON(200, gin.H{"code": 14, "message": "failed", "data": "device not found"})
|
||||||
}
|
}
|
||||||
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue