Commit f95eb1665928cc177c4dbbec86555df460285e04
Merge branch '20220922' into 'master'
refactor: 条件过滤设备信息 See merge request huang/thingsboard3.3.2!134
Showing
3 changed files
with
29 additions
and
9 deletions
@@ -358,13 +358,27 @@ public class YtDeviceController extends BaseController { | @@ -358,13 +358,27 @@ public class YtDeviceController extends BaseController { | ||
358 | 358 | ||
359 | @GetMapping("/list/{deviceType}") | 359 | @GetMapping("/list/{deviceType}") |
360 | @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{})") | 360 | @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{})") |
361 | - @ApiOperation("获取该组织的所有设备") | 361 | + @ApiOperation("获取特定设备类型的所有设备") |
362 | public List<DeviceDTO> getGatewayDevices( | 362 | public List<DeviceDTO> getGatewayDevices( |
363 | - @ApiParam(value = "组织ID") @RequestParam("organizationId") String organizationId, | ||
364 | - @ApiParam(value = "设备类型") @PathVariable("deviceType") DeviceTypeEnum deviceType) | ||
365 | - throws ThingsboardException { | 363 | + |
364 | + @ApiParam(value = "设备类型") @PathVariable("deviceType") DeviceTypeEnum deviceType, | ||
365 | + @ApiParam(value = "组织ID") @RequestParam(value="organizationId", required = false) String organizationId, | ||
366 | + @ApiParam(value = "设备标签") @RequestParam(value="deviceLabel", required = false) String deviceLabel) | ||
367 | + throws ThingsboardException { | ||
368 | + return deviceService.findDevicesByDeviceTypeAndOrganizationId( | ||
369 | + deviceType, getCurrentUser().getCurrentTenantId(), organizationId,deviceLabel); | ||
370 | + } | ||
371 | + | ||
372 | + @GetMapping("/list") | ||
373 | + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{})") | ||
374 | + @ApiOperation("获取满足条件的所有设备") | ||
375 | + public List<DeviceDTO> getDevices( | ||
376 | + @ApiParam(value = "设备类型") @RequestParam(value="deviceType", required = false) DeviceTypeEnum deviceType, | ||
377 | + @ApiParam(value = "组织ID") @RequestParam(value="organizationId", required = false) String organizationId, | ||
378 | + @ApiParam(value = "设备标签") @RequestParam(value="deviceLabel", required = false) String deviceLabel) | ||
379 | + throws ThingsboardException { | ||
366 | return deviceService.findDevicesByDeviceTypeAndOrganizationId( | 380 | return deviceService.findDevicesByDeviceTypeAndOrganizationId( |
367 | - deviceType, getCurrentUser().getCurrentTenantId(), organizationId); | 381 | + deviceType, getCurrentUser().getCurrentTenantId(), organizationId,deviceLabel); |
368 | } | 382 | } |
369 | 383 | ||
370 | @GetMapping("/list/master/{organizationId}") | 384 | @GetMapping("/list/master/{organizationId}") |
@@ -243,12 +243,16 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -243,12 +243,16 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
243 | 243 | ||
244 | @Override | 244 | @Override |
245 | public List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( | 245 | public List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( |
246 | - DeviceTypeEnum deviceType, String tenantId, String organizationId) { | 246 | + DeviceTypeEnum deviceType, String tenantId, String organizationId,String deviceLabel) { |
247 | List<String> orgIds = organizationAllIds(tenantId, organizationId); | 247 | List<String> orgIds = organizationAllIds(tenantId, organizationId); |
248 | + if(orgIds.isEmpty()){ | ||
249 | + throw new YtDataValidationException(ErrorMessage.ORGANIZATION_NOT_EXTIED.getMessage()); | ||
250 | + } | ||
248 | return ReflectUtils.sourceToTarget( | 251 | return ReflectUtils.sourceToTarget( |
249 | baseMapper.selectList( | 252 | baseMapper.selectList( |
250 | new LambdaQueryWrapper<YtDevice>() | 253 | new LambdaQueryWrapper<YtDevice>() |
251 | - .eq(YtDevice::getDeviceType, deviceType) | 254 | + .eq(deviceType != null,YtDevice::getDeviceType, deviceType) |
255 | + .eq(deviceLabel != null,YtDevice::getLabel, deviceLabel) | ||
252 | .in(YtDevice::getOrganizationId, orgIds)), | 256 | .in(YtDevice::getOrganizationId, orgIds)), |
253 | DeviceDTO.class); | 257 | DeviceDTO.class); |
254 | } | 258 | } |
@@ -339,7 +343,9 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | @@ -339,7 +343,9 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev | ||
339 | @NotNull | 343 | @NotNull |
340 | private List<String> organizationAllIds(String tenantId, String organizationId) { | 344 | private List<String> organizationAllIds(String tenantId, String organizationId) { |
341 | List<String> organizationIds = new ArrayList<>(); | 345 | List<String> organizationIds = new ArrayList<>(); |
342 | - organizationIds.add(organizationId); | 346 | + if(!StringUtils.isEmpty(organizationId)){ |
347 | + organizationIds.add(organizationId); | ||
348 | + } | ||
343 | // 查询该组织的所有子类 | 349 | // 查询该组织的所有子类 |
344 | List<OrganizationDTO> organizationDTOS = | 350 | List<OrganizationDTO> organizationDTOS = |
345 | ytOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds); | 351 | ytOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds); |
@@ -49,7 +49,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { | @@ -49,7 +49,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { | ||
49 | * @return 设备列表 | 49 | * @return 设备列表 |
50 | */ | 50 | */ |
51 | List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( | 51 | List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( |
52 | - DeviceTypeEnum deviceType, String tenantId, String organizationId); | 52 | + DeviceTypeEnum deviceType, String tenantId, String organizationId,String deviceLabel); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * 通过设备ID和租户ID判断该设备是否存在 | 55 | * 通过设备ID和租户ID判断该设备是否存在 |