package njcn;


import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.njcn.influx.bo.po.InfluxDBDataFlicker;
import com.njcn.influx.core.InfluxExecutor;
import com.njcn.influx.imapper.InfluxDBDataFlickerMapper;
import com.njcn.oracle.bo.param.MigrationParam;
import com.njcn.oracle.bo.po.DataFlicker;
import com.njcn.oracle.mybatis.service.IReplenishMybatisService;
import lombok.SneakyThrows;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年12月14日 12:55
 */
public class DataTest extends BaseJunitTest {
    private @Autowired InfluxDBDataFlickerMapper influxDBDataFlickerMapper;



    @SneakyThrows
    @Test
    public void testBean() {
        LocalDateTime endTime = LocalDateTimeUtil.parse("2023-12-29 15:00:10", DatePattern.NORM_DATETIME_PATTERN);
        LocalDateTime startTime = LocalDateTimeUtil.offset(endTime, -24, ChronoUnit.HOURS);

//        LocalDateTime endTime = LocalDateTimeUtil.parse("1970-01-02 00:00:10", DatePattern.NORM_DATETIME_PATTERN);
//        LocalDateTime startTime = LocalDateTimeUtil.offset(endTime, -2, ChronoUnit.HOURS);
        List<InfluxDBDataFlicker> dataFlickers = new ArrayList<>();
        InfluxDBDataFlicker flicker1 = new InfluxDBDataFlicker();
        flicker1.setTime(Instant.now().minusSeconds(60*60*24*50));
        flicker1.setLineId("12345");
        flicker1.setPhaseType("A");
        flicker1.setFluc(1.0f);
        flicker1.setPlt(1.0f);
        flicker1.setPst(1.0f);
        flicker1.setQualityFlag("1");
        InfluxDBDataFlicker flicker2 = new InfluxDBDataFlicker();
        flicker2.setTime(Instant.now().minusSeconds(60*60*24*24));
        flicker2.setLineId("12345");
        flicker2.setPhaseType("A");
        flicker2.setFluc(1.0f);
        flicker2.setPlt(1.0f);
        flicker2.setPst(1.0f);
        flicker2.setQualityFlag("1");
        dataFlickers.add(flicker1);
        dataFlickers.add(flicker2);
        influxDBDataFlickerMapper.insertBatch(dataFlickers);
//        MigrationParam migrationParam = new MigrationParam();
//        migrationParam.setStartTime(startTime);
//        migrationParam.setEndTime(endTime);
//        IReplenishMybatisService executor = (IReplenishMybatisService) SpringUtil.getBean(Class.forName("com.njcn.oracle.service.impl.DataFlickerServiceImpl"));
//        //查询数据
//        List<DataFlicker> temp1 = executor.queryData(migrationParam);
//        List<InfluxDBDataFlicker> collect = temp1.stream().map(temp -> {
//            InfluxDBDataFlicker dataFlicker = new InfluxDBDataFlicker();
//            dataFlicker = InfluxDBDataFlicker.oralceToInfluxDB(temp);
//
//            return dataFlicker;
//        }).collect(Collectors.toList());
//
//        Object args[] ={collect};
//        interpreter.insert(args);
//        System.out.println(1111111);

    }



}
