修复device请求数据与重启问题
This commit is contained in:
parent
00c23de1ca
commit
9cf0306744
|
|
@ -8,34 +8,39 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeviceAddReq struct {
|
type DeviceAddReq struct {
|
||||||
DeviceName string `json:"device_name"`
|
DeviceName string `json:"device_name" form:"device_name" binding:"required"`
|
||||||
DeviceIP string `json:"device_ip"`
|
DeviceIP string `json:"device_ip" form:"device_ip" binding:"required"`
|
||||||
DeviceStatus string `json:"device_status"`
|
DeviceStatus string `json:"device_status" form:"device_status" binding:"required"`
|
||||||
AuthID int `json:"auth_id"`
|
AuthID int `json:"auth_id" form:"auth_id" binding:"required"`
|
||||||
DeviceInfo string `json:"device_info"`
|
DeviceInfo string `json:"device_info" form:"device_info" binding:"required"`
|
||||||
DeviceType string `json:"device_type"`
|
DeviceType string `json:"device_type" form:"device_type" binding:"required"`
|
||||||
DeviceLocation string `json:"device_location"`
|
DeviceLocation string `json:"device_location" form:"device_location" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceUpdateReq struct {
|
type DeviceUpdateReq struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id" form:"id"`
|
||||||
DeviceName string `json:"device_name"`
|
DeviceName string `json:"device_name" form:"device_name" binding:"required"`
|
||||||
DeviceIP string `json:"device_ip"`
|
DeviceIP string `json:"device_ip" form:"device_ip" binding:"required"`
|
||||||
DeviceStatus string `json:"device_status"`
|
DeviceStatus string `json:"device_status" form:"device_status" binding:"required"`
|
||||||
AuthID int `json:"auth_id"`
|
AuthID int `json:"auth_id" form:"auth_id" binding:"required"`
|
||||||
DeviceInfo string `json:"device_info"`
|
DeviceInfo string `json:"device_info" form:"device_info" binding:"required"`
|
||||||
DeviceType string `json:"device_type"`
|
DeviceType string `json:"device_type" form:"device_type" binding:"required"`
|
||||||
DeviceLocation string `json:"device_location"`
|
DeviceLocation string `json:"device_location" form:"device_location" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceStatus struct {
|
type DeviceStatus struct {
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip" form:"ip" binding:"required"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status" form:"status" binding:"required"`
|
||||||
ID int `json:"id"`
|
ID int `json:"id" form:"id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceDelReq struct {
|
type DeviceDelReq struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id" form:"id" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeviceRestartReq struct {
|
||||||
|
ID int `json:"id" form:"id" binding:"required"`
|
||||||
|
Option string `json:"option" form:"option" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUpDeviceGroup(router *gin.Engine) {
|
func SetUpDeviceGroup(router *gin.Engine) {
|
||||||
|
|
@ -142,23 +147,38 @@ func GetDeviceList(c *gin.Context) {
|
||||||
|
|
||||||
func RestartDevice(c *gin.Context) {
|
func RestartDevice(c *gin.Context) {
|
||||||
user_id, _ := c.Get("id")
|
user_id, _ := c.Get("id")
|
||||||
var req DeviceDelReq
|
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": 1, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
device_id := req.ID
|
device_id := req.ID
|
||||||
device := service.GetDevice(device_id, int(user_id.(float64)))
|
if req.Option == "one" {
|
||||||
if device.ID != 0 {
|
device := service.GetDevice(device_id, int(user_id.(float64)))
|
||||||
if device.DeviceIP != "" {
|
if device.ID != 0 {
|
||||||
if Restart(device.DeviceIP) {
|
if device.DeviceIP != "" {
|
||||||
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
if Restart(device.DeviceIP) {
|
||||||
} else {
|
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
} else {
|
||||||
|
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
||||||
|
}
|
||||||
|
} else if req.Option == "all" {
|
||||||
|
devices := service.GetDeviceList(int(user_id.(float64)))
|
||||||
|
if len(devices) > 0 {
|
||||||
|
for _, device := range devices {
|
||||||
|
if device.DeviceIP != "" {
|
||||||
|
if !Restart(device.DeviceIP) {
|
||||||
|
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
c.JSON(200, gin.H{"code": 0, "message": "success"})
|
||||||
c.JSON(200, gin.H{"code": 1, "message": "failed"})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue