Commit 8d764d172c7b235a9b43c37c6afc46f4e3076b3a

Authored by 云中非
1 parent 5b41f39d

fix: 组织设备未包含子组织设备问题修复

@@ -353,8 +353,8 @@ public class YtDeviceController extends BaseController { @@ -353,8 +353,8 @@ public class YtDeviceController extends BaseController {
353 @ApiOperation("获取该组织的所有设备") 353 @ApiOperation("获取该组织的所有设备")
354 public List<DeviceDTO> getGatewayDevices( 354 public List<DeviceDTO> getGatewayDevices(
355 @ApiParam(value = "组织ID") @RequestParam("organizationId") String organizationId, 355 @ApiParam(value = "组织ID") @RequestParam("organizationId") String organizationId,
356 - @ApiParam(value = "设备类型") @PathVariable("deviceType") DeviceTypeEnum deviceType) {  
357 - return deviceService.findDevicesByDeviceTypeAndOrganizationId(deviceType, organizationId); 356 + @ApiParam(value = "设备类型") @PathVariable("deviceType") DeviceTypeEnum deviceType) throws ThingsboardException {
  357 + return deviceService.findDevicesByDeviceTypeAndOrganizationId(deviceType,getCurrentUser().getCurrentTenantId(), organizationId);
358 } 358 }
359 359
360 @GetMapping("/gateway/{tbDeviceId}") 360 @GetMapping("/gateway/{tbDeviceId}")
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
6 import lombok.RequiredArgsConstructor; 6 import lombok.RequiredArgsConstructor;
7 import lombok.extern.slf4j.Slf4j; 7 import lombok.extern.slf4j.Slf4j;
8 import org.apache.commons.lang3.StringUtils; 8 import org.apache.commons.lang3.StringUtils;
  9 +import org.jetbrains.annotations.NotNull;
9 import org.jetbrains.annotations.Nullable; 10 import org.jetbrains.annotations.Nullable;
10 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
11 import org.springframework.transaction.annotation.Transactional; 12 import org.springframework.transaction.annotation.Transactional;
@@ -217,12 +218,13 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev @@ -217,12 +218,13 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev
217 218
218 @Override 219 @Override
219 public List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( 220 public List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(
220 - DeviceTypeEnum deviceType, String organizationId) { 221 + DeviceTypeEnum deviceType, String tenantId, String organizationId) {
  222 + List<String> orgIds = organizationAllIds(tenantId,organizationId);
221 return ReflectUtils.sourceToTarget( 223 return ReflectUtils.sourceToTarget(
222 baseMapper.selectList( 224 baseMapper.selectList(
223 new LambdaQueryWrapper<YtDevice>() 225 new LambdaQueryWrapper<YtDevice>()
224 .eq(YtDevice::getDeviceType, deviceType) 226 .eq(YtDevice::getDeviceType, deviceType)
225 - .eq(YtDevice::getOrganizationId, organizationId)), 227 + .in(YtDevice::getOrganizationId, orgIds)),
226 DeviceDTO.class); 228 DeviceDTO.class);
227 } 229 }
228 230
@@ -286,16 +288,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev @@ -286,16 +288,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev
286 queryMap.put("tenantId", tenantId); 288 queryMap.put("tenantId", tenantId);
287 String organizationId = (String) queryMap.get("organizationId"); 289 String organizationId = (String) queryMap.get("organizationId");
288 if (!StringUtils.isEmpty(organizationId)) { 290 if (!StringUtils.isEmpty(organizationId)) {
289 - List<String> organizationIds = new ArrayList<>();  
290 - organizationIds.add(organizationId);  
291 - // 查询该组织的所有子类  
292 - List<OrganizationDTO> organizationDTOS =  
293 - ytOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds);  
294 - List<String> queryOrganizationIds = new ArrayList<>();  
295 - organizationDTOS.forEach(  
296 - item -> {  
297 - queryOrganizationIds.add(item.getId());  
298 - }); 291 + List<String> queryOrganizationIds = organizationAllIds(tenantId, organizationId);
299 queryMap.put("organizationIds", queryOrganizationIds); 292 queryMap.put("organizationIds", queryOrganizationIds);
300 } 293 }
301 IPage<YtDevice> page = getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false); 294 IPage<YtDevice> page = getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false);
@@ -311,6 +304,27 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev @@ -311,6 +304,27 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev
311 return new YtPageData<>(records, deviceIPage.getTotal()); 304 return new YtPageData<>(records, deviceIPage.getTotal());
312 } 305 }
313 306
  307 + /**
  308 + * 组织结构下的所有组织ID
  309 + * @param tenantId 租户ID
  310 + * @param organizationId 组织ID
  311 + * @return
  312 + */
  313 + @NotNull
  314 + private List<String> organizationAllIds(String tenantId, String organizationId) {
  315 + List<String> organizationIds = new ArrayList<>();
  316 + organizationIds.add(organizationId);
  317 + // 查询该组织的所有子类
  318 + List<OrganizationDTO> organizationDTOS =
  319 + ytOrganizationMapper.findOrganizationTreeList(tenantId, organizationIds);
  320 + List<String> queryOrganizationIds = new ArrayList<>();
  321 + organizationDTOS.forEach(
  322 + item -> {
  323 + queryOrganizationIds.add(item.getId());
  324 + });
  325 + return queryOrganizationIds;
  326 + }
  327 +
314 @Override 328 @Override
315 public YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap) { 329 public YtPageData<RelationDeviceDTO> pageRelation(Map<String, Object> queryMap) {
316 IPage<YtDevice> page = getPage(queryMap, "last_online_time", false); 330 IPage<YtDevice> page = getPage(queryMap, "last_online_time", false);
@@ -48,7 +48,7 @@ public interface YtDeviceService extends BaseService<YtDevice> { @@ -48,7 +48,7 @@ public interface YtDeviceService extends BaseService<YtDevice> {
48 * @return 设备列表 48 * @return 设备列表
49 */ 49 */
50 List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId( 50 List<DeviceDTO> findDevicesByDeviceTypeAndOrganizationId(
51 - DeviceTypeEnum deviceType, String organizationId); 51 + DeviceTypeEnum deviceType, String tenantId, String organizationId);
52 52
53 /** 53 /**
54 * 通过设备ID和租户ID判断该设备是否存在 54 * 通过设备ID和租户ID判断该设备是否存在