package com.trs.ggzyexchange.schedul;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.trs.ggzyexchange.enums.JobLock;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

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

@Component
public class TestSchedul implements Job {

    private Logger logger = LoggerFactory.getLogger(TestSchedul.class);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            System.out.println(JobLock.JobFlag);
            if(JobLock.JobFlag){
                JobLock.JobFlag = false;
                System.out.println("定时任务");
                try {
                    Thread.sleep(10000);
                }catch (Exception e){
                    e.printStackTrace();
                }
                logger.info("当前时间1111111111111111111111111========================：{}", new SimpleDateFormat().format(new Date()));
                JobLock.JobFlag = true;
            }else {
                System.out.println("不执行任务");
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
