|
|
|
@ -23,15 +23,25 @@ import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.query.AlarmData; |
|
|
|
import org.thingsboard.server.common.data.query.AlarmDataQuery; |
|
|
|
import org.thingsboard.server.common.data.query.EntityCountQuery; |
|
|
|
import org.thingsboard.server.common.data.query.EntityData; |
|
|
|
import org.thingsboard.server.common.data.query.EntityDataPageLink; |
|
|
|
import org.thingsboard.server.common.data.query.EntityDataQuery; |
|
|
|
import org.thingsboard.server.dao.attributes.AttributesService; |
|
|
|
import org.thingsboard.server.dao.timeseries.TimeseriesService; |
|
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
|
import org.thingsboard.server.service.query.EntityQueryService; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@TbCoreComponent |
|
|
|
@RequestMapping("/api") |
|
|
|
@ -40,6 +50,12 @@ public class EntityQueryController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private EntityQueryService entityQueryService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AttributesService attributesService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TimeseriesService timeseriesService; |
|
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/entitiesQuery/count", method = RequestMethod.POST) |
|
|
|
@ -76,4 +92,39 @@ public class EntityQueryController extends BaseController { |
|
|
|
throw handleException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/entitiesQuery/find/keys/timeseries", method = RequestMethod.POST) |
|
|
|
@ResponseBody |
|
|
|
public List<String> findEntityTimeseriesKeysByQuery(@RequestBody EntityDataQuery query) throws ThingsboardException { |
|
|
|
TenantId tenantId = getTenantId(); |
|
|
|
return getKeys(query, entityIds -> timeseriesService.findAllKeysByEntityIds(tenantId, entityIds)); |
|
|
|
} |
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
@RequestMapping(value = "/entitiesQuery/find/keys/attributes", method = RequestMethod.POST) |
|
|
|
@ResponseBody |
|
|
|
public List<String> findEntityAttributesKeysByQuery(@RequestBody EntityDataQuery query) throws ThingsboardException { |
|
|
|
TenantId tenantId = getTenantId(); |
|
|
|
return getKeys(query, entityIds -> attributesService.findAllKeysByEntityIds(tenantId, entityIds.get(0).getEntityType(), entityIds)); |
|
|
|
} |
|
|
|
|
|
|
|
private List<String> getKeys(EntityDataQuery query, Function<List<EntityId>, List<String>> function) throws ThingsboardException { |
|
|
|
checkNotNull(query); |
|
|
|
try { |
|
|
|
EntityDataPageLink pageLink = query.getPageLink(); |
|
|
|
if (pageLink.getPageSize() > 100) { |
|
|
|
pageLink.setPageSize(100); |
|
|
|
} |
|
|
|
List<EntityId> ids = this.entityQueryService.findEntityDataByQuery(getCurrentUser(), query).getData().stream() |
|
|
|
.map(EntityData::getEntityId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
if (ids.isEmpty()) { |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
return function.apply(ids); |
|
|
|
} catch (Exception e) { |
|
|
|
throw handleException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|