package com.jjt.stop;

import com.jjt.JjtApplication;
import com.jjt.biz.domain.TwinDevice;
import com.jjt.biz.service.ITwinDeviceService;
import com.jjt.calc.service.ITwinCalcStopService;
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;
import java.util.List;

/**
 * StopTest$
 *
 * @author wukai
 * @date 2025/3/20 00:48
 */
@SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class StopTest {
    @Resource
    ITwinDeviceService deviceService;
    @Resource
    ITwinCalcStopService stopService;

    @Test
    void test() {
        TwinDevice search = new TwinDevice();
        //查询所有在线的设备
        search.setOnline("1");
        //TODO 临时设置单个设备，上线需取消
        search.setDeviceId(1L);
        List<TwinDevice> list = deviceService.selectTwinDeviceList(search);

        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();
            stopService.process(start, start.plusHours(1), list);
            start = start.plusHours(1);
        } while (!start.isAfter(end));
    }
}
