|
|
|
@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.thingsboard.server.common.data.EntityInfo; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.HasCustomerId; |
|
|
|
import org.thingsboard.server.common.data.HasEmail; |
|
|
|
@ -41,19 +42,24 @@ import org.thingsboard.server.common.data.query.EntityDataPageLink; |
|
|
|
import org.thingsboard.server.common.data.query.EntityDataQuery; |
|
|
|
import org.thingsboard.server.common.data.query.EntityFilterType; |
|
|
|
import org.thingsboard.server.common.data.query.EntityKey; |
|
|
|
import org.thingsboard.server.common.data.query.EntityKeyType; |
|
|
|
import org.thingsboard.server.common.data.query.EntityListFilter; |
|
|
|
import org.thingsboard.server.common.data.query.EntityNameFilter; |
|
|
|
import org.thingsboard.server.common.data.query.EntityTypeFilter; |
|
|
|
import org.thingsboard.server.common.data.query.KeyFilter; |
|
|
|
import org.thingsboard.server.common.data.query.RelationsQueryFilter; |
|
|
|
import org.thingsboard.server.common.data.query.TsValue; |
|
|
|
import org.thingsboard.server.common.msg.edqs.EdqsApiService; |
|
|
|
import org.thingsboard.server.common.stats.EdqsStatsService; |
|
|
|
import org.thingsboard.server.dao.exception.IncorrectParameterException; |
|
|
|
import org.thingsboard.server.dao.model.ModelConstants; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
@ -199,6 +205,30 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
|
|
|
return fetchAndConvert(tenantId, entityId, Function.identity()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<EntityId, EntityInfo> fetchEntityInfos(TenantId tenantId, CustomerId customerId, Set<EntityId> entityIds) { |
|
|
|
Map<EntityId, EntityInfo> infos = new HashMap<>(); |
|
|
|
entityIds.stream() |
|
|
|
.collect(Collectors.groupingBy(EntityId::getEntityType)) |
|
|
|
.forEach((entityType, ids) -> { |
|
|
|
EntityListFilter filter = new EntityListFilter(); |
|
|
|
filter.setEntityType(entityType); |
|
|
|
filter.setEntityList(ids.stream().map(Object::toString).toList()); |
|
|
|
EntityDataQuery query = new EntityDataQuery(filter, new EntityDataPageLink(ids.size(), 0, null, null), |
|
|
|
List.of(new EntityKey(EntityKeyType.ENTITY_FIELD, ModelConstants.NAME_PROPERTY)), Collections.emptyList(), Collections.emptyList()); |
|
|
|
|
|
|
|
entityQueryDao.findEntityDataByQuery(tenantId, customerId, query).getData().forEach(entityData -> { |
|
|
|
EntityId entityId = entityData.getEntityId(); |
|
|
|
Optional.ofNullable(entityData.getLatest().get(EntityKeyType.ENTITY_FIELD)) |
|
|
|
.map(fields -> fields.get(ModelConstants.NAME_PROPERTY)) |
|
|
|
.map(TsValue::getValue).ifPresent(name -> { |
|
|
|
infos.put(entityId, new EntityInfo(entityId, name)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return infos; |
|
|
|
} |
|
|
|
|
|
|
|
private <T> Optional<T> fetchAndConvert(TenantId tenantId, EntityId entityId, Function<HasId<?>, T> converter) { |
|
|
|
EntityDaoService entityDaoService = entityServiceRegistry.getServiceByEntityType(entityId.getEntityType()); |
|
|
|
Optional<HasId<?>> entityOpt = entityDaoService.findEntity(tenantId, entityId); |
|
|
|
@ -295,7 +325,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe |
|
|
|
} |
|
|
|
|
|
|
|
if ((query.getEntityFields() == null || query.getEntityFields().isEmpty()) && |
|
|
|
(query.getLatestValues() == null || query.getLatestValues().isEmpty())) { |
|
|
|
(query.getLatestValues() == null || query.getLatestValues().isEmpty())) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|