Commit 689db98149f91925a2c6e2c4d5bd3b4f879b0ba7

Authored by xp.Huang
1 parent d1c55bce

feat: 提供批量获取产品物模型的接口

... ... @@ -24,10 +24,7 @@ import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
24 24 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
25 25 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
26 26 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
27   -import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
28   -import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO;
29   -import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO;
30   -import org.thingsboard.server.common.data.yunteng.dto.TkThingsModel;
  27 +import org.thingsboard.server.common.data.yunteng.dto.*;
31 28 import org.thingsboard.server.common.data.yunteng.dto.thingsmodel.ImportThingsModelDTO;
32 29 import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum;
33 30 import org.thingsboard.server.common.data.yunteng.enums.ImportEnum;
... ... @@ -44,6 +41,7 @@ import java.io.IOException;
44 41 import java.io.InputStream;
45 42 import java.util.HashMap;
46 43 import java.util.List;
  44 +import java.util.Map;
47 45
48 46 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
49 47 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE;
... ... @@ -367,4 +365,16 @@ public class ThingsModelController extends BaseController {
367 365 return null;
368 366 }
369 367 }
  368 +
  369 + @PostMapping("/batch/get_tsl")
  370 + @ApiOperation("获取多个产品的物模型数据")
  371 + public ResponseEntity<List<BatchDeviceProfileInfoDTO>> getDeviceProfilesTSL(@RequestBody DeviceProfileTSLDTO profileTSLDTO)
  372 + throws ThingsboardException {
  373 + if(null == profileTSLDTO.getDeviceProfileIds() || null == profileTSLDTO.getFunctionTypeEnum() ||
  374 + profileTSLDTO.getDeviceProfileIds().isEmpty()){
  375 + throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
  376 + }
  377 + return ResponseEntity.ok(thingsModelService.getDeviceProfileTSLInfoByIds(getCurrentUser().getCurrentTenantId(),
  378 + profileTSLDTO.getDeviceProfileIds(),profileTSLDTO.getFunctionTypeEnum()));
  379 + }
370 380 }
... ...
  1 +package org.thingsboard.server.common.data.yunteng.dto;
  2 +
  3 +import com.fasterxml.jackson.databind.JsonNode;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
  7 +
  8 +@Data
  9 +public class BatchDeviceProfileInfoDTO {
  10 +
  11 + @ApiModelProperty(value = "产品ID/设备配置ID")
  12 + private String id;
  13 + @ApiModelProperty(value = "产品名称/设备配置名称")
  14 + private String name;
  15 + @ApiModelProperty(value = "传输协议")
  16 + private String transportType;
  17 + @ApiModelProperty(value = "产品类型:GATEWAY,DIRECT_CONNECTION,SENSOR")
  18 + private DeviceTypeEnum deviceType;
  19 + @ApiModelProperty(value = "物模型TSL")
  20 + private JsonNode tsl;
  21 +}
... ...
  1 +package org.thingsboard.server.common.data.yunteng.dto;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum;
  6 +
  7 +import java.util.List;
  8 +
  9 +@Data
  10 +public class DeviceProfileTSLDTO {
  11 +
  12 + @ApiModelProperty(value = "产品id列表", required = true)
  13 + private List<String> deviceProfileIds;
  14 +
  15 + @ApiModelProperty(value = "查询的物模型类型", required = true)
  16 + private FunctionTypeEnum functionTypeEnum;
  17 +}
... ...
... ... @@ -188,7 +188,7 @@ public class ThingsModelServiceImpl
188 188 new LambdaQueryWrapper<TkThingsModelEntity>()
189 189 .eq(TkThingsModelEntity::getTenantId, tenantId)
190 190 .eq(TkThingsModelEntity::getDeviceProfileId, deviceProfileId)
191   - .eq(TkThingsModelEntity::getFunctionType, typeEnum)
  191 + .eq(!typeEnum.equals(FunctionTypeEnum.all),TkThingsModelEntity::getFunctionType, typeEnum)
