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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.eactive.eai.rms.common.spring.BaseController;
import com.eactive.eai.rms.onl.common.util.DateUtil;
import com.eactive.eai.rms.onl.statistics.backup.service.DailyBackupService;
import com.eactive.eai.rms.onl.statistics.backup.service.MonthlyBackupService;
import com.eactive.eai.rms.onl.statistics.backup.service.NewLogDailyBackupService;

/**
 * <pre>
 *     1. 기능 : dailyBackupTest
 * </pre>
 *
 * @author : music75
 * @version : $Revision: 1.4 $
 * @since : rts 1.0
 */
@Controller
public class BackupTestController extends BaseController {
	
	@Autowired
	@Qualifier("dailyBackupService")
	private DailyBackupService dailyBackupService ;

	@Autowired
	@Qualifier("monthlyBackupService")
	private MonthlyBackupService monthlyBackupService ;
	
	@Autowired
	@Qualifier("newLogDailyBackupService")
	private NewLogDailyBackupService newLogDailyBackupService ;

	@RequestMapping("/backup/excute/day.do")
	public ModelAndView DayHandleRequest(HttpServletRequest request,
			HttpServletResponse response,String day,String service) throws Exception {

		try {
			//DataSourceType d = DataSourceTypeManager.getDataSourceType(service);
			if (day == null){
//				dailyBackupService.backup(DateUtil.getDate(-1), d);
				dailyBackupService.doAction(DateUtil.getDate(-1), service);
			}else{
//				dailyBackupService.backup(day, d);//20121212 입력한 일을 통계낸다
				dailyBackupService.doAction(day, service);//20121212 입력한 일을 통계낸다
			}
		} catch (Exception e) {
			logger.error("DayHandleRequest Error", e);
		}
		
		return null;
	}
	@RequestMapping("/backup/excute/month.do")
	public ModelAndView monthHandleRequest(HttpServletRequest request,
			HttpServletResponse response,String month) throws Exception {
		try {
			if (month == null){
//				monthlyBackupService.backup(DateUtil.getDate());
				monthlyBackupService.doAction(DateUtil.getDate());
			}else{
//				monthlyBackupService.backup(month);//201212  입력한 달을 통계낸다
				monthlyBackupService.doAction(month);//201212  입력한 달을 통계낸다
			}
		} catch (Exception e) {
			logger.error("monthHandleRequest Error", e);
		}
		return null;
	}	
	@RequestMapping("/backup/excute/dayForNewLog.do")
	public ModelAndView DayForNewLogHandleRequest(HttpServletRequest request,
			HttpServletResponse response,String day,String service) throws Exception {

		try {
			if (day == null){
				newLogDailyBackupService.doAction(DateUtil.getDate(-1), service);
			}else{
				newLogDailyBackupService.doAction(day, service);
			}
		} catch (Exception e) {
			logger.error("DayHandleRequest Error", e);
		}
		
		return null;
	}
}
