Commit 50a50e034a7491b2a0f0bf198e58e3892f7b7901
1 parent
1b86d49f
perf:获取满足条件的所有设备 接口 isExcludeEdge参数默认为fase
Showing
8 changed files
with
29 additions
and
24 deletions
... | ... | @@ -385,23 +385,20 @@ public class TkDeviceController extends BaseController { |
385 | 385 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") |
386 | 386 | @ApiOperation("获取满足条件的所有设备") |
387 | 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 | 398 | throws ThingsboardException { |
399 | + if(isExcludeEdge==null){ | |
400 | + isExcludeEdge=false; | |
401 | + } | |
405 | 402 | return tkdeviceService.findDevicesByDeviceTypeAndOrganizationId( |
406 | 403 | deviceType, |
407 | 404 | getCurrentUser().getTenantId().getId(), |
... | ... | @@ -411,7 +408,9 @@ public class TkDeviceController extends BaseController { |
411 | 408 | transportType, |
412 | 409 | isSceneLinkage, |
413 | 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 | 327 | TransportTypeEnum transportTypeEnum, |
328 | 328 | Boolean isSceneLinkage, |
329 | 329 | Boolean isEdgeDistribution, |
330 | - UUID edgeId) { | |
330 | + UUID edgeId, | |
331 | + Boolean isExcludeEdge) { | |
331 | 332 | List<String> orgIds = organizationService.organizationAllIds(tenantId.toString(), organizationId); |
332 | 333 | if (orgIds.isEmpty()) { |
333 | 334 | throw new TkDataValidationException(MessageUtils.message(ErrorMessage.ORGANIZATION_NOT_EXTIED.getI18nCode())); |
... | ... | @@ -335,7 +336,7 @@ public class TkDeviceServiceImpl extends AbstractTbBaseService<DeviceMapper, TkD |
335 | 336 | |
336 | 337 | List<TkDeviceEntity> listEntity = baseMapper.findDevicesByDeviceTypeAndOrganizationId(orgIds, |
337 | 338 | deviceType == null ? null : deviceType.name(), |
338 | - deviceLabel, deviceProfileId, transportTypeEnum,isSceneLinkage,isEdgeDistribution,edgeId); | |
339 | + deviceLabel, deviceProfileId, transportTypeEnum,isSceneLinkage,isEdgeDistribution,edgeId,isExcludeEdge); | |
339 | 340 | return listEntity.stream().map(entity -> { |
340 | 341 | return CopyUtils.copyAndReturn(entity, new DeviceDTO()); |
341 | 342 | } | ... | ... |
... | ... | @@ -62,7 +62,7 @@ public class TkDeviceStateLogServiceImpl |
62 | 62 | } |
63 | 63 | if(isPtCommonTenant){ |
64 | 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 | 66 | List<String> finalTbDevices = new ArrayList<>(); |
67 | 67 | devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString())); |
68 | 68 | deviceIds = finalTbDevices; | ... | ... |
... | ... | @@ -250,7 +250,7 @@ public class TkHomePageServiceImpl implements HomePageService { |
250 | 250 | totalFilter.put("organizationIds",organizationIds); |
251 | 251 | //查询所有设备 |
252 | 252 | List<TkDeviceEntity> devices = deviceMapper.findDevicesByDeviceTypeAndOrganizationId(organizationIds,null, |
253 | - null,null,null,false,false,null); | |
253 | + null,null,null,false,false,null,false); | |
254 | 254 | List<String> finalTbDevices = new ArrayList<>(); |
255 | 255 | devices.forEach(item -> finalTbDevices.add(item.getTbDeviceId().toString())); |
256 | 256 | todayFilter.put("deviceIds",finalTbDevices); | ... | ... |
... | ... | @@ -113,7 +113,7 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid |
113 | 113 | List<TkVideoGbtDeviceDTO> deviceList = new ArrayList<>(); |
114 | 114 | List<DeviceDTO> deviceDTOS = tkdeviceService.findDevicesByDeviceTypeAndOrganizationId( |
115 | 115 | null, UUID.fromString(dto.getTenantId()),organizationId,null, |
116 | - null, TransportTypeEnum.GBT28181,false,false,null); | |
116 | + null, TransportTypeEnum.GBT28181,false,false,null,true); | |
117 | 117 | if(deviceDTOS.isEmpty()){ |
118 | 118 | return dto; |
119 | 119 | } | ... | ... |
... | ... | @@ -164,7 +164,8 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { |
164 | 164 | @Param("transportType")TransportTypeEnum transportType, |
165 | 165 | @Param("isSceneLinkage")Boolean isSceneLinkage, |
166 | 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 | 171 | List<DeviceDTO> findDevicesByProfileIdAndOrganizationId( | ... | ... |
... | ... | @@ -81,7 +81,7 @@ public interface TkDeviceService extends TbBaseService<TkDeviceEntity> { |
81 | 81 | TransportTypeEnum transportTypeEnum, |
82 | 82 | Boolean isSceneLinkage, |
83 | 83 | Boolean isEdgeDistribution, |
84 | - UUID edgeId); | |
84 | + UUID edgeId,Boolean excludeEdge); | |
85 | 85 | |
86 | 86 | |
87 | 87 | List<DeviceDTO> findDevicesByOrganizationIds( | ... | ... |
... | ... | @@ -571,6 +571,7 @@ |
571 | 571 | <!--此设备是边端创建或者已经分配给边端--> |
572 | 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 | 573 | </if> |
574 | + | |
574 | 575 | <if test="edgeId != null"> |
575 | 576 | LEFT JOIN relation re on re.to_id = ifd.id |
576 | 577 | and re.from_id =#{edgeId} |
... | ... | @@ -586,6 +587,9 @@ |
586 | 587 | </if> |
587 | 588 | where |
588 | 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 | 593 | <if test="isSceneLinkage == true"> |
590 | 594 | and re.to_id is null |
591 | 595 | </if> | ... | ... |