package com.eactive.eai.rms.onl.statistics.backup.service;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationContext;

import com.eactive.eai.rms.onl.common.util.DateUtil;

public class DailyBackupJob implements Job {
    /**
    * Logger for this class
    */
	private static final Logger logger = Logger.getLogger(DailyBackupJob.class);


    private DailyBackupService dailyBackupService;
    
    /**
     * 1. 통계대상 조회
     * 2. 백업 이력 확인
     * 3. 없으면 이력 INSERT 
     * 4. TSEAIST02 에 데이터 INSERT
     * 5. 성공 이력이면 '이미 백업이 정상적으로 처리 되었습니다.' 메세지만 update
     * 6. 실패면 TSEAIST02 삭제 후 INSERT 결과 UPDATE
     * 
     */    
    
//  @ScheduleMethod(concurrent = false, type = ScheduleType.CRON, cronExpression = "0 0 3 * * ?")
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
        //JobKey jobKey = context.getJobDetail().getKey();

		ApplicationContext appContext = null;
		try {
			appContext = (ApplicationContext)context.getScheduler().getContext().get("applicationContext");
		} catch (SchedulerException e) {
			logger.error("applicationContext get module error",e);
			return ;
		}

		dailyBackupService = (DailyBackupService)appContext.getBean("dailyBackupService");	
		
		String date = DateUtil.getDate(-1);
		dailyBackupService.doAction(date);
	}

}