192 192 .eq(TkThingsModelEntity::getStatus, StatusEnum.ENABLE.getIndex()));
193 193 if (entityList.isEmpty()) {
194 194 return null;
... ... @@ -267,7 +267,7 @@ public class ThingsModelServiceImpl
267 267 for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {
268 268 JsonNode functionJson = thingsModelDTO.getFunctionJson();
269 269 if (null != functionJson) {
270   - switch (typeEnum) {
  270 + switch (thingsModelDTO.getFunctionType()) {
271 271 case properties:
272 272 AttributeModelDTO attributeModelDTO = new AttributeModelDTO();
273 273 BeanUtils.copyProperties(thingsModelDTO, attributeModelDTO);
... ... @@ -440,6 +440,30 @@ public class ThingsModelServiceImpl
440 440 }
441 441 return true;
442 442 }
  443 +
  444 + @Override
  445 + public List<BatchDeviceProfileInfoDTO> getDeviceProfileTSLInfoByIds(String tenantId, List<String> deviceProfileIds, FunctionTypeEnum functionTypeEnum) {
  446 + List<BatchDeviceProfileInfoDTO> list = new ArrayList<>();
  447 + if(null != deviceProfileIds && !deviceProfileIds.isEmpty()){
  448 + deviceProfileIds.stream().forEach(deviceProfileId->{
  449 + BatchDeviceProfileInfoDTO batchDeviceProfileInfo = new BatchDeviceProfileInfoDTO();
  450 + DeviceProfileDTO deviceProfileDTO = tkDeviceProfileService.getDeviceProfile(tenantId,deviceProfileId);
  451 + if(null != deviceProfileDTO){
  452 + batchDeviceProfileInfo.setId(deviceProfileId);
  453 + batchDeviceProfileInfo.setName(deviceProfileDTO.getName());
  454 + batchDeviceProfileInfo.setDeviceType(deviceProfileDTO.getDeviceType());
  455 + batchDeviceProfileInfo.setTransportType(deviceProfileDTO.getTransportType());
  456 + JsonNode tsl = getTingsModelTSL(functionTypeEnum,tenantId,deviceProfileId);
  457 + if(null != tsl && tsl.isArray()){
  458 + batchDeviceProfileInfo.setTsl(tsl);
  459 + }
  460 + list.add(batchDeviceProfileInfo);
  461 + }
  462 + });
  463 + }
  464 + return list;
  465 + }
  466 +
443 467 private void checkNameAndIdentifier(
444 468 List<String> existIdentifiers,
445 469 FunctionTypeEnum functionType,
... ...
1 1 package org.thingsboard.server.dao.yunteng.service;
2 2
3 3 import com.fasterxml.jackson.databind.JsonNode;
  4 +import org.thingsboard.server.common.data.yunteng.dto.BatchDeviceProfileInfoDTO;
4 5 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
5 6 import org.thingsboard.server.common.data.yunteng.dto.ThingsModelDTO;
6 7 import org.thingsboard.server.common.data.yunteng.dto.TkThingsModel;
... ... @@ -50,8 +51,14 @@ public interface ThingsModelService extends BaseService<TkThingsModelEntity>{
50 51
51 52 boolean getByIdentifier(String tenantId, String deviceProfileId,String categoryId,String identifier);
52 53
53   -
54   -
55   -
  54 + /**
  55 + * 获取对应产品列表的物模型信息
  56 + * @param tenantId 租户ID
  57 + * @param deviceProfileIds 产品列表
  58 + * @param functionTypeEnum
  59 + * @return
  60 + */
  61 + List<BatchDeviceProfileInfoDTO> getDeviceProfileTSLInfoByIds(String tenantId, List<String> deviceProfileIds,
  62 + FunctionTypeEnum functionTypeEnum);
56 63
57 64 }
... ...