Commit 8c9227fd919102bad6d94a22da68ebfacfcc33ed

Authored by 云中非
1 parent 2e4248d8

refactor: 条件过滤设备信息

1、设备类型过滤
2、组织过滤
3、设备标签过滤
... ... @@ -358,13 +358,27 @@ public class YtDeviceController extends BaseController {
358 358
359 359 @GetMapping("/list/{deviceType}")
360 360 @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{})")
361   - @ApiOperation("获取该组织的所有设备")
  361 + @ApiOperation("获取特定设备类型的所有设备")
362 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 380 return deviceService.findDevicesByDeviceTypeAndOrganizationId(
367   - deviceType, getCurrentUser().getCurrentTenantId(), organizationId);
  381 + deviceType, getCurrentUser().getCurrentTenantId(), organizationId,deviceLabel);
368 382 }
369 383
370 384 @GetMapping("/list/master/{organizationId}")
... ...
... ... @@ -243,12 +243,16 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev
243 243
244 244 @Override
245 245 public List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(
246   - DeviceTypeEnum deviceType, String tenantId, String organizationId) {
  246 + DeviceTypeEnum deviceType, String tenantId, String organizationId,String deviceLabel) {
247 247 List<String> orgIds = organizationAllIds(tenantId, organizationId);
  248 + if(orgIds.isEmpty()){
  249 + throw new YtDataValidationException(ErrorMessage.ORGANIZATION_NOT_EXTIED.getMessage());
  250 + }
248 251 return ReflectUtils.sourceToTarget(
249 252 baseMapper.selectList(
250 253 new LambdaQueryWrapper<YtDevice>()
251   - .eq(YtDevice::getDeviceType, deviceType)
  254 + .eq(deviceType != null,YtDevice::getDeviceType, deviceType)
  255 + .eq(deviceLabel != null,YtDevice::getLabel, deviceLabel)
252 256 .in(YtDevice::getOrganizationId, orgIds)),
253 257 DeviceDTO.class);
254 258 }
... ... @@ -339,7 +343,9 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev
339 343 @NotNull
340 344 private List<String> organizationAllIds(String tenantId, String organizationId) {
341 345 List<String> organizationIds = new ArrayList<>();
342   - organizationIds.add(organizationId);
  346 + if(!StringUtils.isEmpty(organizationId)){
  347 + organizationIds.add(organizationId);
  348 + }
343 349 // 查询该组织的所有子类
344 350 List<OrganizationDTO> organizationDTOS =
345 351 ytOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds);
... ...
... ... @@ -49,7 +49,7 @@ public interface YtDeviceService extends BaseService<YtDevice> {
49 49 * @return 设备列表
50 50 */
51 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 55 * 通过设备ID和租户ID判断该设备是否存在
... ...