package com.jjt.task;

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

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

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

    @Resource
    private ITwinCalcHourService calcHourService;
    @Resource
    private ITwinCalcDayService dayService;
    @Resource
    private ITwinEmpCalcService empCalcService;
    @Resource
    private IotService iotService;

    @Test
    public void curr() {
        apiService.curr();
    }


    @Test
    public void last() {
        iotService.setToken();
//        String date = "2025-02-26";
//        LocalDate localDate = LocalDate.parse(date);
//        dayService.day(localDate);
//        dayService.day(LocalDate.parse("2025-02-23"));
//        dayService.day(LocalDate.parse("2025-02-24"));
//        dayService.day(LocalDate.parse("2025-03-16"));
        for (int i = 1; i < 19; i++) {
            String d = "2025-03-" + (i < 10 ? "0" + i : i);
            dayService.day(LocalDate.parse(d));
        }
////        empCalcService.calc(DateUtils.toDate(localDate));
//        LocalDateTime ldt = LocalDateTime.of(localDate, LocalTime.MIN);
//        for (int i = 11; i < 15; i++) {
//            LocalDateTime tt = ldt.plusHours(i);
//            System.err.println(tt.toLocalDate().toString() + tt.getHour());
//            calcHourService.calc(tt.toLocalDate().toString(), tt.getHour());
//        }

//        calcHourService.calc("2025-02-24", 14);

//        calcHourService.last();
    }

    @Test
    public void test() {
        iotService.setToken();
        String st = "2025-03-16";
        String ed = "2025-03-16";
        LocalDate localDate = LocalDate.parse(st);
        LocalDate endDate = LocalDate.parse(ed);
        LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(7);
        LocalDateTime end = LocalDateTime.of(endDate.plusDays(1), LocalTime.MIN).plusHours(6);
        LocalDateTime curr = LocalDateTime.now();
        if (end.isAfter(curr)) {
            end = curr.minusHours(1);
        }
        do {
            int i = start.getHour();
            System.err.println(start.toLocalDate().toString() + "\t" + i);
            calcHourService.calc(start.toLocalDate().toString(), i);
            if (i == 6) {
                dayService.day(start.toLocalDate().minusDays(1));
            }
            start = start.plusHours(1);
        } while (!start.isAfter(end));
    }
}

