import com.njcn.executor.pojo.vo.DataFlicker;
import com.njcn.influxdb.config.InfluxDbConfig;
import com.njcn.influxdb.utils.InfluxDbUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.influxdb.querybuilder.SelectQueryImpl;
import org.influxdb.querybuilder.WhereNested;
import org.influxdb.querybuilder.WhereQueryImpl;
import org.influxdb.querybuilder.clauses.Clause;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/7/4 19:04
 */
public class Test1 extends BaseJunitTest{

    @Resource
    private InfluxDbConfig influxDbConfig;

    @Test
    public void testMethod(){
        InfluxDbUtils influxDBUtil = new InfluxDbUtils(influxDbConfig.getUser(), influxDbConfig.getPassword(), influxDbConfig.getUrl(), influxDbConfig.getDatabase(), "");
        SelectQueryImpl selectQuery = select().from(influxDbConfig.getDatabase(),"data_flicker").where(eq("fluc",0)).limit(1).tz("Asia/Shanghai");
        WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
        QueryResult queryResult = influxDBUtil.query(selectQuery.getCommand());
        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
        List<DataFlicker> list = resultMapper.toPOJO(queryResult, DataFlicker.class);
        System.out.println("list===:" + list);
    }

    private List<Clause> getClauses() {
        Clause c1 = eq("line_id", "5e467a40023b299070682eb21f2ec9a1");
        Clause c2 = eq("line_id", "183245996f303ebfd80eeb3377cecdc2");
        Clause c3 = eq("line_id", "0d46f54420246e999d5c68b3133f668c");
        return Arrays.asList(c1, c2, c3);
    }

    private void whereAndNested(List<Clause> clauses, WhereQueryImpl<SelectQueryImpl> whereQuery) {
        WhereNested<WhereQueryImpl<SelectQueryImpl>> andNested = whereQuery.andNested();
        for (Clause clause : clauses) {
            andNested.or(clause);
        }
        andNested.close();
    }
}
