Commit e37f18915f4673fe65076471e99ffca242cf488e

Authored by 云中非
2 parents f0541523 c428f82e

Merge branch 'master' into 20221124

@@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; @@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
29 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; 29 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
30 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; 30 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
31 import org.thingsboard.server.common.data.yunteng.dto.*; 31 import org.thingsboard.server.common.data.yunteng.dto.*;
  32 +import org.thingsboard.server.common.data.yunteng.enums.DataTypeEnum;
32 import org.thingsboard.server.common.data.yunteng.enums.DeviceState; 33 import org.thingsboard.server.common.data.yunteng.enums.DeviceState;
33 import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; 34 import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
34 import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; 35 import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
@@ -206,7 +207,7 @@ public class YtDeviceController extends BaseController { @@ -206,7 +207,7 @@ public class YtDeviceController extends BaseController {
206 @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType, 207 @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType,
207 @RequestParam(value = "organizationId", required = false) String organizationId, 208 @RequestParam(value = "organizationId", required = false) String organizationId,
208 @RequestParam(value = "alarmStatus", required = false) Integer alarmStatus, 209 @RequestParam(value = "alarmStatus", required = false) Integer alarmStatus,
209 - @RequestParam(value = "profileId", required = false) String profileId, 210 + @RequestParam(value = "deviceProfileId", required = false) String deviceProfileId,
210 @RequestParam(value = ORDER_FILED, required = false) String orderBy, 211 @RequestParam(value = ORDER_FILED, required = false) String orderBy,
211 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) 212 @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
212 throws ThingsboardException { 213 throws ThingsboardException {
@@ -216,7 +217,7 @@ public class YtDeviceController extends BaseController { @@ -216,7 +217,7 @@ public class YtDeviceController extends BaseController {
216 queryMap.put(ORDER_FILED, orderBy); 217 queryMap.put(ORDER_FILED, orderBy);
217 queryMap.put("name", name); 218 queryMap.put("name", name);
218 queryMap.put("alarmStatus", alarmStatus); 219 queryMap.put("alarmStatus", alarmStatus);
219 - queryMap.put("profileId", profileId); 220 + queryMap.put("deviceProfileId", deviceProfileId);
220 if (deviceState != null) { 221 if (deviceState != null) {
221 if (deviceState != DeviceState.INACTIVE) { 222 if (deviceState != DeviceState.INACTIVE) {
222 queryMap.put("deviceState", deviceState == DeviceState.ONLINE); 223 queryMap.put("deviceState", deviceState == DeviceState.ONLINE);
@@ -355,12 +356,14 @@ public class YtDeviceController extends BaseController { @@ -355,12 +356,14 @@ public class YtDeviceController extends BaseController {
355 @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") 356 @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})")
356 @ApiOperation("主设备列表") 357 @ApiOperation("主设备列表")
357 public List<SelectItemDTO> getMasterDevices( 358 public List<SelectItemDTO> getMasterDevices(
358 - @ApiParam(value = "组织ID") @PathVariable("organizationId") String organizationId) 359 + @ApiParam(value = "组织ID") @PathVariable("organizationId") String organizationId,
  360 + @ApiParam(value = "设备配置ID") @RequestParam(value = "deviceProfileId", required = false)
  361 + String deviceProfileId)
359 throws ThingsboardException { 362 throws ThingsboardException {
360 return deviceService.findMasterDevices( 363 return deviceService.findMasterDevices(
361 getCurrentUser().getCurrentTenantId(), 364 getCurrentUser().getCurrentTenantId(),
362 getCurrentUser().isCustomerUser() ? getCurrentUser().getCustomerId().toString() : null, 365 getCurrentUser().isCustomerUser() ? getCurrentUser().getCustomerId().toString() : null,
363 - organizationId); 366 + organizationId,deviceProfileId);
364 } 367 }
365 368
366 @GetMapping("/list/slave/{organizationId}") 369 @GetMapping("/list/slave/{organizationId}")
@@ -484,16 +487,17 @@ public class YtDeviceController extends BaseController { @@ -484,16 +487,17 @@ public class YtDeviceController extends BaseController {
484 return result; 487 return result;
485 } 488 }
486 489
487 - @GetMapping({"/attributes/{profileId}/{id}"}) 490 + @GetMapping({"/attributes/{deviceProfileId}/{id}"})
488 @ApiOperation("获取设备的属性") 491 @ApiOperation("获取设备的属性")
489 public ResponseEntity<JsonNode> getDeviceAttributes( 492 public ResponseEntity<JsonNode> getDeviceAttributes(
490 - @PathVariable("profileId") String profileId, @PathVariable("id") String id) 493 + @PathVariable("deviceProfileId") String deviceProfileId, @PathVariable("id") String id,
  494 + @RequestParam(value = "dataType", required = false) DataTypeEnum dataType)
491 throws ThingsboardException { 495 throws ThingsboardException {
492 String tenantId = getCurrentUser().getCurrentTenantId(); 496 String tenantId = getCurrentUser().getCurrentTenantId();
493 - DeviceProfileDTO dto = ytDeviceProfileService.findByTbDeviceProfileId(tenantId, profileId); 497 + DeviceProfileDTO dto = ytDeviceProfileService.findDeviceProfileById(tenantId, deviceProfileId);
494 if (null == dto) { 498 if (null == dto) {
495 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); 499 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
496 } 500 }
497 - return ResponseEntity.ok(deviceService.getDeviceAttributes(profileId,dto.getId(), id, tenantId)); 501 + return ResponseEntity.ok(deviceService.getDeviceAttributes(deviceProfileId, id, tenantId,dataType));
498 } 502 }
499 } 503 }
@@ -36,9 +36,10 @@ public class DeviceDTO extends TenantDTO { @@ -36,9 +36,10 @@ public class DeviceDTO extends TenantDTO {
36 @NotEmpty( 36 @NotEmpty(
37 message = "设备配置ID不能为空或者空字符串", 37 message = "设备配置ID不能为空或者空字符串",
38 groups = {AddGroup.class}) 38 groups = {AddGroup.class})
39 - @ApiModelProperty(value = "设备配置", required = true) 39 + @ApiModelProperty(value = "TB设备配置ID", required = true)
40 private String profileId; 40 private String profileId;
41 - 41 + @ApiModelProperty(value = "平台设备配置ID", required = true)
  42 + private String deviceProfileId;
42 @ApiModelProperty(value = "关联网关设备") 43 @ApiModelProperty(value = "关联网关设备")
43 private String gatewayId; 44 private String gatewayId;
44 private String gatewayName; 45 private String gatewayName;
@@ -5,32 +5,43 @@ import io.swagger.annotations.ApiModelProperty; @@ -5,32 +5,43 @@ import io.swagger.annotations.ApiModelProperty;
5 import lombok.Data; 5 import lombok.Data;
6 import lombok.EqualsAndHashCode; 6 import lombok.EqualsAndHashCode;
7 import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum; 7 import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum;
  8 +import org.thingsboard.server.common.data.yunteng.enums.CallTypeEnum;
8 import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum; 9 import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum;
9 10
10 import java.util.List; 11 import java.util.List;
11 12
12 /** 13 /**
13 - * @Description 场景联动执行动作数据传输表  
14 - * @Author cxy  
15 - * @Date 2021/11/24 17:32 14 + * @Description 场景联动执行动作数据传输表 @Author cxy @Date 2021/11/24 17:32
16 */ 15 */
17 @Data 16 @Data
18 @EqualsAndHashCode(callSuper = true) 17 @EqualsAndHashCode(callSuper = true)
19 -public class DoActionDTO extends TenantDTO{ 18 +public class DoActionDTO extends TenantDTO {
20 19
21 - @ApiModelProperty(value = "所属设备id")  
22 - private List<String> deviceId;  
23 - private ScopeEnum entityType; 20 + @ApiModelProperty(value = "所属设备id")
  21 + private List<String> deviceId;
24 22
  23 + private ScopeEnum entityType;
25 24
26 - @ApiModelProperty(value = "场景联动内容")  
27 - private JsonNode doContext; 25 + @ApiModelProperty(value = "场景联动内容")
  26 + private JsonNode doContext;
  27 +
  28 + @ApiModelProperty(value = "设备配置ID")
  29 + private String deviceProfileId;
  30 +
  31 + @ApiModelProperty(value = "调用类型:sync同步/async异步")
  32 + private CallTypeEnum callType;
  33 +
  34 + @ApiModelProperty(value = "命令类型:0自定义 1服务")
  35 + private Integer commandType;
  36 +
  37 + @ApiModelProperty(value = "服务模型ID")
  38 + private String thingsModelId;
28 39
29 @ApiModelProperty(value = "输出目标:设备,告警,其他") 40 @ApiModelProperty(value = "输出目标:设备,告警,其他")
30 private ActionTypeEnum outTarget; 41 private ActionTypeEnum outTarget;
31 42
32 - @ApiModelProperty(value = "场景联动id")  
33 - private String sceneLinkageId; 43 + @ApiModelProperty(value = "场景联动id")
  44 + private String sceneLinkageId;
34 45
35 @ApiModelProperty(value = "输出目标为告警才进行配置") 46 @ApiModelProperty(value = "输出目标为告警才进行配置")
36 private String alarmProfileId; 47 private String alarmProfileId;
@@ -19,4 +19,7 @@ public class SelectItemDTO { @@ -19,4 +19,7 @@ public class SelectItemDTO {
19 19
20 @ApiModelProperty("设备类型") 20 @ApiModelProperty("设备类型")
21 private DeviceTypeEnum deviceType; 21 private DeviceTypeEnum deviceType;
  22 +
  23 + @ApiModelProperty("设备配置ID")
  24 + private String deviceProfileId;
22 } 25 }
dao/src/main/java/org/thingsboard/server/dao/yunteng/entities/TkDeviceEntity.java renamed from dao/src/main/java/org/thingsboard/server/dao/yunteng/entities/TkDevice.java
@@ -13,12 +13,13 @@ import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; @@ -13,12 +13,13 @@ import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
13 @Data 13 @Data
14 @EqualsAndHashCode(callSuper = true) 14 @EqualsAndHashCode(callSuper = true)
15 @TableName(value = ModelConstants.Table.TK_DEVICE_TABLE_NAME, autoResultMap = true) 15 @TableName(value = ModelConstants.Table.TK_DEVICE_TABLE_NAME, autoResultMap = true)
16 -public class TkDevice extends TenantBaseEntity { 16 +public class TkDeviceEntity extends TenantBaseEntity {
17 private String name; 17 private String name;
18 private String alias; 18 private String alias;
19 @TableField(typeHandler = JacksonTypeHandler.class) 19 @TableField(typeHandler = JacksonTypeHandler.class)
20 private JsonNode deviceInfo; 20 private JsonNode deviceInfo;
21 private String profileId; 21 private String profileId;
  22 + private String deviceProfileId;
22 private String tbDeviceId; 23 private String tbDeviceId;
23 private String gatewayId; 24 private String gatewayId;
24 private String brand; 25 private String brand;
@@ -9,9 +9,9 @@ import lombok.EqualsAndHashCode; @@ -9,9 +9,9 @@ import lombok.EqualsAndHashCode;
9 import org.apache.ibatis.type.EnumTypeHandler; 9 import org.apache.ibatis.type.EnumTypeHandler;
10 import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; 10 import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
11 import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum; 11 import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum;
  12 +import org.thingsboard.server.common.data.yunteng.enums.CallTypeEnum;
12 import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum; 13 import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum;
13 import org.thingsboard.server.dao.yunteng.mapper.ListStringTypeHandler; 14 import org.thingsboard.server.dao.yunteng.mapper.ListStringTypeHandler;
14 -  
15 import java.util.List; 15 import java.util.List;
16 16
17 /** 17 /**
@@ -22,26 +22,26 @@ import java.util.List; @@ -22,26 +22,26 @@ import java.util.List;
22 @EqualsAndHashCode(callSuper = true) 22 @EqualsAndHashCode(callSuper = true)
23 public class TkDoActionEntity extends TenantBaseEntity { 23 public class TkDoActionEntity extends TenantBaseEntity {
24 24
25 - private static final long serialVersionUID = -5459834451418047957L;  
26 - 25 + private static final long serialVersionUID = -5459834451418047957L;
27 26
28 - @TableField(typeHandler = ListStringTypeHandler.class)  
29 - private List<String> deviceId; 27 + @TableField(typeHandler = ListStringTypeHandler.class)
  28 + private List<String> deviceId;
30 29
31 - @TableField(typeHandler = EnumTypeHandler.class)  
32 - private ScopeEnum entityType;  
33 - @TableField(typeHandler = EnumTypeHandler.class)  
34 - private ActionTypeEnum outTarget;  
35 - /**  
36 - * 场景联动内容  
37 - */  
38 - @TableField(typeHandler = JacksonTypeHandler.class)  
39 - private JsonNode doContext; 30 + @TableField(typeHandler = EnumTypeHandler.class)
  31 + private ScopeEnum entityType;
40 32
41 - /**  
42 - * 场景联动id  
43 - */  
44 - private String sceneLinkageId; 33 + @TableField(typeHandler = EnumTypeHandler.class)
  34 + private ActionTypeEnum outTarget;
45 35
46 - private String alarmProfileId; 36 + @TableField(typeHandler = EnumTypeHandler.class)
  37 + private CallTypeEnum callType;
  38 + private String deviceProfileId;
  39 + private Integer commandType;
  40 + private String thingsModelId;
  41 + /** 场景联动内容 */
  42 + @TableField(typeHandler = JacksonTypeHandler.class)
  43 + private JsonNode doContext;
  44 + /** 场景联动id */
  45 + private String sceneLinkageId;
  46 + private String alarmProfileId;
47 } 47 }
@@ -151,7 +151,7 @@ public class ThingsModelServiceImpl @@ -151,7 +151,7 @@ public class ThingsModelServiceImpl
151 @Override 151 @Override
152 public JsonNode getTingsModelTSL( 152 public JsonNode getTingsModelTSL(
153 FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId) { 153 FunctionTypeEnum typeEnum, String tenantId, String deviceProfileId) {
154 - JsonNode jsonNode; 154 + JsonNode jsonNode = JacksonUtil.newObjectNode();
155 DeviceProfileDTO deviceProfileDTO = 155 DeviceProfileDTO deviceProfileDTO =
156 ytDeviceProfileService.findDeviceProfileById(tenantId, deviceProfileId); 156 ytDeviceProfileService.findDeviceProfileById(tenantId, deviceProfileId);
157 if (null == deviceProfileDTO) { 157 if (null == deviceProfileDTO) {
@@ -159,32 +159,38 @@ public class ThingsModelServiceImpl @@ -159,32 +159,38 @@ public class ThingsModelServiceImpl
159 } 159 }
160 List<ThingsModelDTO> thingsModelDTOS = 160 List<ThingsModelDTO> thingsModelDTOS =
161 selectByDeviceProfileId(typeEnum, tenantId, deviceProfileId); 161 selectByDeviceProfileId(typeEnum, tenantId, deviceProfileId);
162 - 162 + if(null ==thingsModelDTOS){
  163 + return jsonNode;
  164 + }
163 DeviceTypeEnum deviceType = deviceProfileDTO.getDeviceType(); 165 DeviceTypeEnum deviceType = deviceProfileDTO.getDeviceType();
164 if (typeEnum.equals(FunctionTypeEnum.properties)) { 166 if (typeEnum.equals(FunctionTypeEnum.properties)) {
165 jsonNode = getAttributeTSL(thingsModelDTOS, deviceType); 167 jsonNode = getAttributeTSL(thingsModelDTOS, deviceType);
166 } else { 168 } else {
167 if (typeEnum.equals(FunctionTypeEnum.services)) { 169 if (typeEnum.equals(FunctionTypeEnum.services)) {
168 List<ServiceModelDTO> serviceList = new ArrayList<>(); 170 List<ServiceModelDTO> serviceList = new ArrayList<>();
169 - for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {  
170 - ServiceModelDTO serviceDTO = new ServiceModelDTO();  
171 - BeanUtils.copyProperties(thingsModelDTO, serviceDTO);  
172 - JsonNode functionJson = thingsModelDTO.getFunctionJson();  
173 - if (null != functionJson) {  
174 - serviceDTO.setInputData(functionJson.get("inputData"));  
175 - serviceDTO.setOutputData(functionJson.get("outputData")); 171 + if (!thingsModelDTOS.isEmpty()) {
  172 + for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {
  173 + ServiceModelDTO serviceDTO = new ServiceModelDTO();
  174 + BeanUtils.copyProperties(thingsModelDTO, serviceDTO);
  175 + JsonNode functionJson = thingsModelDTO.getFunctionJson();
  176 + if (null != functionJson) {
  177 + serviceDTO.setInputData(functionJson.get("inputData"));
  178 + serviceDTO.setOutputData(functionJson.get("outputData"));
  179 + }
  180 + serviceList.add(serviceDTO);
176 } 181 }
177 - serviceList.add(serviceDTO);  
178 } 182 }
179 jsonNode = JacksonUtil.convertValue(serviceList, JsonNode.class); 183 jsonNode = JacksonUtil.convertValue(serviceList, JsonNode.class);
180 } else { 184 } else {
181 List<EventModelDTO> eventList = new ArrayList<>(); 185 List<EventModelDTO> eventList = new ArrayList<>();
182 - for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {  
183 - EventModelDTO eventDTO = new EventModelDTO();  
184 - BeanUtils.copyProperties(thingsModelDTO, eventDTO);  
185 - JsonNode functionJson = thingsModelDTO.getFunctionJson();  
186 - if (null != functionJson) {  
187 - eventDTO.setOutputData(functionJson.get("outputData")); 186 + if (!thingsModelDTOS.isEmpty()) {
  187 + for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {
  188 + EventModelDTO eventDTO = new EventModelDTO();
  189 + BeanUtils.copyProperties(thingsModelDTO, eventDTO);
  190 + JsonNode functionJson = thingsModelDTO.getFunctionJson();
  191 + if (null != functionJson) {
  192 + eventDTO.setOutputData(functionJson.get("outputData"));
  193 + }
188 } 194 }
189 } 195 }
190 jsonNode = JacksonUtil.convertValue(eventList, JsonNode.class); 196 jsonNode = JacksonUtil.convertValue(eventList, JsonNode.class);
@@ -140,7 +140,7 @@ public class TkDeviceProfileServiceImpl @@ -140,7 +140,7 @@ public class TkDeviceProfileServiceImpl
140 // check if ids bind to device 140 // check if ids bind to device
141 int count = 141 int count =
142 deviceMapper.selectCount( 142 deviceMapper.selectCount(
143 - new QueryWrapper<TkDevice>().lambda().in(TkDevice::getProfileId, ids)); 143 + new QueryWrapper<TkDeviceEntity>().lambda().in(TkDeviceEntity::getProfileId, ids));
144 if (count > 0) { 144 if (count > 0) {
145 throw new YtDataValidationException("有设备使用待删除配置,请先删除设备或者修改设备配置"); 145 throw new YtDataValidationException("有设备使用待删除配置,请先删除设备或者修改设备配置");
146 } 146 }
@@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; @@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.constant.ModelConstants;
20 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; 20 import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException;
21 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; 21 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
22 import org.thingsboard.server.common.data.yunteng.dto.*; 22 import org.thingsboard.server.common.data.yunteng.dto.*;
  23 +import org.thingsboard.server.common.data.yunteng.enums.DataTypeEnum;
23 import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; 24 import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
24 import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum; 25 import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum;
25 import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum; 26 import org.thingsboard.server.common.data.yunteng.enums.ScopeEnum;
@@ -39,12 +40,12 @@ import java.util.stream.Collectors; @@ -39,12 +40,12 @@ import java.util.stream.Collectors;
39 @Service 40 @Service
40 @RequiredArgsConstructor 41 @RequiredArgsConstructor
41 @Slf4j 42 @Slf4j
42 -public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDevice> 43 +public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDeviceEntity>
43 implements TkDeviceService { 44 implements TkDeviceService {
44 45
45 private final DeviceProfileDao deviceProfileDao; 46 private final DeviceProfileDao deviceProfileDao;
46 47
47 - private final OrganizationMapper ytOrganizationMapper; 48 + private final OrganizationMapper tkOrganizationMapper;
48 private final SceneLinkageMapper sceneLinkageMapper; 49 private final SceneLinkageMapper sceneLinkageMapper;
49 private final TriggerMapper triggerMapper; 50 private final TriggerMapper triggerMapper;
50 private final DoConditionMapper conditionMapper; 51 private final DoConditionMapper conditionMapper;
@@ -66,7 +67,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -66,7 +67,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
66 67
67 validateUpdate(deviceDTO); 68 validateUpdate(deviceDTO);
68 69
69 - TkDevice device = new TkDevice(); 70 + TkDeviceEntity device = new TkDeviceEntity();
70 deviceDTO.copyToEntity( 71 deviceDTO.copyToEntity(
71 device, 72 device,
72 ModelConstants.TablePropertyMapping.ACTIVE_TIME, 73 ModelConstants.TablePropertyMapping.ACTIVE_TIME,
@@ -109,7 +110,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -109,7 +110,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
109 deviceDTO.setTenantId(currentTenantId); 110 deviceDTO.setTenantId(currentTenantId);
110 } else { 111 } else {
111 deviceTenantId = deviceDTO.getTenantId(); 112 deviceTenantId = deviceDTO.getTenantId();
112 - TkDevice device = baseMapper.selectById(deviceDTO.getId()); 113 + TkDeviceEntity device = baseMapper.selectById(deviceDTO.getId());
113 if (device == null) { 114 if (device == null) {
114 throw new YtDataValidationException("设备不存在!"); 115 throw new YtDataValidationException("设备不存在!");
115 } 116 }
@@ -126,7 +127,8 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -126,7 +127,8 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
126 TenantId id = TenantId.fromUUID(UUID.fromString(deviceTenantId)); 127 TenantId id = TenantId.fromUUID(UUID.fromString(deviceTenantId));
127 DeviceProfile deviceProfile = 128 DeviceProfile deviceProfile =
128 deviceProfileDao.findById(id, UUID.fromString(deviceDTO.getProfileId())); 129 deviceProfileDao.findById(id, UUID.fromString(deviceDTO.getProfileId()));
129 - TkOrganizationEntity organization = ytOrganizationMapper.selectById(deviceDTO.getOrganizationId()); 130 + TkOrganizationEntity organization =
  131 + tkOrganizationMapper.selectById(deviceDTO.getOrganizationId());
130 if (null == deviceProfile || null == organization) { 132 if (null == deviceProfile || null == organization) {
131 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); 133 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
132 } else if (!organization.getTenantId().equals(deviceTenantId)) { 134 } else if (!organization.getTenantId().equals(deviceTenantId)) {
@@ -209,7 +211,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -209,7 +211,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
209 211
210 private DeviceDTO insert(DeviceDTO deviceDTO) { 212 private DeviceDTO insert(DeviceDTO deviceDTO) {
211 213
212 - TkDevice device = new TkDevice(); 214 + TkDeviceEntity device = new TkDeviceEntity();
213 deviceDTO.copyToEntity( 215 deviceDTO.copyToEntity(
214 device, 216 device,
215 ModelConstants.TablePropertyMapping.ACTIVE_TIME, 217 ModelConstants.TablePropertyMapping.ACTIVE_TIME,
@@ -227,15 +229,15 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -227,15 +229,15 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
227 229
228 @Override 230 @Override
229 public List<String> findTbDeviceId(String tenantId, Set<String> ids) { 231 public List<String> findTbDeviceId(String tenantId, Set<String> ids) {
230 - LambdaQueryWrapper<TkDevice> queryWrapper =  
231 - new QueryWrapper<TkDevice>() 232 + LambdaQueryWrapper<TkDeviceEntity> queryWrapper =
  233 + new QueryWrapper<TkDeviceEntity>()
232 .lambda() 234 .lambda()
233 - .eq(TkDevice::getTenantId, tenantId)  
234 - .in(TkDevice::getId, ids); 235 + .eq(TkDeviceEntity::getTenantId, tenantId)
  236 + .in(TkDeviceEntity::getId, ids);
235 237
236 List<String> tbDeviceIds = 238 List<String> tbDeviceIds =
237 baseMapper.selectList(queryWrapper).stream() 239 baseMapper.selectList(queryWrapper).stream()
238 - .map(TkDevice::getTbDeviceId) 240 + .map(TkDeviceEntity::getTbDeviceId)
239 .collect(Collectors.toList()); 241 .collect(Collectors.toList());
240 for (String tbDeviceId : tbDeviceIds) { 242 for (String tbDeviceId : tbDeviceIds) {
241 sceneNotUsed(tenantId, tbDeviceId, null); 243 sceneNotUsed(tenantId, tbDeviceId, null);
@@ -252,10 +254,10 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -252,10 +254,10 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
252 } 254 }
253 return ReflectUtils.sourceToTarget( 255 return ReflectUtils.sourceToTarget(
254 baseMapper.selectList( 256 baseMapper.selectList(
255 - new LambdaQueryWrapper<TkDevice>()  
256 - .eq(deviceType != null, TkDevice::getDeviceType, deviceType)  
257 - .eq(deviceLabel != null, TkDevice::getLabel, deviceLabel)  
258 - .in(TkDevice::getOrganizationId, orgIds)), 257 + new LambdaQueryWrapper<TkDeviceEntity>()
  258 + .eq(deviceType != null, TkDeviceEntity::getDeviceType, deviceType)
  259 + .eq(deviceLabel != null, TkDeviceEntity::getLabel, deviceLabel)
  260 + .in(TkDeviceEntity::getOrganizationId, orgIds)),
259 DeviceDTO.class); 261 DeviceDTO.class);
260 } 262 }
261 263
@@ -279,12 +281,12 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -279,12 +281,12 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
279 if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(tenantId)) { 281 if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(tenantId)) {
280 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); 282 throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
281 } 283 }
282 - TkDevice device = 284 + TkDeviceEntity device =
283 baseMapper.selectOne( 285 baseMapper.selectOne(
284 - new LambdaQueryWrapper<TkDevice>()  
285 - .eq(TkDevice::getTenantId, tenantId)  
286 - .eq(isTbDeviceId, TkDevice::getTbDeviceId, deviceId)  
287 - .eq(!isTbDeviceId, TkDevice::getId, deviceId)); 286 + new LambdaQueryWrapper<TkDeviceEntity>()
  287 + .eq(TkDeviceEntity::getTenantId, tenantId)
  288 + .eq(isTbDeviceId, TkDeviceEntity::getTbDeviceId, deviceId)
  289 + .eq(!isTbDeviceId, TkDeviceEntity::getId, deviceId));
288 DeviceDTO deviceDTO = null != device ? device.getDTO(DeviceDTO.class) : null; 290 DeviceDTO deviceDTO = null != device ? device.getDTO(DeviceDTO.class) : null;
289 if (null == deviceDTO) { 291 if (null == deviceDTO) {
290 throw new YtDataValidationException(ErrorMessage.DEVICE_NOT_EXISTENCE_IN_TENANT.getMessage()); 292 throw new YtDataValidationException(ErrorMessage.DEVICE_NOT_EXISTENCE_IN_TENANT.getMessage());
@@ -295,11 +297,11 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -295,11 +297,11 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
295 @Override 297 @Override
296 @Transactional 298 @Transactional
297 public void deleteDevices(String tenantId, Set<String> ids) { 299 public void deleteDevices(String tenantId, Set<String> ids) {
298 - LambdaQueryWrapper<TkDevice> queryWrapper =  
299 - new QueryWrapper<TkDevice>() 300 + LambdaQueryWrapper<TkDeviceEntity> queryWrapper =
  301 + new QueryWrapper<TkDeviceEntity>()
300 .lambda() 302 .lambda()
301 - .eq(TkDevice::getTenantId, tenantId)  
302 - .in(TkDevice::getId, ids); 303 + .eq(TkDeviceEntity::getTenantId, tenantId)
  304 + .in(TkDeviceEntity::getId, ids);
303 305
304 baseMapper.delete(queryWrapper); 306 baseMapper.delete(queryWrapper);
305 } 307 }
@@ -317,7 +319,8 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -317,7 +319,8 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
317 List<String> queryOrganizationIds = organizationAllIds(tenantId, organizationId); 319 List<String> queryOrganizationIds = organizationAllIds(tenantId, organizationId);
318 queryMap.put("organizationIds", queryOrganizationIds); 320 queryMap.put("organizationIds", queryOrganizationIds);
319 } 321 }
320 - IPage<TkDevice> page = getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false); 322 + IPage<TkDeviceEntity> page =
  323 + getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false);
321 IPage<DeviceDTO> deviceIPage = baseMapper.getDevicePage(page, queryMap); 324 IPage<DeviceDTO> deviceIPage = baseMapper.getDevicePage(page, queryMap);
322 List<DeviceDTO> records = deviceIPage.getRecords(); 325 List<DeviceDTO> records = deviceIPage.getRecords();
323 records.forEach( 326 records.forEach(
@@ -344,7 +347,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -344,7 +347,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
344 } 347 }
345 // 查询该组织的所有子类 348 // 查询该组织的所有子类
346 List<OrganizationDTO> organizationDTOS = 349 List<OrganizationDTO> organizationDTOS =
347 - ytOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds); 350 + tkOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds);
348 List<String> queryOrganizationIds = new ArrayList<>(); 351 List<String> queryOrganizationIds = new ArrayList<>();
349 organizationDTOS.forEach(item -> queryOrganizationIds.add(item.getId())); 352 organizationDTOS.forEach(item -> queryOrganizationIds.add(item.getId()));
350 return queryOrganizationIds; 353 return queryOrganizationIds;
@@ -352,7 +355,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -352,7 +355,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
352 355
353 @Override 356 @Override
354 public YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap) { 357 public YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap) {
355 - IPage<TkDevice> page = getPage(queryMap, "last_online_time", false); 358 + IPage<TkDeviceEntity> page = getPage(queryMap, "last_online_time", false);
356 IPage<RelationDeviceDTO> deviceIPage = baseMapper.getRelationDevicePage(page, queryMap); 359 IPage<RelationDeviceDTO> deviceIPage = baseMapper.getRelationDevicePage(page, queryMap);
357 List<RelationDeviceDTO> records = deviceIPage.getRecords(); 360 List<RelationDeviceDTO> records = deviceIPage.getRecords();
358 return new YtPageData<>(records, deviceIPage.getTotal()); 361 return new YtPageData<>(records, deviceIPage.getTotal());
@@ -360,13 +363,13 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -360,13 +363,13 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
360 363
361 @Override 364 @Override
362 public boolean deviceNameUsed(String tenantId, String deviceName, String deviceId) { 365 public boolean deviceNameUsed(String tenantId, String deviceName, String deviceId) {
363 - List<TkDevice> deviceList = 366 + List<TkDeviceEntity> deviceList =
364 baseMapper.selectList( 367 baseMapper.selectList(
365 - new QueryWrapper<TkDevice>() 368 + new QueryWrapper<TkDeviceEntity>()
366 .lambda() 369 .lambda()
367 - .eq(true, TkDevice::getTenantId, tenantId)  
368 - .eq(TkDevice::getName, deviceName));  
369 - for (TkDevice dev : deviceList) { 370 + .eq(true, TkDeviceEntity::getTenantId, tenantId)
  371 + .eq(TkDeviceEntity::getName, deviceName));
  372 + for (TkDeviceEntity dev : deviceList) {
370 if (deviceName.equals(dev.getName()) 373 if (deviceName.equals(dev.getName())
371 && (StringUtils.isEmpty(deviceId) || !deviceId.equals(dev.getId()))) { 374 && (StringUtils.isEmpty(deviceId) || !deviceId.equals(dev.getId()))) {
372 return true; 375 return true;
@@ -399,7 +402,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -399,7 +402,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
399 402
400 @Override 403 @Override
401 public String otherUsing(String deviceId, String tenantId) { 404 public String otherUsing(String deviceId, String tenantId) {
402 - TkDevice device = baseMapper.selectById(deviceId); 405 + TkDeviceEntity device = baseMapper.selectById(deviceId);
403 if (device == null) { 406 if (device == null) {
404 throw new YtDataValidationException(ErrorMessage.DEVICE_NOT_EXTIED.getMessage()); 407 throw new YtDataValidationException(ErrorMessage.DEVICE_NOT_EXTIED.getMessage());
405 } 408 }
@@ -411,7 +414,9 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -411,7 +414,9 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
411 @Nullable 414 @Nullable
412 private String usedBySceneLinkage(String tenantId, String tbDeviceId) { 415 private String usedBySceneLinkage(String tenantId, String tbDeviceId) {
413 LambdaQueryWrapper<TkSceneLinkageEntity> sceneFilter = 416 LambdaQueryWrapper<TkSceneLinkageEntity> sceneFilter =
414 - new QueryWrapper<TkSceneLinkageEntity>().lambda().eq(TkSceneLinkageEntity::getTenantId, tenantId) 417 + new QueryWrapper<TkSceneLinkageEntity>()
  418 + .lambda()
  419 + .eq(TkSceneLinkageEntity::getTenantId, tenantId)
415 // .eq(SceneLinkage::getStatus, 1) 420 // .eq(SceneLinkage::getStatus, 1)
416 ; 421 ;
417 Optional<List<TkSceneLinkageEntity>> scenes = 422 Optional<List<TkSceneLinkageEntity>> scenes =
@@ -460,9 +465,9 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -460,9 +465,9 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
460 465
461 @Override 466 @Override
462 public List<SelectItemDTO> findMasterDevices( 467 public List<SelectItemDTO> findMasterDevices(
463 - String tenantId, String customerId, String organizationId) { 468 + String tenantId, String customerId, String organizationId, String deviceProfileId) {
464 List<String> orgIds = organizationAllIds(tenantId, organizationId); 469 List<String> orgIds = organizationAllIds(tenantId, organizationId);
465 - return baseMapper.masterDevices(customerId, tenantId, orgIds); 470 + return baseMapper.masterDevices(customerId, tenantId, orgIds, deviceProfileId);
466 } 471 }
467 472
468 @Override 473 @Override
@@ -487,10 +492,10 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -487,10 +492,10 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
487 @Override 492 @Override
488 public boolean saveSlaveDevice( 493 public boolean saveSlaveDevice(
489 String slaveId, String slaveName, String gatewayId, Long createTime) { 494 String slaveId, String slaveName, String gatewayId, Long createTime) {
490 - LambdaQueryWrapper<TkDevice> deviceFilter =  
491 - new QueryWrapper<TkDevice>().lambda().eq(TkDevice::getTbDeviceId, gatewayId);  
492 - TkDevice gateway = baseMapper.selectOne(deviceFilter);  
493 - TkDevice slaveDevice = new TkDevice(); 495 + LambdaQueryWrapper<TkDeviceEntity> deviceFilter =
  496 + new QueryWrapper<TkDeviceEntity>().lambda().eq(TkDeviceEntity::getTbDeviceId, gatewayId);
  497 + TkDeviceEntity gateway = baseMapper.selectOne(deviceFilter);
  498 + TkDeviceEntity slaveDevice = new TkDeviceEntity();
494 slaveDevice.setName(slaveName); 499 slaveDevice.setName(slaveName);
495 slaveDevice.setTbDeviceId(slaveId); 500 slaveDevice.setTbDeviceId(slaveId);
496 slaveDevice.setSn(generateSn()); 501 slaveDevice.setSn(generateSn());
@@ -517,11 +522,11 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -517,11 +522,11 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
517 522
518 @Override 523 @Override
519 public DeviceDTO getSubsetDeviceByTbDeviceId(String tenantId, String tbDeviceId) { 524 public DeviceDTO getSubsetDeviceByTbDeviceId(String tenantId, String tbDeviceId) {
520 - TkDevice device = 525 + TkDeviceEntity device =
521 baseMapper.selectOne( 526 baseMapper.selectOne(
522 - new LambdaQueryWrapper<TkDevice>()  
523 - .eq(TkDevice::getTbDeviceId, tbDeviceId)  
524 - .eq(TkDevice::getTenantId, tenantId)); 527 + new LambdaQueryWrapper<TkDeviceEntity>()
  528 + .eq(TkDeviceEntity::getTbDeviceId, tbDeviceId)
  529 + .eq(TkDeviceEntity::getTenantId, tenantId));
525 return Optional.ofNullable(device) 530 return Optional.ofNullable(device)
526 .map(obj -> obj.getDTO(DeviceDTO.class)) 531 .map(obj -> obj.getDTO(DeviceDTO.class))
527 .orElseThrow( 532 .orElseThrow(
@@ -531,30 +536,37 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -531,30 +536,37 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
531 } 536 }
532 537
533 @Override 538 @Override
534 - public JsonNode getDeviceAttributes(String tbProfileId,String profileId, String id, String tenantId) { 539 + public JsonNode getDeviceAttributes(
  540 + String deviceProfileId, String id, String tenantId, DataTypeEnum dataType) {
535 return getDevice(tenantId, id) 541 return getDevice(tenantId, id)
536 .map( 542 .map(
537 obj -> { 543 obj -> {
538 - if (obj.getProfileId().equals(tbProfileId)) {  
539 - JsonNode jsonNode = JacksonUtil.newObjectNode();  
540 - List<ThingsModelDTO> thingsModel =  
541 - thingsModelService.selectByDeviceProfileId(  
542 - FunctionTypeEnum.properties, tenantId, profileId);  
543 - if (null !=thingsModel && !thingsModel.isEmpty()) {  
544 - List<Map<String, Object>> attributes = new ArrayList<>();  
545 - for (ThingsModelDTO dto : thingsModel) {  
546 - Map<String, Object> attribute = new HashMap<>();  
547 - attribute.put("name", dto.getFunctionName());  
548 - attribute.put("identifier", dto.getIdentifier());  
549 - attribute.put("detail", dto.getFunctionJson());  
550 - attributes.add(attribute); 544 + JsonNode jsonNode = JacksonUtil.newObjectNode();
  545 + List<ThingsModelDTO> thingsModel =
  546 + thingsModelService.selectByDeviceProfileId(
  547 + FunctionTypeEnum.properties, tenantId, deviceProfileId);
  548 + if (null != thingsModel && !thingsModel.isEmpty()) {
  549 + List<Map<String, Object>> attributes = new ArrayList<>();
  550 + for (ThingsModelDTO dto : thingsModel) {
  551 + JsonNode functionJson = dto.getFunctionJson();
  552 + String dataTypeKey = "dataType";
  553 + if (null != functionJson
  554 + && null != functionJson.get(dataTypeKey)
  555 + && null != functionJson.get(dataTypeKey).get("type")) {
  556 + DataTypeEnum queryDataType =
  557 + DataTypeEnum.valueOf(functionJson.get(dataTypeKey).get("type").asText());
  558 + if (null == dataType || queryDataType.equals(dataType)) {
  559 + Map<String, Object> attribute = new HashMap<>();
  560 + attribute.put("name", dto.getFunctionName());
  561 + attribute.put("identifier", dto.getIdentifier());
  562 + attribute.put("detail", functionJson);
  563 + attributes.add(attribute);
  564 + }
551 } 565 }
552 - jsonNode = JacksonUtil.convertValue(attributes, JsonNode.class);  
553 } 566 }
554 - return jsonNode;  
555 - } else {  
556 - throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); 567 + jsonNode = JacksonUtil.convertValue(attributes, JsonNode.class);
557 } 568 }
  569 + return jsonNode;
558 }) 570 })
559 .orElseThrow( 571 .orElseThrow(
560 () -> { 572 () -> {
@@ -48,10 +48,10 @@ public class TkNoticeServiceImpl implements TkNoticeService { @@ -48,10 +48,10 @@ public class TkNoticeServiceImpl implements TkNoticeService {
48 * 2、查找告警配置 ,与设备配置一一对应。 48 * 2、查找告警配置 ,与设备配置一一对应。
49 * 3、查找告警通知联系人 49 * 3、查找告警通知联系人
50 */ 50 */
51 - QueryWrapper<TkDevice> queryWrapper = new QueryWrapper<TkDevice>(); 51 + QueryWrapper<TkDeviceEntity> queryWrapper = new QueryWrapper<TkDeviceEntity>();
52 queryWrapper.lambda() 52 queryWrapper.lambda()
53 - .eq(TkDevice::getTbDeviceId, alarmInfo.getDeviceId());  
54 - TkDevice device = deviceMapper.selectOne(queryWrapper); 53 + .eq(TkDeviceEntity::getTbDeviceId, alarmInfo.getDeviceId());
  54 + TkDeviceEntity device = deviceMapper.selectOne(queryWrapper);
55 55
56 56
57 if (device == null) { 57 if (device == null) {
@@ -128,12 +128,12 @@ public class TkOrganizationServiceImpl extends AbstractBaseService<OrganizationM @@ -128,12 +128,12 @@ public class TkOrganizationServiceImpl extends AbstractBaseService<OrganizationM
128 128
129 // 查询是否有设备使用该组织 129 // 查询是否有设备使用该组织
130 for (String id : ids) { 130 for (String id : ids) {
131 - List<TkDevice> deviceList = 131 + List<TkDeviceEntity> deviceList =
132 deviceMapper.selectList( 132 deviceMapper.selectList(
133 - new QueryWrapper<TkDevice>() 133 + new QueryWrapper<TkDeviceEntity>()
134 .lambda() 134 .lambda()
135 - .eq(TkDevice::getTenantId, tenantId)  
136 - .eq(TkDevice::getOrganizationId, id)); 135 + .eq(TkDeviceEntity::getTenantId, tenantId)
  136 + .eq(TkDeviceEntity::getOrganizationId, id));
137 if (!deviceList.isEmpty()) { 137 if (!deviceList.isEmpty()) {
138 throw new YtDataValidationException("待删除数据存在关联设备,不能删除!"); 138 throw new YtDataValidationException("待删除数据存在关联设备,不能删除!");
139 } 139 }
@@ -403,9 +403,9 @@ public class TkSceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageM @@ -403,9 +403,9 @@ public class TkSceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageM
403 } 403 }
404 } 404 }
405 405
406 - List<TkDevice> orgDevices = 406 + List<TkDeviceEntity> orgDevices =
407 deviceMapper.selectList( 407 deviceMapper.selectList(
408 - new QueryWrapper<TkDevice>().lambda().in(TkDevice::getOrganizationId, orgIds)); 408 + new QueryWrapper<TkDeviceEntity>().lambda().in(TkDeviceEntity::getOrganizationId, orgIds));
409 List<DeviceDTO> result = 409 List<DeviceDTO> result =
410 orgDevices.stream() 410 orgDevices.stream()
411 .filter(t -> typeFilter.isEmpty() || typeFilter.contains(t.getDeviceType())) 411 .filter(t -> typeFilter.isEmpty() || typeFilter.contains(t.getDeviceType()))
@@ -8,124 +8,135 @@ import org.thingsboard.server.common.data.yunteng.dto.BaseHomePageTop; @@ -8,124 +8,135 @@ import org.thingsboard.server.common.data.yunteng.dto.BaseHomePageTop;
8 import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; 8 import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
9 import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; 9 import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO;
10 import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; 10 import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO;
11 -import org.thingsboard.server.dao.yunteng.entities.TkDevice; 11 +import org.thingsboard.server.dao.yunteng.entities.TkDeviceEntity;
12 12
13 import java.util.List; 13 import java.util.List;
14 import java.util.Map; 14 import java.util.Map;
15 15
16 @Mapper 16 @Mapper
17 -public interface DeviceMapper extends BaseMapper<TkDevice> {  
18 -  
19 - IPage<DeviceDTO> getDevicePage(IPage<?> page, @Param("queryMap") Map<String, Object> queryMap);  
20 -  
21 - DeviceDTO selectDetail(@Param("tenantId") String tenantId, @Param("id") String id);  
22 -  
23 - /**  
24 - * 通过网关子设备的TB设备ID查询网关设备信息  
25 - *  
26 - * @param tbDeviceId 网关子设备的TB设备ID  
27 - * @return 网关设备信息  
28 - */  
29 - List<DeviceDTO> findGateWayDeviceByTbDeviceId(@Param("tbDeviceId") String tbDeviceId);  
30 -  
31 - /**  
32 - * 更新设备告警状态  
33 - *  
34 - * @param tbDeviceId TB设备主键  
35 - * @param created 告警状态:0正常,1告警  
36 - * @return true or false  
37 - */  
38 - boolean freshAlarmStatus(  
39 - @Param("tbDeviceId") String tbDeviceId, @Param("created") Integer created);  
40 -  
41 - /**  
42 - * 用于统计设备相关信息  
43 - *  
44 - * @param queryMap 查询条件  
45 - * @return 查询的设备信息  
46 - */  
47 - List<DeviceDTO> findDevices(@Param("queryMap") Map<String, Object> queryMap);  
48 -  
49 - /**  
50 - * 获取关联设备的子设备分页列表  
51 - *  
52 - * @param page 分页  
53 - * @param queryMap 查询条件  
54 - * @return 分页数据  
55 - */  
56 - IPage<RelationDeviceDTO> getRelationDevicePage(  
57 - IPage<?> page, @Param("queryMap") Map<String, Object> queryMap);  
58 -  
59 - /**  
60 - * 通过用户ID查询分配的所有设备ID  
61 - *  
62 - * @param customerId 用户ID  
63 - * @return 所有的设备ids  
64 - */  
65 - List<String> findDeviceIdsByCustomerId(@Param("customerId") String customerId);  
66 -  
67 - List<BaseHomePageTop> findDeviceMessageInfo(  
68 - @Param("todayTime") Long todayTime, @Param("customerId") String customerId);  
69 -  
70 - List<BaseHomePageTop> findDeviceAlarmInfoByCustomer(  
71 - @Param("todayTime") Long todayTime, @Param("customerId") String customerId);  
72 -  
73 - Integer findDeviceMessageInfoByTs(  
74 - @Param("customerId") String customerId,  
75 - @Param("startTime") Long startTime,  
76 - @Param("endTime") Long endTime);  
77 -  
78 - Integer findDeviceAlarmInfoByCreatedTime(  
79 - @Param("customerId") String customerId,  
80 - @Param("startTime") Long startTime,  
81 - @Param("endTime") Long endTime);  
82 -  
83 -  
84 - Integer countMsgs(@Param("queryMap") Map<String, Object> queryMap);  
85 -  
86 - Integer countDataPoints(@Param("queryMap") Map<String, Object> queryMap);  
87 -  
88 - /**  
89 - * 主设备列表  
90 - *  
91 - * @param customerId 客户ID  
92 - * @param tenantId 租户ID  
93 - * @param organizationIds 组织ID  
94 - * @return  
95 - */  
96 - List<SelectItemDTO> masterDevices(@Param("customerId") String customerId, @Param("tenantId") String tenantId, @Param("organizationIds") List<String> organizationIds);  
97 -  
98 - /**  
99 - * 从设备列表  
100 - *  
101 - * @param customerId 客户ID  
102 - * @param tenantId 租户ID  
103 - * @param organizationIds 组织ID  
104 - * @param masterId 主设备ID  
105 - * @return  
106 - */  
107 - List<SelectItemDTO> slaveDevices(@Param("customerId") String customerId, @Param("tenantId") String tenantId  
108 - , @Param("organizationIds") List<String> organizationIds, @Param("masterId") String masterId);  
109 -  
110 - /**  
111 - * TCP协议传输时,获取网关设备的从设备  
112 - * @param tenantId 租户ID  
113 - * @param masterId 网关设备的TB_ID  
114 - * @param code 网关子设备的标识符,例如:485协议的从设备地址码  
115 - * @return  
116 - */  
117 - DeviceDTO slaveDevice(@Param("tenantId") String tenantId, @Param("masterId") String masterId, @Param("code") String code);  
118 - /**  
119 - * 设备遥测数据指标名称  
120 - *  
121 - * @param tenantId 租户ID  
122 - * @param customerId 客户ID  
123 - * @param organizationIds 组织ID  
124 - * @param deviceIds 设备ID  
125 - * @return  
126 - */  
127 - List<String> findDeviceKeys(@Param("tenantId") String tenantId  
128 - , @Param("customerId") String customerId  
129 - , @Param("organizationIds") List<String> organizationIds  
130 - , @Param("deviceIds") List<String> deviceIds); 17 +public interface DeviceMapper extends BaseMapper<TkDeviceEntity> {
  18 +
  19 + IPage<DeviceDTO> getDevicePage(IPage<?> page, @Param("queryMap") Map<String, Object> queryMap);
  20 +
  21 + DeviceDTO selectDetail(@Param("tenantId") String tenantId, @Param("id") String id);
  22 +
  23 + /**
  24 + * 通过网关子设备的TB设备ID查询网关设备信息
  25 + *
  26 + * @param tbDeviceId 网关子设备的TB设备ID
  27 + * @return 网关设备信息
  28 + */
  29 + List<DeviceDTO> findGateWayDeviceByTbDeviceId(@Param("tbDeviceId") String tbDeviceId);
  30 +
  31 + /**
  32 + * 更新设备告警状态
  33 + *
  34 + * @param tbDeviceId TB设备主键
  35 + * @param created 告警状态:0正常,1告警
  36 + * @return true or false
  37 + */
  38 + boolean freshAlarmStatus(
  39 + @Param("tbDeviceId") String tbDeviceId, @Param("created") Integer created);
  40 +
  41 + /**
  42 + * 用于统计设备相关信息
  43 + *
  44 + * @param queryMap 查询条件
  45 + * @return 查询的设备信息
  46 + */
  47 + List<DeviceDTO> findDevices(@Param("queryMap") Map<String, Object> queryMap);
  48 +
  49 + /**
  50 + * 获取关联设备的子设备分页列表
  51 + *
  52 + * @param page 分页
  53 + * @param queryMap 查询条件
  54 + * @return 分页数据
  55 + */
  56 + IPage<RelationDeviceDTO> getRelationDevicePage(
  57 + IPage<?> page, @Param("queryMap") Map<String, Object> queryMap);
  58 +
  59 + /**
  60 + * 通过用户ID查询分配的所有设备ID
  61 + *
  62 + * @param customerId 用户ID
  63 + * @return 所有的设备ids
  64 + */
  65 + List<String> findDeviceIdsByCustomerId(@Param("customerId") String customerId);
  66 +
  67 + List<BaseHomePageTop> findDeviceMessageInfo(
  68 + @Param("todayTime") Long todayTime, @Param("customerId") String customerId);
  69 +
  70 + List<BaseHomePageTop> findDeviceAlarmInfoByCustomer(
  71 + @Param("todayTime") Long todayTime, @Param("customerId") String customerId);
  72 +
  73 + Integer findDeviceMessageInfoByTs(
  74 + @Param("customerId") String customerId,
  75 + @Param("startTime") Long startTime,
  76 + @Param("endTime") Long endTime);
  77 +
  78 + Integer findDeviceAlarmInfoByCreatedTime(
  79 + @Param("customerId") String customerId,
  80 + @Param("startTime") Long startTime,
  81 + @Param("endTime") Long endTime);
  82 +
  83 + Integer countMsgs(@Param("queryMap") Map<String, Object> queryMap);
  84 +
  85 + Integer countDataPoints(@Param("queryMap") Map<String, Object> queryMap);
  86 +
  87 + /**
  88 + * 主设备列表
  89 + *
  90 + * @param customerId 客户ID
  91 + * @param tenantId 租户ID
  92 + * @param organizationIds 组织ID
  93 + * @return
  94 + */
  95 + List<SelectItemDTO> masterDevices(
  96 + @Param("customerId") String customerId,
  97 + @Param("tenantId") String tenantId,
  98 + @Param("organizationIds") List<String> organizationIds,
  99 + @Param("deviceProfileId") String deviceProfileId);
  100 +
  101 + /**
  102 + * 从设备列表
  103 + *
  104 + * @param customerId 客户ID
  105 + * @param tenantId 租户ID
  106 + * @param organizationIds 组织ID
  107 + * @param masterId 主设备ID
  108 + * @return
  109 + */
  110 + List<SelectItemDTO> slaveDevices(
  111 + @Param("customerId") String customerId,
  112 + @Param("tenantId") String tenantId,
  113 + @Param("organizationIds") List<String> organizationIds,
  114 + @Param("masterId") String masterId);
  115 +
  116 + /**
  117 + * TCP协议传输时,获取网关设备的从设备
  118 + *
  119 + * @param tenantId 租户ID
  120 + * @param masterId 网关设备的TB_ID
  121 + * @param code 网关子设备的标识符,例如:485协议的从设备地址码
  122 + * @return
  123 + */
  124 + DeviceDTO slaveDevice(
  125 + @Param("tenantId") String tenantId,
  126 + @Param("masterId") String masterId,
  127 + @Param("code") String code);
  128 + /**
  129 + * 设备遥测数据指标名称
  130 + *
  131 + * @param tenantId 租户ID
  132 + * @param customerId 客户ID
  133 + * @param organizationIds 组织ID
  134 + * @param deviceIds 设备ID
  135 + * @return
  136 + */
  137 + List<String> findDeviceKeys(
  138 + @Param("tenantId") String tenantId,
  139 + @Param("customerId") String customerId,
  140 + @Param("organizationIds") List<String> organizationIds,
  141 + @Param("deviceIds") List<String> deviceIds);
131 } 142 }
@@ -5,178 +5,186 @@ import org.thingsboard.server.common.data.id.EntityId; @@ -5,178 +5,186 @@ import org.thingsboard.server.common.data.id.EntityId;
5 import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; 5 import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
6 import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; 6 import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO;
7 import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; 7 import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO;
  8 +import org.thingsboard.server.common.data.yunteng.enums.DataTypeEnum;
8 import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; 9 import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
9 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; 10 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
10 -import org.thingsboard.server.dao.yunteng.entities.TkDevice; 11 +import org.thingsboard.server.dao.yunteng.entities.TkDeviceEntity;
11 12
12 import java.util.List; 13 import java.util.List;
13 import java.util.Map; 14 import java.util.Map;
14 import java.util.Optional; 15 import java.util.Optional;
15 import java.util.Set; 16 import java.util.Set;
16 17
17 -public interface TkDeviceService extends BaseService<TkDevice> {  
18 - DeviceDTO insertOrUpdate(String tenantId, DeviceDTO deviceDTO);  
19 -  
20 - void deleteDevices(String tenantId, Set<String> ids);  
21 -  
22 - Optional<DeviceDTO> getDevice(String tenantId, String id);  
23 -  
24 - YtPageData<DeviceDTO> page(String tenantId, Map<String, Object> queryMap);  
25 -  
26 - YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap);  
27 -  
28 - /**  
29 - * 验证表单数据有效性  
30 - *  
31 - * @param ytDevice  
32 - */  
33 - void validateFormData(String currentTenantId, DeviceDTO ytDevice);  
34 -  
35 - /**  
36 - * 查询所有的设备信息  
37 - *  
38 - * @param deviceDTO 过滤参数  
39 - * @return List<DeviceDTO>  
40 - */  
41 - boolean deviceNameUsed(String tenantId, String deviceName,String deviceId);  
42 -  
43 - List<String> findTbDeviceId(String tenantId, Set<String> ids);  
44 -  
45 - /**  
46 - * 通过设备类型和组织ID查询所有的设备  
47 - *  
48 - * @param deviceType 设备类型  
49 - * @param organizationId 组织ID  
50 - * @return 设备列表  
51 - */  
52 - List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(  
53 - DeviceTypeEnum deviceType, String tenantId, String organizationId,String deviceLabel);  
54 -  
55 - /**  
56 - * 通过设备ID和租户ID判断该设备是否存在  
57 - *  
58 - * @param tenantId 租户ID  
59 - * @param deviceId 设备ID  
60 - * @return 设备  
61 - */  
62 - DeviceDTO checkDeviceByTenantIdAndDeviceId(String tenantId, String deviceId);  
63 -  
64 - /**  
65 - * 通过网关子设备的TB设备ID查询网关设备信息  
66 - *  
67 - * @param tbDeviceId 网关子设备的TB设备ID  
68 - * @param tenantId 租户ID  
69 - * @return 网关设备信息  
70 - */  
71 - List<DeviceDTO> findGateWayDeviceByTbDeviceId(String tenantId, String tbDeviceId);  
72 -  
73 - /**  
74 - * 通过设备ID和租户ID检查设备是否存在  
75 - *  
76 - * @param tenantId 租户ID  
77 - * @param deviceId 设备ID  
78 - * @param isTbDeviceId 是TB设备ID  
79 - * @return 设备信息  
80 - */  
81 - DeviceDTO checkDeviceByTenantIdAndId(String tenantId, String deviceId, boolean isTbDeviceId);  
82 -  
83 - /**  
84 - * 更新设备告警状态  
85 - *  
86 - * @param tbDeviceId TB设备主键  
87 - * @param created 告警状态:0正常,1告警  
88 - * @return  
89 - */  
90 - boolean freshAlarmStatus(EntityId tbDeviceId, Integer created);  
91 -  
92 -  
93 - /**  
94 - * 自动生成设备SN  
95 - *  
96 - * @return  
97 - */  
98 - String generateSn();  
99 -  
100 - /**  
101 - *  
102 - * 设备是否被其它资源使用,例如:场景联动  
103 - * @param deviceId 平台设备ID  
104 - * @param tenantId 租户ID  
105 - * @return  
106 - */  
107 - String otherUsing(String deviceId,String tenantId);  
108 -  
109 - /**  
110 - * 主设备信息  
111 - * @param tenantId 租户ID  
112 - * @param organizationId 组织ID  
113 - * @return 设备列表  
114 - */  
115 - List<SelectItemDTO> findMasterDevices(String tenantId, String customerId, String organizationId);  
116 -  
117 - /**  
118 - * 从设备信息  
119 - * @param masterId 主设备ID  
120 - * @param tenantId 租户ID  
121 - * @param organizationId 组织ID  
122 - * @return 设备列表  
123 - */  
124 - List<SelectItemDTO> findSlaveDevices(String masterId,String tenantId,String customerId, String organizationId);  
125 -  
126 -  
127 - /**  
128 - * TCP协议传输时,获取网关设备的从设备  
129 - * @param tenantId 租户ID  
130 - * @param masterId 网关设备的TB_ID  
131 - * @param deviceCode 网关子设备的标识符,例如:485协议的从设备地址码  
132 - * @return  
133 - */  
134 - DeviceDTO findSlaveDevice(String tenantId,String masterId,String deviceCode);  
135 -  
136 - /**  
137 - * 设备遥测数据指标名称  
138 - * @param tenantId 租户ID  
139 - * @param customerId 客户ID  
140 - * @param organizationId 组织ID  
141 - * @param deviceIds 设备ID  
142 - * @return  
143 - */  
144 - List<String> findDeviceKeys(String tenantId,String customerId, String organizationId,List<String> deviceIds);  
145 -  
146 -  
147 - /**  
148 - * Thingsboard自动创建的传感器设备(网关子设备)同步到平台  
149 - * @param slaveId 网关子设备TB平台的ID  
150 - * @param slaveName 网关子设备TB平台的名称  
151 - * @param gatewayId 网关设备TB平台的ID  
152 - * @return  
153 - */  
154 - boolean saveSlaveDevice(String slaveId, String slaveName, String gatewayId, Long createTime);  
155 -  
156 - /**  
157 - * 通过设备ids查询拥有数值型属性的设备  
158 - * @param tenantId 租户ID  
159 - * @param ids  
160 - * @return 数值型设备列表  
161 - */  
162 - List<DeviceDTO> findNumberAttributeDevicesByIds(String tenantId,List<String> ids);  
163 -  
164 - /**  
165 - * 通过tb设备ID获取平台设备信息  
166 - * @param tenantId 租户ID  
167 - * @param tbDeviceId tb设备ID  
168 - * @return 设备信息  
169 - */  
170 - DeviceDTO getSubsetDeviceByTbDeviceId(String tenantId,String tbDeviceId);  
171 -  
172 - /**  
173 - * 通过设备ID 设备配置ID获取属性  
174 - * @param tbProfileId tb设备配置ID  
175 - * @param profileId 设备配置ID  
176 - * @param id 设备ID  
177 - * @param tenantId 租户ID  
178 - * @return 属性信息  
179 - */  
180 - JsonNode getDeviceAttributes(String tbProfileId,String profileId,String id,String tenantId);  
181 - 18 +public interface TkDeviceService extends BaseService<TkDeviceEntity> {
  19 + DeviceDTO insertOrUpdate(String tenantId, DeviceDTO deviceDTO);
  20 +
  21 + void deleteDevices(String tenantId, Set<String> ids);
  22 +
  23 + Optional<DeviceDTO> getDevice(String tenantId, String id);
  24 +
  25 + YtPageData<DeviceDTO> page(String tenantId, Map<String, Object> queryMap);
  26 +
  27 + YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap);
  28 +
  29 + /**
  30 + * 验证表单数据有效性
  31 + *
  32 + * @param ytDevice
  33 + */
  34 + void validateFormData(String currentTenantId, DeviceDTO ytDevice);
  35 +
  36 + /**
  37 + * 查询所有的设备信息
  38 + *
  39 + * @param deviceDTO 过滤参数
  40 + * @return List<DeviceDTO>
  41 + */
  42 + boolean deviceNameUsed(String tenantId, String deviceName, String deviceId);
  43 +
  44 + List<String> findTbDeviceId(String tenantId, Set<String> ids);
  45 +
  46 + /**
  47 + * 通过设备类型和组织ID查询所有的设备
  48 + *
  49 + * @param deviceType 设备类型
  50 + * @param organizationId 组织ID
  51 + * @return 设备列表
  52 + */
  53 + List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(
  54 + DeviceTypeEnum deviceType, String tenantId, String organizationId, String deviceLabel);
  55 +
  56 + /**
  57 + * 通过设备ID和租户ID判断该设备是否存在
  58 + *
  59 + * @param tenantId 租户ID
  60 + * @param deviceId 设备ID
  61 + * @return 设备
  62 + */
  63 + DeviceDTO checkDeviceByTenantIdAndDeviceId(String tenantId, String deviceId);
  64 +
  65 + /**
  66 + * 通过网关子设备的TB设备ID查询网关设备信息
  67 + *
  68 + * @param tbDeviceId 网关子设备的TB设备ID
  69 + * @param tenantId 租户ID
  70 + * @return 网关设备信息
  71 + */
  72 + List<DeviceDTO> findGateWayDeviceByTbDeviceId(String tenantId, String tbDeviceId);
  73 +
  74 + /**
  75 + * 通过设备ID和租户ID检查设备是否存在
  76 + *
  77 + * @param tenantId 租户ID
  78 + * @param deviceId 设备ID
  79 + * @param isTbDeviceId 是TB设备ID
  80 + * @return 设备信息
  81 + */
  82 + DeviceDTO checkDeviceByTenantIdAndId(String tenantId, String deviceId, boolean isTbDeviceId);
  83 +
  84 + /**
  85 + * 更新设备告警状态
  86 + *
  87 + * @param tbDeviceId TB设备主键
  88 + * @param created 告警状态:0正常,1告警
  89 + * @return
  90 + */
  91 + boolean freshAlarmStatus(EntityId tbDeviceId, Integer created);
  92 +
  93 + /**
  94 + * 自动生成设备SN
  95 + *
  96 + * @return
  97 + */
  98 + String generateSn();
  99 +
  100 + /**
  101 + * 设备是否被其它资源使用,例如:场景联动
  102 + *
  103 + * @param deviceId 平台设备ID
  104 + * @param tenantId 租户ID
  105 + * @return
  106 + */
  107 + String otherUsing(String deviceId, String tenantId);
  108 +
  109 + /**
  110 + * 主设备信息
  111 + *
  112 + * @param tenantId 租户ID
  113 + * @param organizationId 组织ID
  114 + * @return 设备列表
  115 + */
  116 + List<SelectItemDTO> findMasterDevices(
  117 + String tenantId, String customerId, String organizationId, String deviceProfileId);
  118 +
  119 + /**
  120 + * 从设备信息
  121 + *
  122 + * @param masterId 主设备ID
  123 + * @param tenantId 租户ID
  124 + * @param organizationId 组织ID
  125 + * @return 设备列表
  126 + */
  127 + List<SelectItemDTO> findSlaveDevices(
  128 + String masterId, String tenantId, String customerId, String organizationId);
  129 +
  130 + /**
  131 + * TCP协议传输时,获取网关设备的从设备
  132 + *
  133 + * @param tenantId 租户ID
  134 + * @param masterId 网关设备的TB_ID
  135 + * @param deviceCode 网关子设备的标识符,例如:485协议的从设备地址码
  136 + * @return
  137 + */
  138 + DeviceDTO findSlaveDevice(String tenantId, String masterId, String deviceCode);
  139 +
  140 + /**
  141 + * 设备遥测数据指标名称
  142 + *
  143 + * @param tenantId 租户ID
  144 + * @param customerId 客户ID
  145 + * @param organizationId 组织ID
  146 + * @param deviceIds 设备ID
  147 + * @return
  148 + */
  149 + List<String> findDeviceKeys(
  150 + String tenantId, String customerId, String organizationId, List<String> deviceIds);
  151 +
  152 + /**
  153 + * Thingsboard自动创建的传感器设备(网关子设备)同步到平台
  154 + *
  155 + * @param slaveId 网关子设备TB平台的ID
  156 + * @param slaveName 网关子设备TB平台的名称
  157 + * @param gatewayId 网关设备TB平台的ID
  158 + * @return
  159 + */
  160 + boolean saveSlaveDevice(String slaveId, String slaveName, String gatewayId, Long createTime);
  161 +
  162 + /**
  163 + * 通过设备ids查询拥有数值型属性的设备
  164 + *
  165 + * @param tenantId 租户ID
  166 + * @param ids
  167 + * @return 数值型设备列表
  168 + */
  169 + List<DeviceDTO> findNumberAttributeDevicesByIds(String tenantId, List<String> ids);
  170 +
  171 + /**
  172 + * 通过tb设备ID获取平台设备信息
  173 + *
  174 + * @param tenantId 租户ID
  175 + * @param tbDeviceId tb设备ID
  176 + * @return 设备信息
  177 + */
  178 + DeviceDTO getSubsetDeviceByTbDeviceId(String tenantId, String tbDeviceId);
  179 +
  180 + /**
  181 + * 通过设备ID 设备配置ID获取属性
  182 + *
  183 + * @param deviceProfileId 平台设备配置ID
  184 + * @param id 设备ID
  185 + * @param tenantId 租户ID
  186 + * @param dataType 数据属性
  187 + * @return 属性信息de
  188 + */
  189 + JsonNode getDeviceAttributes(String deviceProfileId, String id, String tenantId, DataTypeEnum dataType);
182 } 190 }
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 <result property="deviceInfo" column="device_info" 14 <result property="deviceInfo" column="device_info"
15 typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> 15 typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
16 <result property="profileId" column="profile_id"/> 16 <result property="profileId" column="profile_id"/>
  17 + <result property="deviceProfileId" column="device_profile_id"/>
17 <result property="activeTime" column="active_time"/> 18 <result property="activeTime" column="active_time"/>
18 <result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> 19 <result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
19 <result property="brand" column="brand" /> 20 <result property="brand" column="brand" />
@@ -63,7 +64,7 @@ @@ -63,7 +64,7 @@
63 64
64 <sql id="basicColumns"> 65 <sql id="basicColumns">
65 ifd.id 66 ifd.id
66 - ,ifd.sn,ifd.brand,ifd.name,ifd.alias,ifd.device_info,ifd.profile_id,ifd.active_time,ifd.tenant_id,ifd.description 67 + ,ifd.sn,ifd.brand,ifd.name,ifd.alias,ifd.device_info,ifd.profile_id,ifd.device_profile_id,ifd.active_time,ifd.tenant_id,ifd.description
67 ,ifd.tb_device_id,ifd.label,ifd.last_connect_time,ifd.device_type,ifd.device_state,ifd.create_time,ifd.update_time,ifd.creator, 68 ,ifd.tb_device_id,ifd.label,ifd.last_connect_time,ifd.device_type,ifd.device_state,ifd.create_time,ifd.update_time,ifd.creator,
68 ifd.updater,ifd.organization_id,ifd.alarm_status 69 ifd.updater,ifd.organization_id,ifd.alarm_status
69 </sql> 70 </sql>
@@ -93,8 +94,8 @@ @@ -93,8 +94,8 @@
93 <if test="queryMap.tenantId !=null and queryMap.tenantId !=''"> 94 <if test="queryMap.tenantId !=null and queryMap.tenantId !=''">
94 AND ifd.tenant_id = #{queryMap.tenantId} 95 AND ifd.tenant_id = #{queryMap.tenantId}
95 </if> 96 </if>
96 - <if test="queryMap.profileId !=null and queryMap.profileId !=''">  
97 - AND ifd.profile_id = #{queryMap.profileId} 97 + <if test="queryMap.deviceProfileId !=null and queryMap.deviceProfileId !=''">
  98 + AND ifd.device_profile_id = #{queryMap.deviceProfileId}
98 </if> 99 </if>
99 <if test="queryMap.name !=null and queryMap.name !=''"> 100 <if test="queryMap.name !=null and queryMap.name !=''">
100 AND ( 101 AND (
@@ -330,7 +331,7 @@ @@ -330,7 +331,7 @@
330 331
331 <select id="masterDevices" resultMap="listInform"> 332 <select id="masterDevices" resultMap="listInform">
332 SELECT 333 SELECT
333 - base.tb_device_id as id,base.name,base.device_type 334 + base.tb_device_id as id,base.name,base.device_type,base.device_profile_id
334 FROM tk_device base 335 FROM tk_device base
335 LEFT JOIN device tde ON tde.ID :: TEXT = base.tb_device_id 336 LEFT JOIN device tde ON tde.ID :: TEXT = base.tb_device_id
336 <where> 337 <where>
@@ -338,6 +339,9 @@ @@ -338,6 +339,9 @@
338 <if test="tenantId !=null and tenantId !=''"> 339 <if test="tenantId !=null and tenantId !=''">
339 AND base.tenant_id = #{tenantId} 340 AND base.tenant_id = #{tenantId}
340 </if> 341 </if>
  342 + <if test="deviceProfileId !=null and deviceProfileId !=''">
  343 + AND base.device_profile_id = #{deviceProfileId}
  344 + </if>
341 <if test="customerId !=null and customerId !=''"> 345 <if test="customerId !=null and customerId !=''">
342 AND tde.customer_id :: TEXT = #{customerId} 346 AND tde.customer_id :: TEXT = #{customerId}
343 </if> 347 </if>
@@ -352,7 +356,7 @@ @@ -352,7 +356,7 @@
352 356
353 <select id="slaveDevices" resultMap="listInform"> 357 <select id="slaveDevices" resultMap="listInform">
354 SELECT 358 SELECT
355 - ide.tb_device_id as id,ide.name,ide.device_type 359 + ide.tb_device_id as id,ide.name,ide.device_type,ide.device_profile_id
356 FROM (select * from relation where relation_type_group = 'COMMON' AND relation_type = 'Created' AND from_type = 'DEVICE' AND to_type = 'DEVICE' 360 FROM (select * from relation where relation_type_group = 'COMMON' AND relation_type = 'Created' AND from_type = 'DEVICE' AND to_type = 'DEVICE'
357 <if test="masterId !=null and masterId !=''"> 361 <if test="masterId !=null and masterId !=''">
358 AND from_id :: TEXT = #{masterId} 362 AND from_id :: TEXT = #{masterId}
@@ -8,19 +8,25 @@ @@ -8,19 +8,25 @@
8 <result property="entityType" column="entity_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> 8 <result property="entityType" column="entity_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
9 <result property="doContext" column="do_context" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> 9 <result property="doContext" column="do_context" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
10 <result property="outTarget" column="out_target" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> 10 <result property="outTarget" column="out_target" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
11 - <result property="sceneLinkageId" column="scene_linkage_id"/> 11 + <result property="callType" column="call_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
  12 + <result property="commandType" column="command_type"/>
  13 + <result property="thingsModelId" column="scene_linkage_id"/>
  14 + <result property="sceneLinkageId" column="things_model_id"/>
  15 + <result property="deviceProfileId" column="device_profile_id"/>
12 <result property="alarmProfileId" column="alarm_profile_id"/> 16 <result property="alarmProfileId" column="alarm_profile_id"/>
13 - <result property="description" column="description"/>  
14 <result property="tenantId" column="tenant_id"/> 17 <result property="tenantId" column="tenant_id"/>
15 <result property="updater" column="updater"/> 18 <result property="updater" column="updater"/>
16 <result property="updateTime" column="update_time"/> 19 <result property="updateTime" column="update_time"/>
17 <result property="createTime" column="create_time"/> 20 <result property="createTime" column="create_time"/>
18 <result property="creator" column="creator"/> 21 <result property="creator" column="creator"/>
19 - 22 +
20 </resultMap> 23 </resultMap>
21 - 24 + <sql id="columns">
  25 + id,device_id,entity_type,do_context,out_target,call_type,scene_linkage_id,alarm_profile_id,
  26 + tenant_id,updater,update_time,create_time,creator,command_type,things_model_id,device_profile_id
  27 + </sql>
22 <select id="listBySceneId" resultMap="actionDTO"> 28 <select id="listBySceneId" resultMap="actionDTO">
23 - SELECT * FROM tk_do_action WHERE scene_linkage_id = #{sceneId} 29 + SELECT <include refid="columns"/> FROM tk_do_action WHERE scene_linkage_id = #{sceneId}
24 </select> 30 </select>
25 31
26 </mapper> 32 </mapper>