Commit 2926ea7a14fb0b181539fc2bd5ce53698ccb2034
1 parent
97375a4f
fix: 设备删除,场景联动启动失败问题
1、触发器中不存在设备,启动提示设备不存在。 2、场景联动所属组织没有设备空指针异常
Showing
1 changed file
with
15 additions
and
4 deletions
... | ... | @@ -469,8 +469,10 @@ public class SceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageMap |
469 | 469 | List<DeviceDTO> organizationDevices = |
470 | 470 | findDeviceList(self.getOrganizationId(), tenantId, customerId); |
471 | 471 | List<String> allDevices = new ArrayList<>(); |
472 | - for (DeviceDTO item : organizationDevices) { | |
473 | - allDevices.add(item.getTbDeviceId()); | |
472 | + if(organizationDevices != null && !organizationDevices.isEmpty()){ | |
473 | + for (DeviceDTO item : organizationDevices) { | |
474 | + allDevices.add(item.getTbDeviceId()); | |
475 | + } | |
474 | 476 | } |
475 | 477 | |
476 | 478 | Map<String, List<String>> matchedDevices = new HashMap<>(); |
... | ... | @@ -487,8 +489,17 @@ public class SceneLinkageServiceImpl extends AbstractBaseService<SceneLinkageMap |
487 | 489 | trigger -> { |
488 | 490 | String scenId = trigger.getSceneLinkageId(); |
489 | 491 | List<String> devices = trigger.getEntityId(); |
490 | - if (ScopeEnum.ALL.equals(trigger.getEntityType()) && currentSceneId.equals(scenId)) { | |
491 | - devices = allDevices; | |
492 | + if(currentSceneId.equals(scenId)){ | |
493 | + if (ScopeEnum.ALL.equals(trigger.getEntityType()) ) { | |
494 | + devices = allDevices; | |
495 | + }else{ | |
496 | + devices = devices.stream() | |
497 | + .filter(t -> allDevices.contains(t)) | |
498 | + .collect(Collectors.toList()); | |
499 | + } | |
500 | + if (devices == null || devices.isEmpty()) { | |
501 | + throw new YtDataValidationException(ErrorMessage.DEVICE_NOT_EXTIED.getMessage()); | |
502 | + } | |
492 | 503 | } |
493 | 504 | deviceSceneMap(matchedDevices, devices, scenId); |
494 | 505 | }); | ... | ... |