Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2022 www.mobaijun.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mobaijun.influxdb.util;
import com.mobaijun.influxdb.annotation.Aggregate;
import com.mobaijun.influxdb.annotation.Count;
import com.mobaijun.influxdb.core.Query;
import com.mobaijun.influxdb.core.constant.Constant;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import org.influxdb.dto.Point;
import org.influxdb.dto.QueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
/**
* Software:IntelliJ IDEA 2021.3.2
* ClassName: InfluxdbUtils
* 类描述: influxdb 工具类
*
* @author MoBaiJun 2022/4/29 14:29
*/
public class InfluxdbUtils {
/**
* logger
*/
private static final Logger log = LoggerFactory.getLogger(InfluxdbUtils.class);
/**
* 将queryResult 转换为实体对象List
* influxdb-java 本身提供了 InfluxDBResultMapper.toPOJO(queryResult, clazz);
* 上述方式得用 Instant 时间就很难受
*
* @param queryResult queryResult
* @param clazz final Class
* @param List
* @return List
*/
public static List toPojo(final QueryResult queryResult, final Class clazz) {
Objects.requireNonNull(queryResult, Constant.QUERY_RESULT);
Objects.requireNonNull(clazz, Constant.CLAZZ);
List results = new LinkedList<>();
for (QueryResult.Result result : queryResult.getResults()) {
if (Objects.nonNull(result.getSeries())) {
for (QueryResult.Series series : result.getSeries()) {
List columns = series.getColumns();
int fieldSize = columns.size();
for (List