package com.pj.current;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.pj.api.jh.task.StartUpCheckPayStatusTask;
import com.pj.current.config.WxConfig;
import com.pj.current.task.TaskService;
import com.pj.current.task.TokenTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * springboot启动之后
 *
 * @author kong
 */
@Component
@Slf4j
public class SaPlusStartup implements CommandLineRunner {

    @Value("${spring.application.name:sa-plus}")
    private String applicationName;

    @Value("${server.port:8080}")
    private String port;

    @Value("${server.servlet.context-path:}")
    private String path;

    @Value("${spring.profiles.active:}")
    private String active;
    @Resource
    private ThreadPoolTaskScheduler threadPoolTaskScheduler;
    @Resource
    TokenTask tokenTask;
    @Resource
    WxConfig wxConfig;

    @Resource
    TaskService taskService;

    @Override
    public void run(String... args){
        tokenTask.run();
        threadPoolTaskScheduler.scheduleAtFixedRate(tokenTask, wxConfig.getFlushSecond() * 1000);
        taskService.addTask(new StartUpCheckPayStatusTask("=========检查正在支付订单状态========",2000L));
    }


    /**
     * 返回系统当前时间的YYYY-MM-dd hh:mm:ss 字符串格式
     */
    private static String getNow() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }


}

