package com.eactive.eai.rms.onl.common.controller;

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

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;


/**
 * <pre>
 *     1. 기능 : 공통 오늘 날짜 얻기
 *     2. 설명 : 초기 날짜 세팅을 위한 년, 년월, 년월일, 년월일시간
 *              Constants조회 : cmd = Y, M, D, T
 * </pre>
 *
 * @author : music75
 * @version : $Revision: 1.7 $
 * @since : rts 1.0
 */
@Controller
public class CurrentDateController extends BaseController  {
	
	@RequestMapping("/bizcommon/currentDate.do")
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		//

		String cmd       = "";
		String currentYn = "N";
		int    ai_day    = -30;
		int    ai_day2    = -1;
		if(request.getParameter("cmd") != null)       cmd = request.getParameter("cmd");
		if(request.getParameter("currentYn") != null) currentYn = request.getParameter("currentYn");

		if("Y".equals(currentYn)){
			ai_day = 0;
			ai_day2 = 0;
		}
//		try {
//			GauceOutputStream gos = null;
//			//
//			try {
//
//				GauceDataSet dataSet = new GauceDataSet();
//
//				String currentDay = "";
//				if("Y".equals(cmd)){
//					currentDay = DateUtil.getYear(ai_day);
//				}else if("M".equals(cmd)){
//					String month = DateUtil.getMonth(ai_day);
//
//					if(month.equals(DateUtil.getMonth())){
//						month = (Integer.parseInt(month) - 1)+"";
//					}
//
//					month = addZero(month);
//
//					currentDay = DateUtil.getYear(ai_day)+"-"+month;
//				}else if("D".equals(cmd)){
//					String month = DateUtil.getMonth();
//
//					if(DateUtil.getDay().equals("01")){
//						month = (Integer.parseInt(month) - 1)+"";
//					}
//
//					month = addZero(month);
//					String day = DateUtil.getDay(ai_day2);
//					day = addZero(day);
//
//					currentDay = DateUtil.getYear(ai_day)+"-"+month+"-"+day;
//
//				}else if("T".equals(cmd)){
//					String month = DateUtil.getMonth();
//					String day = DateUtil.getDay();
//
//					month = addZero(month);
//					day = addZero(day);
//
//					String Hour = DateUtil.getHour();
//					Hour = addZero(Hour);
//
//					String Minute = DateUtil.getMinute();
//					Minute = addZero(Minute);
//
//					currentDay = DateUtil.getYear(ai_day)+"-"+month+"-"+day+" "+Hour+":"+Minute;
//				}
//				dataSet.put("Date", currentDay, 16,
//						GauceDataColumn.TB_STRING);
//
//				dataSet.heap();
//
//				gos = ((HttpGauceResponse) response)
//					.getGauceOutputStream();
//
//				gos.write(dataSet);
//			} catch (IOException e) {
//				//
//				logger.error("[GAUCE SEND ERROR]");
//				//e.printStackTrace();
//				throw new SysException("[GAUCE SEND ERROR]", e); // 에러발생
//			}finally{
//				if (gos != null)
//				{
//					try
//					{
//						gos.close();
//					}
//					catch (Exception e)
//					{
//						gos = null;
//					}
//				}
//			}
//		} catch (Exception e) {
//			//e.printStackTrace();
//			logger.error("[SYS ERROR]");
//			((HttpGauceResponse) response).addException(e);
//		}
		return null;
	}

	public static String addZero(String str){
		String strRtn = str;
		if(str.length() == 1){
			strRtn = "0"+strRtn;
		}
		return strRtn;
	}
}
