添加删除monitor设备接口

This commit is contained in:
junleea 2025-06-06 14:59:25 +08:00
parent 3967d68ce0
commit e94695329c
2 changed files with 38 additions and 0 deletions

View File

@ -102,6 +102,24 @@ func UpdateMonitor(c *gin.Context) {
func DelMonitor(c *gin.Context) { func DelMonitor(c *gin.Context) {
id, _ := c.Get("id") id, _ := c.Get("id")
id1 := int(id.(float64)) 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) { func SetDeviceStatusV2(c *gin.Context) {

View File

@ -164,3 +164,23 @@ func UpdateMonitorDeviceListWithStatus(userId int, deviceReq []proto.GetMonitorD
} }
return err 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
}