package com.jjt.task;

import com.jjt.JjtApplication;
import com.jjt.calc.service.ITwinCalcDayYhjService;
import com.jjt.calc.service.ITwinCalcHourYhjService;
import com.jjt.utils.IotService;
import com.jjt.ws.service.ITwinWorkshopCalcService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

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)
//@ActiveProfiles("devp")
public class YhjTaskTest {
    @Resource
    private ITwinCalcDayYhjService dayService;
    @Resource
    private IotService iotService;
    @Resource
    private ITwinCalcHourYhjService yhjService;

    @Resource
    private ITwinWorkshopCalcService wsCalcService;

    @Test
    public void energe() {
        String st = "2025-05-30";
        LocalDate localDate = LocalDate.parse(st);
        wsCalcService.calc(localDate);
    }

    @Test
    public void last() {
        iotService.setToken();
        yhjService.last();
//        String date = "2025-05-28";
//        LocalDate localDate = LocalDate.parse(date);
//        LocalDateTime ldt = LocalDateTime.of(localDate, LocalTime.MIN);
//        for (int i = 7; i < 21; i++) {
//            LocalDateTime tt = ldt.plusHours(i);
//            System.err.println(tt.toLocalDate().toString() + tt.getHour());
//            yhjService.calc(tt.toLocalDate().toString(), tt.getHour());
//        }
    }

    @Test
    public void day(){
        String st = "2025-05-30";
        LocalDate localDate = LocalDate.parse(st);
        dayService.day(localDate);
    }

    @Test
    public void test() {
        iotService.setToken();
        String st = "2025-05-28";
        String ed = "2025-05-30";
        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);
            yhjService.calc(start.toLocalDate().toString(), i);
            if (i == 6) {
                dayService.day(start.toLocalDate().minusDays(1));
            }
            start = start.plusHours(1);
        } while (!start.isAfter(end));
    }
}

