package com.eactive.eai.rms.onl.statistics.eaisvcname.controller;

import java.util.List;

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.statistics.eaisvcname.service.EaiSvcNameCompareMonthlyService;
import com.eactive.eai.rms.onl.statistics.eaisvcname.vo.StatisticsForm;


/**
 * <pre>
 *     1. 기능 : EAI서비스명 전월대비 통계 화면의 컨트롤러
 * </pre>
 *
 * @author : music75
 * @version : $Revision: 1.5 $
 * @since : rts 1.0
 */
@Controller
public class EaiSvcNameCompareMonthlyController extends BaseController
		 {
	@Autowired
	@Qualifier("eaiSvcNameCompareMonthlyService")
	private EaiSvcNameCompareMonthlyService eaiSvcNameCompareMonthlyService ;

	@RequestMapping("/statistics/eaisvcname/eaiSvcNameCompareMonthly.do")
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		//
		StatisticsForm statisticsForm = new StatisticsForm();

		statisticsForm.setStartDate(request.getParameter("startDate"));

//		try {
//			findEaiSvcNameMonthlyData(statisticsForm, request, response);
//		} catch (BizException be) {
//			//be.printStackTrace();
//			logger.error("[BIZ ERROR]");
//			((HttpGauceResponse) response).addException(be);
//		} catch (SysException se) {
//			//se.printStackTrace();
//			logger.error("[SYS ERROR]");
//			((HttpGauceResponse) response).addException(se);
//		} catch (Exception e) {
//			//e.printStackTrace();
//			logger.error("[SYS ERROR]");
//			((HttpGauceResponse) response).addException(e);
//		}
		return null;
	}

	private void findEaiSvcNameMonthlyData(StatisticsForm statisticsForm,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {


		List listData = eaiSvcNameCompareMonthlyService
				.getFindEaiSvcNameMonthlyData(statisticsForm);

//		GauceInputStream gis = null;
//		GauceOutputStream gos = null;
//
//		//
//		try {
//			gis = ((HttpGauceRequest) request).getGauceInputStream();
//			gos = ((HttpGauceResponse) response).getGauceOutputStream();
//
//			GauceDataSet dataSet = gis.read("ds_01");
//
//			// 그리드 데이터셋 메핑
//			EaiSvcNameCompareMonthlyVO vo = new EaiSvcNameCompareMonthlyVO();
//
//			double sumLastProcAmount = 0;
//			double sumProcAmount = 0;
//			for (int i = 0; i < listData.size(); i++) {
//				vo = (EaiSvcNameCompareMonthlyVO) listData.get(i);
//				sumLastProcAmount += vo.getLastMonthProcColumnName();
//				sumProcAmount += vo.getThisMonthProcColumnName();
//			}
//
//			double lastOccupyRate = 0;
//			double occupyRate = 0;
//			double procRate = 0;
//
//			for (int i = 0; i < listData.size(); i++) {
//				vo = (EaiSvcNameCompareMonthlyVO) listData.get(i);
//				lastOccupyRate = 0;
//				occupyRate = 0;
//				procRate = 0;
//				if (vo.getLastMonthProcColumnName() != 0) {
//					lastOccupyRate = Math.round(vo.getLastMonthProcColumnName()
//							/ sumLastProcAmount * 100 * 100) / 100.;
//				}
//				if (vo.getThisMonthProcColumnName() != 0) {
//					occupyRate = Math.round(vo.getThisMonthProcColumnName()
//							/ sumProcAmount * 100 * 100) / 100.;
//				}
//				if (vo.getLastMonthProcColumnName() != 0) {
//					procRate = Math.round((vo.getThisMonthProcColumnName() - vo
//							.getLastMonthProcColumnName())
//							/ (vo.getLastMonthProcColumnName() * 1.)
//							* 100.
//							* 100.) / 100.;
//				}
//
//				dataSet.put("EaiSvcName", vo.getEaiSvcName(), 30,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.put("EaiSvcDesc", vo.getEaiSvcDesc(), 250,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.put("LastMonthProcColumnName", vo
//						.getLastMonthProcColumnName(), 15,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.put("LastOccupyRate", lastOccupyRate, 15.2,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.put("ThisMonthProcColumnName", vo
//						.getThisMonthProcColumnName(), 15,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.put("OccupyRate", occupyRate, 15.2,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.put("ProcRate", procRate, 15.2,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.put("XLAVEL", vo.getEaiSvcDesc()+" ", 250,
//						GauceDataColumn.TB_NORMAL);
//				dataSet.heap();
//			}
//
//			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;
//				}
//			}
//		}
	}
}
