in backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java [466:545]
public BaseVO<MeasuremtnInfoVO> getMeasurementsByDeviceName(
@PathVariable("serverId") Integer serverId,
@PathVariable("groupName") String groupName,
@PathVariable("deviceName") String deviceName,
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(value = "keyword", required = false) String keyword,
HttpServletRequest request)
throws BaseException {
checkParameter(groupName, deviceName);
check(request, serverId);
Connection connection = connectionService.getById(serverId);
CountDTO countDTO =
iotDBService.getMeasurementsByDevice(connection, deviceName, pageSize, pageNum, keyword);
List<MeasurementDTO> measurementDTOList = countDTO.getObjects();
List<MeasurementVO> measurementVOList = new ArrayList<>();
String host = connection.getHost();
if (measurementDTOList != null) {
List<String> timeseriesList = new ArrayList<>();
for (MeasurementDTO measurementDTO : measurementDTOList) {
timeseriesList.add(measurementDTO.getTimeseries());
}
List<String> batchNewValue =
iotDBService.getBatchLastMeasurementValue(connection, timeseriesList);
List<String> batchDataCount =
iotDBService.getBatchDataCount(connection, deviceName, timeseriesList);
int index = 0;
for (MeasurementDTO measurementDTO : measurementDTOList) {
MeasurementVO measurementVO = new MeasurementVO();
BeanUtils.copyProperties(measurementDTO, measurementVO);
String description =
measurementService.getDescription(host, measurementDTO.getTimeseries());
if (batchNewValue.size() != 0) {
measurementVO.setNewValue(batchNewValue.get(index));
}
if (batchDataCount.size() != 0) {
measurementVO.setDataCount(Integer.parseInt(batchDataCount.get(index)));
}
measurementVO.setDescription(description);
ObjectMapper mapper = new ObjectMapper();
List<List<String>> tags = new ArrayList<>();
List<List<String>> attributes = new ArrayList<>();
try {
if (!"null".equals(measurementDTO.getTags())) {
Map<String, String> tagsMap = mapper.readValue(measurementDTO.getTags(), Map.class);
for (String key : tagsMap.keySet()) {
List<String> tag = new ArrayList<>();
tag.add(key);
tag.add(tagsMap.get(key));
tags.add(tag);
}
}
measurementVO.setTags(tags);
if (!"null".equals(measurementDTO.getAttributes())) {
Map<String, String> attributesMap =
mapper.readValue(measurementDTO.getAttributes(), Map.class);
for (String key : attributesMap.keySet()) {
List<String> attribute = new ArrayList<>();
attribute.add(key);
attribute.add(attributesMap.get(key));
attributes.add(attribute);
}
}
measurementVO.setAttributes(attributes);
} catch (JsonProcessingException e) {
log.error(e.getMessage());
throw new BaseException(ErrorCode.GET_MSM_FAIL, ErrorCode.GET_MSM_FAIL_MSG);
}
measurementVOList.add(measurementVO);
index++;
}
}
MeasuremtnInfoVO measuremtnInfoVO = new MeasuremtnInfoVO();
measuremtnInfoVO.setTotalCount(countDTO.getTotalCount());
measuremtnInfoVO.setTotalPage(countDTO.getTotalPage());
measuremtnInfoVO.setMeasurementVOList(measurementVOList);
return BaseVO.success("Get successfully", measuremtnInfoVO);
}