添加删除monitor设备接口
This commit is contained in:
parent
3967d68ce0
commit
e94695329c
|
|
@ -102,6 +102,24 @@ func UpdateMonitor(c *gin.Context) {
|
|||
func DelMonitor(c *gin.Context) {
|
||||
id, _ := c.Get("id")
|
||||
id1 := int(id.(float64))
|
||||
var req UpdateMonitorDeviceStatusReq
|
||||
var resp proto.GeneralResp
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
delSuccess, err2 := service.DelMonitorDeviceListWithStatus(id1, req.Devices)
|
||||
if err2 != nil {
|
||||
resp.Code = proto.OperationFailed
|
||||
resp.Message = "更新设备状态失败:" + err2.Error()
|
||||
resp.Data = delSuccess
|
||||
} else {
|
||||
resp.Code = proto.SuccessCode
|
||||
resp.Message = "更新设备状态成功"
|
||||
resp.Data = delSuccess
|
||||
}
|
||||
} else {
|
||||
resp.Code = proto.ParameterError
|
||||
resp.Message = "参数解析失败:" + err.Error()
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetDeviceStatusV2(c *gin.Context) {
|
||||
|
|
|
|||
|
|
@ -164,3 +164,23 @@ func UpdateMonitorDeviceListWithStatus(userId int, deviceReq []proto.GetMonitorD
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DelMonitorDeviceListWithStatus(userId int, deviceReq []proto.GetMonitorDeviceStatus) ([]proto.GetMonitorDeviceStatus, error) {
|
||||
user := GetUserByIDFromUserCenter(userId)
|
||||
var err error
|
||||
var delDevices []proto.GetMonitorDeviceStatus
|
||||
if user.Role != "admin" {
|
||||
err = errors.New("user is not admin, can not update monitor device list")
|
||||
return delDevices, err
|
||||
} else {
|
||||
for _, device := range deviceReq {
|
||||
if worker.IsContainSet(proto.Config.MONITOR_SERVER_TOKEN, device.ID) {
|
||||
// 如果设备在集合中,则删除状态
|
||||
worker.DelRedis("monitor_" + device.ID)
|
||||
worker.SetRedisSetRemove(proto.Config.MONITOR_SERVER_TOKEN, device.ID)
|
||||
delDevices = append(delDevices, device)
|
||||
}
|
||||
}
|
||||
}
|
||||
return delDevices, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue