|
|
@ -1,6 +1,11 @@ |
|
|
|
package org.dromara.sample.manage.controller; |
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission; |
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
import org.dromara.common.core.domain.R; |
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
|
import org.dromara.common.satoken.utils.LoginHelper; |
|
|
|
import org.dromara.common.web.core.BaseController; |
|
|
|
import org.dromara.sample.manage.model.dto.DeviceDTO; |
|
|
|
import org.dromara.sample.manage.model.dto.DeviceFirmwareUpgradeDTO; |
|
|
|
import org.dromara.sample.manage.service.IDeviceService; |
|
|
@ -35,22 +40,23 @@ public class DeviceController { |
|
|
|
* Get the topology list of all online devices in one workspace. |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/devices") |
|
|
|
public HttpResultResponse<List<DeviceDTO>> getDevices() { |
|
|
|
LoginUser loginUser = LoginHelper.getLoginUser(); |
|
|
|
List<DeviceDTO> devicesList = deviceService.getDevicesTopoForWeb(loginUser.getTenantId()); |
|
|
|
|
|
|
|
@GetMapping("/{workspace_id}/devices") |
|
|
|
@SaCheckPermission("work:spaces:list") |
|
|
|
@Operation(summary = "获取一个工作区中所有在线设备的列表。", description = "获取一个工作区中所有在线设备的列表") |
|
|
|
public HttpResultResponse<List<DeviceDTO>> getDevices(@PathVariable("workspace_id") String workspaceId) { |
|
|
|
List<DeviceDTO> devicesList = deviceService.getDevicesTopoForWeb(workspaceId); |
|
|
|
return HttpResultResponse.success(devicesList); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 绑定设备 |
|
|
|
* 将设备绑定到工作区,只能web查看 |
|
|
|
* After binding the device to the workspace, the device data can only be seen on the web. |
|
|
|
* @param device |
|
|
|
* @param deviceSn |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/{device_sn}/binding") |
|
|
|
@Operation(summary = "获取一个工作区中所有在线设备的列表。", description = "获取一个工作区中所有在线设备的列表") |
|
|
|
public HttpResultResponse bindDevice(@RequestBody DeviceDTO device, @PathVariable("device_sn") String deviceSn) { |
|
|
|
device.setDeviceSn(deviceSn); |
|
|
|
boolean isUpd = deviceService.bindDevice(device); |
|
|
@ -63,11 +69,12 @@ public class DeviceController { |
|
|
|
* @param deviceSn |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/devices/{device_sn}") |
|
|
|
public HttpResultResponse getDevice( |
|
|
|
@GetMapping("/{workspace_id}/devices/{device_sn}") |
|
|
|
@Operation(summary = "根据设备sn获取设备信息。", description = "根据设备sn获取设备信息。") |
|
|
|
public HttpResultResponse getDevice(@PathVariable("workspace_id") String workspaceId, |
|
|
|
@PathVariable("device_sn") String deviceSn) { |
|
|
|
Optional<DeviceDTO> deviceOpt = deviceService.getDeviceBySn(deviceSn); |
|
|
|
return deviceOpt.isEmpty() ? HttpResultResponse.error("device not found.") : HttpResultResponse.success(deviceOpt.get()); |
|
|
|
return deviceOpt.isEmpty() ? HttpResultResponse.error("找不到该设备。") : HttpResultResponse.success(deviceOpt.get()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -77,23 +84,25 @@ public class DeviceController { |
|
|
|
* @param pageSize |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/devices/bound") |
|
|
|
@Operation(summary = "在工作区中获取绑定设备列表。", description = "在工作区中获取绑定设备列表。") |
|
|
|
@GetMapping("/{workspace_id}/devices/bound") |
|
|
|
public HttpResultResponse<PaginationData<DeviceDTO>> getBoundDevicesWithDomain( |
|
|
|
Integer domain, |
|
|
|
@PathVariable("workspace_id") String workspaceId,Integer domain, |
|
|
|
@RequestParam(defaultValue = "1") Long page, |
|
|
|
@RequestParam(value = "page_size", defaultValue = "50") Long pageSize) { |
|
|
|
LoginUser loginUser = LoginHelper.getLoginUser(); |
|
|
|
PaginationData<DeviceDTO> devices = deviceService.getBoundDevicesWithDomain(loginUser.getTenantId(), page, pageSize, domain); |
|
|
|
PaginationData<DeviceDTO> devices = deviceService.getBoundDevicesWithDomain(workspaceId, page, pageSize, domain); |
|
|
|
|
|
|
|
return HttpResultResponse.success(devices); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 正在删除设备的绑定状态。 |
|
|
|
* 删除设备的绑定状态。 |
|
|
|
* Removing the binding state of the device. |
|
|
|
* @param deviceSn |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Operation(summary = "删除设备的绑定状态。", description = "删除设备的绑定状态。") |
|
|
|
@DeleteMapping("/{device_sn}/unbinding") |
|
|
|
public HttpResultResponse unbindingDevice(@PathVariable("device_sn") String deviceSn) { |
|
|
|
deviceService.unbindDevice(deviceSn); |
|
|
@ -108,7 +117,9 @@ public class DeviceController { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PutMapping("/devices/{device_sn}") |
|
|
|
@Operation(summary = "更新设备信息。", description = "更新设备信息。") |
|
|
|
public HttpResultResponse updateDevice(@RequestBody DeviceDTO device, |
|
|
|
@PathVariable("workspace_id") String workspaceId, |
|
|
|
@PathVariable("device_sn") String deviceSn) { |
|
|
|
device.setDeviceSn(deviceSn); |
|
|
|
boolean isUpd = deviceService.updateDevice(device); |
|
|
@ -121,11 +132,11 @@ public class DeviceController { |
|
|
|
* @param upgradeDTOS |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Operation(summary = "设备离线固件升级任务。", description = "设备离线固件升级任务。") |
|
|
|
@PostMapping("/devices/ota") |
|
|
|
public HttpResultResponse createOtaJob( |
|
|
|
public HttpResultResponse createOtaJob(@PathVariable("workspace_id") String workspaceId, |
|
|
|
@RequestBody List<DeviceFirmwareUpgradeDTO> upgradeDTOS) { |
|
|
|
LoginUser loginUser = LoginHelper.getLoginUser(); |
|
|
|
return deviceService.createDeviceOtaJob(loginUser.getTenantId(), upgradeDTOS); |
|
|
|
return deviceService.createDeviceOtaJob(workspaceId, upgradeDTOS); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -135,15 +146,16 @@ public class DeviceController { |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PutMapping("/devices/{device_sn}/property") |
|
|
|
public HttpResultResponse devicePropertySet(@PathVariable("device_sn") String dockSn, |
|
|
|
@Operation(summary = "设置无人机的属性参数。", description = "设置无人机的属性参数。") |
|
|
|
@PutMapping("/{workspace_id}/devices/{device_sn}/property") |
|
|
|
public HttpResultResponse devicePropertySet(@PathVariable("workspace_id") String workspaceId, |
|
|
|
@PathVariable("device_sn") String dockSn, |
|
|
|
@RequestBody JsonNode param) { |
|
|
|
LoginUser loginUser = LoginHelper.getLoginUser(); |
|
|
|
if (param.size() != 1) { |
|
|
|
return HttpResultResponse.error(CloudSDKErrorEnum.INVALID_PARAMETER); |
|
|
|
} |
|
|
|
|
|
|
|
int result = deviceService.devicePropertySet(loginUser.getTenantId(), dockSn, param); |
|
|
|
int result = deviceService.devicePropertySet(workspaceId, dockSn, param); |
|
|
|
return PropertySetReplyResultEnum.SUCCESS.getResult() == result ? |
|
|
|
HttpResultResponse.success() : HttpResultResponse.error(result, String.valueOf(result)); |
|
|
|
} |
|
|
|