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