Commit cd0517b2bbddcbce5ec0ad7452642f4c386621d2

Authored by xp.Huang
2 parents 1b86d49f 50a50e03

Merge branch 'fix/teambition/2024-10-25' into 'master_dev'

perf:获取满足条件的所有设备 接口 isExcludeEdge参数默认为fase

See merge request yunteng/thingskit!456
@@ -385,23 +385,20 @@ public class TkDeviceController extends BaseController { @@ -385,23 +385,20 @@ public class TkDeviceController extends BaseController {
385 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") 385 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')")
386 @ApiOperation("获取满足条件的所有设备") 386 @ApiOperation("获取满足条件的所有设备")
387 public List<DeviceDTO> getDevices( 387 public List<DeviceDTO> getDevices(
388 - @ApiParam(value = "设备类型") @RequestParam(value = "deviceType", required = false)  
389 - DeviceTypeEnum deviceType,  
390 - @ApiParam(value = "组织ID") @RequestParam(value = "organizationId", required = false)  
391 - String organizationId,  
392 - @ApiParam(value = "设备标签") @RequestParam(value = "deviceLabel", required = false)  
393 - String deviceLabel,  
394 - @ApiParam(value = "设备配置ID") @RequestParam(value = "deviceProfileId", required = false)  
395 - String deviceProfileId,  
396 - @ApiParam(value = "传输协议类型") @RequestParam(value = "transportType", required = false)  
397 - TransportTypeEnum transportType,  
398 - @ApiParam(value = "是否场景联动调用,是true") @RequestParam(value = "isSceneLinkage", required = false)  
399 - Boolean isSceneLinkage,  
400 - @ApiParam(value = "是否边缘分配设备调用,是true") @RequestParam(value = "isEdgeDistribution", required = false)  
401 - Boolean isEdgeDistribution,  
402 - @ApiParam(value = "edgeId") @RequestParam(value = "edgeId", required = false)  
403 - String edgeId) 388 + @ApiParam(value = "设备类型") @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType,
  389 + @ApiParam(value = "组织ID") @RequestParam(value = "organizationId", required = false) String organizationId,
  390 + @ApiParam(value = "设备标签") @RequestParam(value = "deviceLabel", required = false) String deviceLabel,
  391 + @ApiParam(value = "设备配置ID") @RequestParam(value = "deviceProfileId", required = false) String deviceProfileId,
  392 + @ApiParam(value = "传输协议类型") @RequestParam(value = "transportType", required = false) TransportTypeEnum transportType,
  393 + @ApiParam(value = "是否场景联动调用,是true") @RequestParam(value = "isSceneLinkage", required = false) Boolean isSceneLinkage,
  394 + @ApiParam(value = "是否边缘分配设备调用,是true") @RequestParam(value = "isEdgeDistribution", required = false) Boolean isEdgeDistribution,
  395 + @ApiParam(value = "edgeId") @RequestParam(value = "edgeId", required = false) String edgeId,
  396 + @ApiParam(value = "排除边端设备是true") @RequestParam(value = "isExcludeEdge", required = false) Boolean isExcludeEdge
  397 + )
404 throws ThingsboardException { 398 throws ThingsboardException {
  399 + if(isExcludeEdge==null){
  400 + isExcludeEdge=false;
  401 + }
405 return tkdeviceService.findDevicesByDeviceTypeAndOrganizationId( 402 return tkdeviceService.findDevicesByDeviceTypeAndOrganizationId(
406 deviceType, 403 deviceType,
407 getCurrentUser().getTenantId().getId(), 404 getCurrentUser().getTenantId().getId(),
@@ -411,7 +408,9 @@ public class TkDeviceController extends BaseController { @@ -411,7 +408,9 @@ public class TkDeviceController extends BaseController {
411 transportType, 408 transportType,
412 isSceneLinkage, 409 isSceneLinkage,
413 isEdgeDistribution, 410 isEdgeDistribution,
414 - StringUtils.isEmpty(edgeId)?null:UUID.fromString(edgeId)); 411 + StringUtils.isEmpty(edgeId)?null:UUID.fromString(edgeId),
  412 + isExcludeEdge
  413 + );
415 } 414 }
416 415
417 416
@@ -327,7 +327,8 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD @@ -327,7 +327,8 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD
327 TransportTypeEnum transportTypeEnum, 327 TransportTypeEnum transportTypeEnum,
328 Boolean isSceneLinkage, 328 Boolean isSceneLinkage,
329 Boolean isEdgeDistribution, 329 Boolean isEdgeDistribution,
330 - UUID edgeId) { 330 + UUID edgeId,
  331 + Boolean isExcludeEdge) {
331 List<String> orgIds = organizationService.organizationAllIds(tenantId.toString(), organizationId); 332 List<String> orgIds = organizationService.organizationAllIds(tenantId.toString(), organizationId);
332 if (orgIds.isEmpty()) { 333 if (orgIds.isEmpty()) {
333 throw new TkDataValidationException(MessageUtils.message(ErrorMessage.ORGANIZATION_NOT_EXTIED.getI18nCode())); 334 throw new TkDataValidationException(MessageUtils.message(ErrorMessage.ORGANIZATION_NOT_EXTIED.getI18nCode()));
@@ -335,7 +336,7 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD @@ -335,7 +336,7 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD
335 336
336 List<TkDeviceEntity> listEntity = baseMapper.findDevicesByDeviceTypeAndOrganizationId(orgIds, 337 List<TkDeviceEntity> listEntity = baseMapper.findDevicesByDeviceTypeAndOrganizationId(orgIds,
337 deviceType == null ? null : deviceType.name(), 338 deviceType == null ? null : deviceType.name(),
338 - deviceLabel, deviceProfileId, transportTypeEnum,isSceneLinkage,isEdgeDistribution,edgeId); 339 + deviceLabel, deviceProfileId, transportTypeEnum,isSceneLinkage,isEdgeDistribution,edgeId,isExcludeEdge);
339 return listEntity.stream().map(entity -> { 340 return listEntity.stream().map(entity -> {
340 return CopyUtils.copyAndReturn(entity, new DeviceDTO()); 341 return CopyUtils.copyAndReturn(entity, new DeviceDTO());
341 } 342 }
@@ -62,7 +62,7 @@ public class TkDeviceStateLogServiceImpl @@ -62,7 +62,7 @@ public class TkDeviceStateLogServiceImpl
62 } 62 }
63 if(isPtCommonTenant){ 63 if(isPtCommonTenant){
64 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId((List<String>) queryMap.get("orgIds"), 64 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId((List<String>) queryMap.get("orgIds"),
65 - null,null,null,null,false,false,null); 65 + null,null,null,null,false,false,null,false);
66 List<String> finalTbDevices = new ArrayList<>(); 66 List<String> finalTbDevices = new ArrayList<>();
67 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString())); 67 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString()));
68 deviceIds = finalTbDevices; 68 deviceIds = finalTbDevices;
@@ -250,7 +250,7 @@ public class TkHomePageServiceImpl implements HomePageService { @@ -250,7 +250,7 @@ public class TkHomePageServiceImpl implements HomePageService {
250 totalFilter.put("organizationIds",organizationIds); 250 totalFilter.put("organizationIds",organizationIds);
251 //查询所有设备 251 //查询所有设备
252 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId(organizationIds,null, 252 List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId(organizationIds,null,
253 - null,null,null,false,false,null); 253 + null,null,null,false,false,null,false);
254 List<String> finalTbDevices = new ArrayList<>(); 254 List<String> finalTbDevices = new ArrayList<>();
255 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString())); 255 devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString()));
256 todayFilter.put("deviceIds",finalTbDevices); 256 todayFilter.put("deviceIds",finalTbDevices);
@@ -113,7 +113,7 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid @@ -113,7 +113,7 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid
113 List<TkVideoGbtDeviceDTO> deviceList = new ArrayList<>(); 113 List<TkVideoGbtDeviceDTO> deviceList = new ArrayList<>();
114 List<DeviceDTO> deviceDTOS = tkdeviceService.findDevicesByDeviceTypeAndOrganizationId( 114 List<DeviceDTO> deviceDTOS = tkdeviceService.findDevicesByDeviceTypeAndOrganizationId(
115 null, UUID.fromString(dto.getTenantId()),organizationId,null, 115 null, UUID.fromString(dto.getTenantId()),organizationId,null,
116 - null, TransportTypeEnum.GBT28181,false,false,null); 116 + null, TransportTypeEnum.GBT28181,false,false,null,true);
117 if(deviceDTOS.isEmpty()){ 117 if(deviceDTOS.isEmpty()){
118 return dto; 118 return dto;
119 } 119 }
@@ -164,7 +164,8 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { @@ -164,7 +164,8 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> {
164 @Param("transportType")TransportTypeEnum transportType, 164 @Param("transportType")TransportTypeEnum transportType,
165 @Param("isSceneLinkage")Boolean isSceneLinkage, 165 @Param("isSceneLinkage")Boolean isSceneLinkage,
166 @Param("isEdgeDistribution")Boolean isEdgeDistribution, 166 @Param("isEdgeDistribution")Boolean isEdgeDistribution,
167 - @Param("edgeId")UUID edgeId) ; 167 + @Param("edgeId")UUID edgeId,
  168 + @Param("isExcludeEdge")Boolean isExcludeEdge) ;
168 169
169 170
170 List<DeviceDTO> findDevicesByProfileIdAndOrganizationId( 171 List<DeviceDTO> findDevicesByProfileIdAndOrganizationId(
@@ -81,7 +81,7 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> { @@ -81,7 +81,7 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> {
81 TransportTypeEnum transportTypeEnum, 81 TransportTypeEnum transportTypeEnum,
82 Boolean isSceneLinkage, 82 Boolean isSceneLinkage,
83 Boolean isEdgeDistribution, 83 Boolean isEdgeDistribution,
84 - UUID edgeId); 84 + UUID edgeId,Boolean excludeEdge);
85 85
86 86
87 List<DeviceDTO> findDevicesByOrganizationIds( 87 List<DeviceDTO> findDevicesByOrganizationIds(
@@ -571,6 +571,7 @@ @@ -571,6 +571,7 @@
571 <!--此设备是边端创建或者已经分配给边端--> 571 <!--此设备是边端创建或者已经分配给边端-->
572 LEFT JOIN relation re on re.to_id = ifd.id and re.from_type = 'EDGE' and( re.relation_type = 'ManagedByEdge' or re.relation_type = 'Contains') 572 LEFT JOIN relation re on re.to_id = ifd.id and re.from_type = 'EDGE' and( re.relation_type = 'ManagedByEdge' or re.relation_type = 'Contains')
573 </if> 573 </if>
  574 +
574 <if test="edgeId != null"> 575 <if test="edgeId != null">
575 LEFT JOIN relation re on re.to_id = ifd.id 576 LEFT JOIN relation re on re.to_id = ifd.id
576 and re.from_id =#{edgeId} 577 and re.from_id =#{edgeId}
@@ -586,6 +587,9 @@ @@ -586,6 +587,9 @@
586 </if> 587 </if>
587 where 588 where
588 1=1 589 1=1
  590 + <if test="isExcludeEdge == true">
  591 + and ifd.id not in (SELECT dev.id from device dev inner join relation re_edge on dev.id=re_edge.to_id and re_edge.from_type = 'EDGE' and re_edge.relation_type = 'ManagedByEdge')
  592 + </if>
589 <if test="isSceneLinkage == true"> 593 <if test="isSceneLinkage == true">
590 and re.to_id is null 594 and re.to_id is null
591 </if> 595 </if>