package com.yutou.nas.utils;

import com.yutou.nas.other.QQSetu;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 服务启动后执行
 */
@Component
public class ApplicationInit implements ApplicationRunner {
    @Resource
    MusicToolsServiceImpl musicTools;

    private static String oldTime = "";

    @Override
    public void run(ApplicationArguments args) throws Exception {
        AudioTools.init();
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                String time = new SimpleDateFormat("HH:mm").format(new Date());
                if (time.equals(oldTime)) {
                    return;
                }
                oldTime = time;
                switch (time) {
                    case "00:00":
                        musicTools.scanMusic();
                        break;
                    case "08:00":
                    case "20:00":
                        QQBotManager.getInstance().reportToDayBangumi();
                        break;
                    case "23:59":
                        QQSetu.printTodaySetu();
                        break;

                }
                switch (time) {
                    case "00:00":
                    case "01:00":
                    case "02:00":
                    case "03:00":
                    case "04:00":
                    case "05:00":
                    case "06:00":
                    case "07:00":
                    case "08:00":
                    case "09:00":
                    case "10:00":
                    case "11:00":
                    case "12:00":
                    case "13:00":
                    case "14:00":
                    case "15:00":
                    case "16:00":
                    case "17:00":
                    case "18:00":
                    case "19:00":
                    case "20:00":
                    case "21:00":
                    case "22:00":
                    case "23:00":
                        BTDownloadManager.getInstance().start();
                }
            }
        }, 0, 35 * 1000);
    }
}
