Commit 73802205a0ce9d1e1ca7be92a2f5e5495a181ad6

Authored by xp.Huang
1 parent a15deac7

feat: 增加产品批量修改规则链

... ... @@ -36,11 +36,14 @@ import org.thingsboard.server.common.data.EntityInfo;
36 36 import org.thingsboard.server.common.data.StringUtils;
37 37 import org.thingsboard.server.common.data.exception.ThingsboardException;
38 38 import org.thingsboard.server.common.data.id.DeviceProfileId;
  39 +import org.thingsboard.server.common.data.id.RuleChainId;
39 40 import org.thingsboard.server.common.data.id.TenantId;
40 41 import org.thingsboard.server.common.data.page.PageData;
41 42 import org.thingsboard.server.common.data.page.PageLink;
  43 +import org.thingsboard.server.common.data.yunteng.dto.BatchUpdateDeviceProfileDTO;
42 44 import org.thingsboard.server.dao.resource.ImageService;
43 45 import org.thingsboard.server.dao.timeseries.TimeseriesService;
  46 +import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService;
44 47 import org.thingsboard.server.queue.util.TbCoreComponent;
45 48 import org.thingsboard.server.service.entitiy.device.profile.TbDeviceProfileService;
46 49 import org.thingsboard.server.service.security.model.SecurityUser;
... ... @@ -82,6 +85,7 @@ public class DeviceProfileController extends BaseController {
82 85
83 86 @Autowired
84 87 private TimeseriesService timeseriesService;
  88 + private final TkDeviceProfileService tkDeviceProfileService;
85 89
86 90 @ApiOperation(value = "Get Device Profile (getDeviceProfileById)",
87 91 notes = "Fetch the Device Profile object based on the provided Device Profile Id. " +
... ... @@ -199,6 +203,25 @@ public class DeviceProfileController extends BaseController {
199 203 return tbDeviceProfileService.save(deviceProfile, getCurrentUser());
200 204 }
201 205
  206 + //thingskit
  207 + @ApiOperation(value = "批量更新产品的规则链")
  208 + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:batch:update:ruleChain'})")
  209 + @RequestMapping(value = "/batch/change/ruleChain", method = RequestMethod.POST)
  210 + @ResponseBody
  211 + public Boolean batchUpdateDeviceProfileRuleChainId(
  212 + @RequestBody BatchUpdateDeviceProfileDTO dto) throws Exception {
  213 + //校验
  214 + tkDeviceProfileService.checkDeviceProfilesCanChangeRuleChain(dto.getDeviceProfileIds(),getTenantId());
  215 + String ruleChainId = dto.getTargetRuleChainId();
  216 + for (String deviceProfileId :dto.getDeviceProfileIds()){
  217 + DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(getTenantId(),new DeviceProfileId(UUID.fromString(deviceProfileId)));
  218 + deviceProfile.setDefaultRuleChainId(new RuleChainId(UUID.fromString(ruleChainId)));
  219 + checkEntity(deviceProfile.getId(), deviceProfile, Resource.DEVICE_PROFILE);
  220 + tbDeviceProfileService.save(deviceProfile, getCurrentUser());
  221 + }
  222 + return true;
  223 + }
  224 +
202 225 @ApiOperation(value = "Delete device profile (deleteDeviceProfile)",
203 226 notes = "Deletes the device profile. Referencing non-existing device profile Id will cause an error. " +
204 227 "Can't delete the device profile if it is referenced by existing devices." + TENANT_AUTHORITY_PARAGRAPH,
... ...
  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 BatchUpdateDeviceProfileDTO {
  10 +
  11 + @ApiModelProperty(value = "选中的产品ID列表")
  12 + private List<String> deviceProfileIds;
  13 +
  14 + @ApiModelProperty(value = "目标规则链ID")
  15 + private String targetRuleChainId;
  16 +}
... ...
... ... @@ -231,7 +231,7 @@ public class TkDeviceProfileServiceImpl
231 231 if(null != datasource){
232 232 JsonNode usedDeviceProfileIds = datasource.get("convertProducts");
233 233 List<String> ids = new ArrayList<>();;
234   - if(usedDeviceProfileIds.isArray()){
  234 + if(null != usedDeviceProfileIds && usedDeviceProfileIds.isArray()){
235 235 Iterator<JsonNode> iteratorNodes = usedDeviceProfileIds.iterator();
236 236 while (iteratorNodes.hasNext()){
237 237 ids.add(iteratorNodes.next().asText());
... ...