Showing
3 changed files
with
66 additions
and
0 deletions
1 | +--菜单权限 | |
2 | +INSERT INTO "public"."sys_menu"("id", "parent_id", "path", "type", "permission", "creator", "create_time", "updater", "update_time", "name", "tenant_id", "component", "redirect", "alias", "case_sensitive", "meta", "sort") VALUES ('45fedfd7-e1df-4090-8754-286c55dd84d3', '815b9cb0-dbdd-4e57-a1c5-2820741d8e5f', NULL, 'SYSADMIN', 'api:yt:device:update:product', '80808080-8080-8080-8080-808080808080', '2023-12-12 15:09:59.413169', NULL, NULL, '更新产品', '13814000-1dd2-11b2-8080-808080808080', NULL, NULL, NULL, NULL, '{"title":"更新产品","menuType":"2","status":"0"}', 11); | |
3 | + | |
4 | +--字典表 | |
5 | + | |
6 | +INSERT INTO "public"."sys_dict_item"("id", "dict_id", "item_text", "item_value", "description", "sort", "status", "tenant_id", "creator", "create_time", "updater", "update_time") VALUES ('c923e463-3b46-4460-bd90-bfd43becad79', '671d5516-ba19-4bfe-a135-5db1dfd920b9', '模版组态设计', 'api:yt:configuration:template:center:get_configuration_info:design', '可视化管理/组态/模版', 1, 1, '13814000-1dd2-11b2-8080-808080808080', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:49:52.266946', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:51:47.117805'); | |
7 | +INSERT INTO "public"."sys_dict_item"("id", "dict_id", "item_text", "item_value", "description", "sort", "status", "tenant_id", "creator", "create_time", "updater", "update_time") VALUES ('376149e9-1e8c-45ae-80e9-b3963ab518d7', '671d5516-ba19-4bfe-a135-5db1dfd920b9', '模版组态删除', 'api:yt:configuration:template:center:delete', '可视化管理/组态/模版', 1, 1, '13814000-1dd2-11b2-8080-808080808080', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:49:01.099506', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:51:47.623122'); | |
8 | +INSERT INTO "public"."sys_dict_item"("id", "dict_id", "item_text", "item_value", "description", "sort", "status", "tenant_id", "creator", "create_time", "updater", "update_time") VALUES ('6b8b68b2-808f-417d-b92f-35442e5289e2', '671d5516-ba19-4bfe-a135-5db1dfd920b9', '模版组态新增', 'api:yt:configuration:template:center:post', '可视化管理/组态/模版', 1, 1, '13814000-1dd2-11b2-8080-808080808080', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:48:17.375162', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:49:04.168494'); | |
9 | +INSERT INTO "public"."sys_dict_item"("id", "dict_id", "item_text", "item_value", "description", "sort", "status", "tenant_id", "creator", "create_time", "updater", "update_time") VALUES ('7cf1e8a0-dbdd-48b0-920c-b40ee681f55e', '671d5516-ba19-4bfe-a135-5db1dfd920b9', '模版组态编辑', 'api:yt:configuration:template:center:update', '可视化管理/组态/模版', 1, 1, '13814000-1dd2-11b2-8080-808080808080', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:48:04.709476', '80808080-8080-8080-8080-808080808080', '2023-12-13 16:49:07.675075'); | ... | ... |
... | ... | @@ -63,6 +63,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; |
63 | 63 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
64 | 64 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
65 | 65 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
66 | +import org.thingsboard.server.common.data.yunteng.dto.BatchDeviceUpdateDTO; | |
66 | 67 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
67 | 68 | import org.thingsboard.server.common.data.yunteng.dto.TkCustomerDeviceDTO; |
68 | 69 | import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; |
... | ... | @@ -213,6 +214,47 @@ public class DeviceController extends BaseController { |
213 | 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 | 259 | @ApiOperation(value = "Create Device (saveDevice) with credentials ", |
218 | 260 | notes = "Create or update the Device. When creating device, platform generates Device Id as " + UUID_WIKI_LINK + | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/BatchDeviceUpdateDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModelProperty; | |
4 | +import lombok.Data; | |
5 | + | |
6 | +import java.util.List; | |
7 | + | |
8 | +@Data | |
9 | +public class BatchDeviceUpdateDTO { | |
10 | + @ApiModelProperty(value = "批量删除设备ids(tbDeviceId)") | |
11 | + private List<String> deviceIds; | |
12 | + | |
13 | + @ApiModelProperty(value = "产品ID(tbDeviceProfileId)") | |
14 | + private String deviceProfileId; | |
15 | +} | ... | ... |