package com.muyu.carData.config.lotdbconfig;

import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.session.pool.SessionPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author：张腾
 * @Package：com.muyu.carData.lotdbconfig
 * @Project：cloud-server-8
 * @name：IotDBSessionConfig
 * @Date：2024/9/27 12:25
 * IotDB线程池
 */
@Component
@Configuration
public class IotDBSessionConfig {

    private static Logger logger = LoggerFactory.getLogger(IotDBSessionConfig.class);

    /**
     * 用户名
     */
    @Value("${spring.iotdb.username}")
    private String username;

    /**
     * 密码
     */
    @Value("${spring.iotdb.password}")
    private String password;

    /**
     * ip地址
     */
    @Value("${spring.iotdb.ip}")
    private String ip;

    /**
     * 端口号
     */
    @Value("${spring.iotdb.port}")
    private Integer port;

    /**
     * 最大连接数
     */
    @Value("${spring.iotdb.maxSize}")
    private Integer maxSize;


    /**
     * 默认每次查询的条数
     */
    @Value("${spring.iotdb.fetchSize}")
    private int fetchSize;


    @Bean
    public Session iotSession(){
        Session session = new Session(ip, port, username, password);
        try {
            session.open();
        } catch (IoTDBConnectionException e) {
            logger.error(String.valueOf(e.getCause()));
        }
        return session;
    }









}
