|
@@ -63,6 +63,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; |
|
@@ -63,6 +63,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; |
63
|
import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
|
63
|
import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
|
64
|
import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
|
64
|
import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
|
65
|
import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
|
65
|
import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
|
|
|
66
|
+import org.thingsboard.server.common.data.yunteng.dto.BatchDeviceUpdateDTO;
|
66
|
import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
|
67
|
import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
|
67
|
import org.thingsboard.server.common.data.yunteng.dto.TkCustomerDeviceDTO;
|
68
|
import org.thingsboard.server.common.data.yunteng.dto.TkCustomerDeviceDTO;
|
68
|
import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
|
69
|
import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
|
|
@@ -213,6 +214,47 @@ public class DeviceController extends BaseController { |
|
@@ -213,6 +214,47 @@ public class DeviceController extends BaseController { |
213
|
throw handleException(e);
|
214
|
throw handleException(e);
|
214
|
}
|
215
|
}
|
215
|
}
|
216
|
}
|
|
|
217
|
+ //thingskit
|
|
|
218
|
+ @ApiOperation(value = "批量修改设备的产品",notes = "批量修改产品的设备是同类型的设备")
|
|
|
219
|
+ @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:device:update:product'})")
|
|
|
220
|
+ @RequestMapping(value = "/device/batch/update", method = RequestMethod.POST)
|
|
|
221
|
+ public boolean batchUpdateDeviceProfileById(@RequestBody BatchDeviceUpdateDTO batchDevice) throws ThingsboardException {
|
|
|
222
|
+ List<String> batchDeviceIds = batchDevice.getDeviceIds();
|
|
|
223
|
+ String deviceProfileId = batchDevice.getDeviceProfileId();
|
|
|
224
|
+ if(StringUtils.isEmpty(deviceProfileId) || null == batchDeviceIds || batchDeviceIds.isEmpty()){
|
|
|
225
|
+ throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
|
|
226
|
+ }
|
|
|
227
|
+ TenantId tenantId = getCurrentUser().getTenantId();
|
|
|
228
|
+ DeviceProfileId profileId = new DeviceProfileId(toUUID(deviceProfileId));
|
|
|
229
|
+ //检查产品是否是该租户的
|
|
|
230
|
+ DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(tenantId,profileId);
|
|
|
231
|
+ if(null == deviceProfile){
|
|
|
232
|
+ throw new TkDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage());
|
|
|
233
|
+ }
|
|
|
234
|
+ for (String id: batchDeviceIds){
|
|
|
235
|
+ if(StringUtils.isEmpty(id)){
|
|
|
236
|
+ throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
|
|
237
|
+ }
|
|
|
238
|
+ Device savedDevice = null;
|
|
|
239
|
+ try {
|
|
|
240
|
+ DeviceId deviceId = new DeviceId(toUUID(id));
|
|
|
241
|
+ Device oldDevice = checkDeviceId(deviceId, Operation.WRITE);
|
|
|
242
|
+ savedDevice = checkNotNull(deviceService.findDeviceById(tenantId,deviceId));
|
|
|
243
|
+ savedDevice.setDeviceProfileId(profileId);
|
|
|
244
|
+ savedDevice.setType(deviceProfile.getName());
|
|
|
245
|
+ checkNotNull(deviceService.saveDeviceWithAccessToken(savedDevice, null));
|
|
|
246
|
+ onDeviceCreatedOrUpdated(savedDevice, oldDevice, true, getCurrentUser());
|
|
|
247
|
+ //更新tk_device
|
|
|
248
|
+ tkDeviceService.updateDeviceProfileByTbDeviceId(tenantId.toString(),
|
|
|
249
|
+ id,deviceProfileId);
|
|
|
250
|
+ }catch (Exception e){
|
|
|
251
|
+ logEntityAction(emptyId(EntityType.DEVICE), savedDevice,
|
|
|
252
|
+ null, ActionType.UPDATED, e);
|
|
|
253
|
+ throw handleException(e);
|
|
|
254
|
+ }
|
|
|
255
|
+ }
|
|
|
256
|
+ return true;
|
|
|
257
|
+ }
|
216
|
|
258
|
|
217
|
@ApiOperation(value = "Create Device (saveDevice) with credentials ",
|
259
|
@ApiOperation(value = "Create Device (saveDevice) with credentials ",
|
218
|
notes = "Create or update the Device. When creating device, platform generates Device Id as " + UUID_WIKI_LINK +
|
260
|
notes = "Create or update the Device. When creating device, platform generates Device Id as " + UUID_WIKI_LINK +
|