package com.jjt.task;

import com.jjt.JjtApplication;
import com.jjt.biz.domain.TwinDevice;
import com.jjt.biz.service.IApiService;
import com.jjt.biz.service.ITwinDeviceService;
import com.jjt.calc.service.ITwinCalcDayService;
import com.jjt.emp.service.ITwinEmpCalcService;
import com.jjt.utils.AsyncService;
import com.jjt.utils.IotService;
import com.jjt.utils.Tools;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * DataProcess$
 *
 * @author wukai
 * @date 2024/5/7 11:49
 */
@SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class DjbTest {
    @Resource
    private IApiService apiService;

    @Resource
    private ITwinDeviceService deviceService;
    @Resource
    private AsyncService asyncService;
    @Resource
    private ITwinCalcDayService dayService;
    @Resource
    private ITwinEmpCalcService empCalcService;
    @Resource
    private IotService iotService;


    @Test
    public void test() throws ExecutionException, InterruptedException {
        LocalDateTime ldt = Tools.currWholeTime();
        //上一个小时
        ldt = ldt.minusHours(1);
        //开始时间需要向前取一秒
        LocalDateTime start = ldt.minusSeconds(1);
        LocalDateTime end = ldt.plusHours(1);
        iotService.setToken();
        TwinDevice twinDevice = deviceService.selectTwinDeviceByDeviceId(175L);
        List<Future<Map<String, List<?>>>> futureList = new ArrayList<>();
        Future<Map<String, List<?>>> future = asyncService.process(twinDevice, start, end);
        futureList.add(future);
        // 等待异步任务完成
        future.get();
    }

}

