package com.jiayue.insu.inclientqn.service;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.RandomUtil;
import com.jiayue.insu.inclientqn.BaseTest;
import com.jiayue.insu.inclientqn.entity.BackForeForecastData;
import com.jiayue.insu.inclientqn.entity.BackForeUsForecastData;
import com.jiayue.insu.inclientqn.entity.BackStatData;
import com.jiayue.insu.inclientqn.inenum.QNHLEnum;
import com.jiayue.insu.inclientqn.service.client.BackDataAnalysisService;
import com.jiayue.insu.inclientqn.service.client.BackDataGenService;
import com.jiayue.insu.inclientqn.service.client.RequestDataService;
import com.jiayue.insu.inclientqn.util.DateTimeUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class BackDataGenServiceTest extends BaseTest {
    @Autowired
    BackDataGenService backDataGenService;
    @Autowired
    private RequestDataService requestDataService;
    @Autowired
    private BackForeUsForecastDataService backForeUsForecastDataService;
    @Autowired
    private BackForeForecastDataService backForeForecastDataService;
    @Autowired
    private BackDataAnalysisService backDataAnalysisService;
    @Autowired
    private BackStatDataService backStatDataService;
    @Test
    void test() {
        try {
            //backDataGenService.genStateRealPowerData("test");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Test
    void test1() {
        try {
            //backDataGenService.genStateRealWeatherData("test","E1");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    @Test
    void test2() {
        try {
            long time = DateTimeUtils.get15min(DateUtil.date().getTime());
            LocalDateTime localDateTime = LocalDateTimeUtil.of(time);
            requestDataService.requestBackStatData(QNHLEnum.DATA_STAT_TYPE_RealWeather, time);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Test
    void test3() {
        cdq();

    }




    @Test
    void test4() {
        dq();

    }

    private void cdq() {
        try {
            LocalDateTime signTime = LocalDateTimeUtil.of(DateTimeUtils.get15min(DateTime.now().getTime()));
            List<BackForeUsForecastData> list = new ArrayList<>();
            for (int i = 1; i <= 16; i++) {
                BackForeUsForecastData backForeUsForecastData = new BackForeUsForecastData();
                backForeUsForecastData.setSignTime(signTime);
                backForeUsForecastData.setForecastTime(signTime.plusMinutes(15 * i));
                backForeUsForecastData.setForecastValue(RandomUtil.randomBigDecimal(new BigDecimal(50)));
                backForeUsForecastData.setForecastOpenCap(new BigDecimal("50"));
                list.add(backForeUsForecastData);
            }

            backForeUsForecastDataService.saveBatch(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private void stat() {
        try {
            LocalDateTime signTime = LocalDateTimeUtil.of(DateTimeUtils.get15min(DateTime.now().getTime()));
            BackStatData backStatData =new BackStatData();
            backStatData.setSignTime(signTime);


            backStatDataService.save(backStatData);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void dq() {
        try {
            LocalDateTime beginOfDay = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
            LocalDateTime forecastTime = beginOfDay.plusDays(1);
            List<BackForeForecastData> list = new ArrayList<>();
            for (int i = 0; i < 288; i++) {
                BackForeForecastData backForeForecastData = new BackForeForecastData();
                backForeForecastData.setSignTime(beginOfDay);
                backForeForecastData.setForecastTime(forecastTime.plusMinutes(15 * i));
                backForeForecastData.setForecastValue(RandomUtil.randomBigDecimal(new BigDecimal(50)));
                backForeForecastData.setForecastOpenCap(new BigDecimal("50"));
                list.add(backForeForecastData);
            }

            backForeForecastDataService.saveBatch(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
