package com.yihu.wlyy.statistics.job.cache;

import com.yihu.wlyy.statistics.etl.mycache.CachePool;
import com.yihu.wlyy.statistics.etl.storage.DBStorage;
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

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

/**
 * Created by Administrator on 2016.10.19.
 */

@Component
@Scope("prototype")
public class CacheCleanJob implements Job {
    public static String jobKey="CLEAN_CACHE_JOB";
    public static String cron="0 55 23 * * ?";
    @Autowired
    private DBStorage dbStorage;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        QuartzJobLog quartzJobLog = new QuartzJobLog();
        quartzJobLog.setJobStartTime(new Date());
        quartzJobLog.setJobId(jobKey);
        quartzJobLog.setJobName(jobKey);
        CachePool.cleanAllCache();
        quartzJobLog.setJobEndTime(new Date());
        quartzJobLog.setJobContent("清空缓存成功:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        quartzJobLog.setJobType("1");
        dbStorage.saveLog(quartzJobLog);
    }

}
