Commit f89a0362a4b927db6930b30fb7c6a66d25e1ee9d

Authored by chenjunyu_1481036421
1 parent 525b8863

feat:1.批量修改组织 2.批量公开设备 3.批量私有设备

... ... @@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
40 40 import org.springframework.web.bind.annotation.RestController;
41 41 import org.springframework.web.context.request.async.DeferredResult;
42 42 import org.thingsboard.common.util.JacksonUtil;
  43 +import org.thingsboard.rule.engine.api.TbNodeException;
43 44 import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg;
44 45 import org.thingsboard.server.common.data.*;
45 46 import org.thingsboard.server.common.data.audit.ActionType;
... ... @@ -371,6 +372,23 @@ public class DeviceController extends BaseController {
371 372 }
372 373 }
373 374
  375 +
  376 + @PostMapping("/batch/customer/device/")
  377 + @ApiOperation("批量私有设备")
  378 + @PreAuthorize("hasAuthority('TENANT_ADMIN')")
  379 + public ResponseEntity<String> batchCustomerDevice(
  380 + @ApiParam(value = "设备ID") @RequestParam(value = "deviceIds", required = false)List<String> deviceIds) throws ThingsboardException {
  381 + for (String deviceId:deviceIds) {
  382 +
  383 + try {
  384 + unassignDeviceFromCustomer(deviceId);
  385 + } catch (ThingsboardException e) {
  386 + throw new ThingsboardException(e.getErrorCode());
  387 + }
  388 + }
  389 + return ResponseEntity.ok("私有成功");
  390 + }
  391 +
374 392 @ApiOperation(value = "Unassign device from customer (unassignDeviceFromCustomer)",
375 393 notes = "Clears assignment of the device to customer. Customer will not be able to query device afterwards." + TENANT_AUTHORITY_PARAGRAPH)
376 394 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
... ... @@ -407,6 +425,22 @@ public class DeviceController extends BaseController {
407 425 }
408 426 }
409 427
  428 +
  429 + @PostMapping("/batch/customer/public/device/")
  430 + @ApiOperation("批量公开设备")
  431 + @PreAuthorize("hasAuthority('TENANT_ADMIN')")
  432 + public ResponseEntity<String> batchCustomerPublicDevice(
  433 + @ApiParam(value = "设备ID") @RequestParam(value = "deviceIds", required = false)List<String> deviceIds) throws ThingsboardException {
  434 + for (String deviceId:deviceIds) {
  435 + try {
  436 + assignDeviceToPublicCustomer(deviceId);
  437 + } catch (ThingsboardException e) {
  438 + throw new ThingsboardException(e.getErrorCode());
  439 + }
  440 + }
  441 + return ResponseEntity.ok("公开成功");
  442 + }
  443 +
410 444 @ApiOperation(value = "Make device publicly available (assignDeviceToPublicCustomer)",
411 445 notes = "Device will be available for non-authorized (not logged-in) users. " +
412 446 "This is useful to create dashboards that you plan to share/embed on a publicly available website. " +
... ...
... ... @@ -64,6 +64,24 @@ public class TkDeviceController extends BaseController {
64 64 private final TkAlarmInfoService tkAlarmInfoService ;
65 65
66 66
  67 + @PostMapping("/batch/update")
  68 + @ApiOperation("批量修改设备")
  69 + @PreAuthorize(
  70 + "@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:device:post','api:yt:device:update'})")
  71 + public ResponseEntity<String> batchUpdateDevice(
  72 + @Validated(AddGroup.class) @RequestBody List<DeviceDTO> deviceDTO,String orgId)
  73 + throws ThingsboardException, ExecutionException, InterruptedException {
  74 + deviceDTO.stream().forEach(i ->{
  75 + i.setOrganizationId(orgId);
  76 + try {
  77 + saveDevice(i);
  78 + } catch (Exception e) {
  79 + e.printStackTrace();
  80 + }
  81 + });
  82 + return ResponseEntity.ok("编辑成功");
  83 + }
  84 +
67 85
68 86 @PostMapping
69 87 @ApiOperation("创建|编辑")
... ...