#init
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
package com.fastbee.controller;
|
||||
|
||||
import com.fastbee.common.annotation.Log;
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.model.LoginUser;
|
||||
import com.fastbee.common.enums.BusinessType;
|
||||
import com.fastbee.common.utils.MessageUtils;
|
||||
import com.fastbee.dto.DeviceBindDTO;
|
||||
import com.fastbee.service.TransferDeviceService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/forward/device")
|
||||
public class TransferDeviceController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private TransferDeviceService transferDeviceService;
|
||||
|
||||
@PostMapping("bind")
|
||||
@ApiOperation("绑定设备")
|
||||
@Log(title = "绑定设备", businessType = BusinessType.OTHER)
|
||||
public AjaxResult bind(@RequestBody DeviceBindDTO bindDTO) {
|
||||
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return transferDeviceService.bind(bindDTO, user);
|
||||
}
|
||||
|
||||
@PostMapping("unbind")
|
||||
@ApiOperation("解绑设备")
|
||||
@Log(title = "解绑设备", businessType = BusinessType.OTHER)
|
||||
public AjaxResult unbind(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return transferDeviceService.unbind(bindDTO, user);
|
||||
}
|
||||
|
||||
@PostMapping("updateDeviceAlias")
|
||||
@ApiOperation("更新设备别名")
|
||||
@Log(title = "更新设备别名", businessType = BusinessType.OTHER)
|
||||
public AjaxResult updateDeviceAlias(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceAlias())) {
|
||||
return AjaxResult.error("设备别名为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return transferDeviceService.updateDeviceAlias(bindDTO, user);
|
||||
}
|
||||
|
||||
@PostMapping("switchDevice")
|
||||
@ApiOperation("切换设备")
|
||||
@Log(title = "切换设备", businessType = BusinessType.OTHER)
|
||||
public AjaxResult switchDevice(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
if (user == null) {
|
||||
return AjaxResult.error("当前token用户不存在!");
|
||||
}
|
||||
return AjaxResult.success(transferDeviceService.switchDevice(bindDTO, user));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的控制权在哪 能否控制
|
||||
*/
|
||||
@PostMapping("remoteControl")
|
||||
@ApiOperation("获取当前设备控制权")
|
||||
@Log(title = "获取当前设备控制权", businessType = BusinessType.OTHER)
|
||||
public AjaxResult remoteControl(@RequestBody DeviceBindDTO bindDTO) {
|
||||
try {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return AjaxResult.success(transferDeviceService.remoteControl(bindDTO, user));
|
||||
} catch (Exception e) {
|
||||
logger.error("获取设备控制权出错", e);
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换控制请求
|
||||
*/
|
||||
@PostMapping("switchControl")
|
||||
@ApiOperation("切换控制请求")
|
||||
@Log(title = "切换控制请求", businessType = BusinessType.OTHER)
|
||||
public AjaxResult switchControl(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getDeviceId())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
return AjaxResult.success(transferDeviceService.switchControl(bindDTO, user));
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放控制权
|
||||
*/
|
||||
@PostMapping("releaseControl")
|
||||
@ApiOperation("释放控制权")
|
||||
@Log(title = "释放控制权", businessType = BusinessType.OTHER)
|
||||
public AjaxResult releaseControl(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (StringUtils.isEmpty(bindDTO.getPlatform())) {
|
||||
return AjaxResult.error("平台为空!");
|
||||
}
|
||||
LoginUser user = getLoginUser();
|
||||
transferDeviceService.releaseControl(bindDTO, user);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user