|
|
@@ -3,8 +3,10 @@ package com.inspur.netty.controller;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import com.inspur.device.domain.bo.SmsbOtaRecordBo;
|
|
|
import com.inspur.device.domain.constants.DeviceConstants;
|
|
|
+import com.inspur.device.domain.constants.DeviceTaskConstants;
|
|
|
import com.inspur.device.domain.vo.SmsbDeviceVo;
|
|
|
import com.inspur.device.service.ISmsbDeviceService;
|
|
|
+import com.inspur.device.service.ISmsbDeviceTaskService;
|
|
|
import com.inspur.device.service.ISmsbOtaRecordService;
|
|
|
import com.inspur.netty.message.push.PushMessageType;
|
|
|
import com.inspur.netty.util.NettyConstants;
|
|
|
@@ -40,6 +42,9 @@ public class DeviceController {
|
|
|
@Autowired
|
|
|
private ISmsbOtaRecordService smsbOtaRecordService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISmsbDeviceTaskService deviceTaskService;
|
|
|
+
|
|
|
/**
|
|
|
* 重启设备
|
|
|
*
|
|
|
@@ -48,15 +53,18 @@ public class DeviceController {
|
|
|
*/
|
|
|
@GetMapping("/reboot/{deviceId}")
|
|
|
public R<String> reboot(@PathVariable Long deviceId) {
|
|
|
- // 查询设备信息
|
|
|
+ // 1 查询设备信息
|
|
|
SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
|
|
|
if (deviceVo == null) {
|
|
|
return R.fail("设备不存在");
|
|
|
}
|
|
|
- // 组装重启命令
|
|
|
+ // 2 任务中心创建任务
|
|
|
+ String taskParam = PushMessageType.CONTROL_REBOOT.getValue();
|
|
|
+ deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_TASK_REBOOT, deviceVo, taskParam);
|
|
|
+ // 3 组装重启命令 发送长连接
|
|
|
String rebootCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_REBOOT.getValue() + NettyConstants.DATA_PACK_SEPARATOR;
|
|
|
boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), rebootCmd);
|
|
|
- return isSend ? R.ok() : R.fail("发送失败,设备长连接已断开");
|
|
|
+ return isSend ? R.ok() : R.fail("长连接发送失败,设备长连接已断开");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -86,15 +94,18 @@ public class DeviceController {
|
|
|
*/
|
|
|
@GetMapping("/shutdown/{deviceId}")
|
|
|
public R<String> shutdown(@PathVariable Long deviceId) {
|
|
|
- // 查询设备信息
|
|
|
+ // 1 查询设备信息
|
|
|
SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
|
|
|
if (deviceVo == null) {
|
|
|
return R.fail("设备不存在");
|
|
|
}
|
|
|
- // 组装重启命令
|
|
|
+ // 2 任务中心创建任务
|
|
|
+ String taskParam = PushMessageType.CONTROL_SHUTDOWN.getValue();
|
|
|
+ deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_TASK_SHUTDOWN, deviceVo, taskParam);
|
|
|
+ // 3 组装关机命令 发送长连接
|
|
|
String shutdownCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_SHUTDOWN.getValue() + NettyConstants.DATA_PACK_SEPARATOR;
|
|
|
boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), shutdownCmd);
|
|
|
- return isSend ? R.ok() : R.fail("发送失败,设备长连接已断开");
|
|
|
+ return isSend ? R.ok() : R.fail("长连接发送失败,设备长连接已断开");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -105,40 +116,44 @@ public class DeviceController {
|
|
|
*/
|
|
|
@GetMapping("/standby/{deviceId}")
|
|
|
public R<String> standby(@PathVariable Long deviceId) {
|
|
|
- // 查询设备信息
|
|
|
+ // 1 查询设备信息
|
|
|
SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
|
|
|
if (deviceVo == null) {
|
|
|
return R.fail("设备不存在");
|
|
|
}
|
|
|
- // 组装重启命令
|
|
|
+ // 2 任务中心创建任务
|
|
|
+ String taskParam = PushMessageType.CONTROL_STANDBY.getValue();
|
|
|
+ deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_TASK_STANDBY, deviceVo, taskParam);
|
|
|
+ // 3 组装待机命令 发送长连接
|
|
|
String standbyCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_STANDBY.getValue() + NettyConstants.DATA_PACK_SEPARATOR;
|
|
|
boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), standbyCmd);
|
|
|
- return isSend ? R.ok() : R.fail("发送失败,设备长连接已断开");
|
|
|
+ return isSend ? R.ok() : R.fail("长连接发送失败,设备长连接已断开");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 设备待机
|
|
|
+ * 截屏
|
|
|
*
|
|
|
* @param deviceId
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/screenshot/{deviceId}")
|
|
|
public R<String> screenshot(@PathVariable Long deviceId) {
|
|
|
- // 查询设备信息
|
|
|
+ // 1 查询设备信息
|
|
|
SmsbDeviceVo deviceVo = smsbDeviceService.getDeviceCacheById(deviceId);
|
|
|
if (deviceVo == null) {
|
|
|
return R.fail("设备不存在");
|
|
|
}
|
|
|
- // 组装重启命令
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
+ // 2 任务中心创建任务
|
|
|
+ String taskParam = PushMessageType.CONTROL_SCREENSHOT.getValue() + "/" + timestamp;
|
|
|
+ deviceTaskService.createNewDeviceTask(DeviceTaskConstants.DEVICE_TASK_SCREENSHOT, deviceVo, taskParam);
|
|
|
+ // 3 缓存Rediskey
|
|
|
+ String redisKey = DeviceConstants.REDIS_SCREENSHOT_KEY + deviceId + ":" + timestamp;
|
|
|
+ String redisValue = LoginHelper.getUserId().toString();
|
|
|
+ RedisUtils.setCacheObject(redisKey, redisValue, Duration.ofMinutes(10));
|
|
|
+ // 4 组装截屏命令
|
|
|
String screenshotCmd = deviceVo.getIdentifier() + PushMessageType.CONTROL_SCREENSHOT.getValue() + "/" + timestamp + NettyConstants.DATA_PACK_SEPARATOR;
|
|
|
boolean isSend = PushMsgUtil.sendV2(deviceVo.getIdentifier(), screenshotCmd);
|
|
|
- // 如果消息发送成功 缓存Rediskey
|
|
|
- if (isSend) {
|
|
|
- String redisKey = DeviceConstants.REDIS_SCREENSHOT_KEY + deviceId + ":" + timestamp;
|
|
|
- String redisValue = LoginHelper.getUserId().toString();
|
|
|
- RedisUtils.setCacheObject(redisKey, redisValue, Duration.ofMinutes(1));
|
|
|
- }
|
|
|
return isSend ? R.ok() : R.fail("发送失败,设备长连接已断开");
|
|
|
|
|
|
}
|