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

/**
 * <pre>
 *     1. 기능 : 평균 응답시간 TOP 10 통계 화면의 컨트롤러
 * </pre>
 *
 * @author : music75
 * @version : $Revision: 1.4 $
 * @since : rts 1.0
 */
@Controller
public class ResponseTimeTopTenController extends BaseController  {

	@Autowired
	@Qualifier("responseTimeTopTenService")
	private ResponseTimeTopTenService responseTimeTopTenService ;

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

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

//		try {
//			findResponseTimeTopTenData(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 findResponseTimeTopTenData(StatisticsForm statisticsForm, HttpServletRequest request,
			HttpServletResponse response) throws Exception {


		List dailyData = responseTimeTopTenService
				.findResponseTimeTop10List(statisticsForm);

//		GauceInputStream gis = null;
//		GauceOutputStream gos = null;
//
//		//
//		try {
//			gis = ((HttpGauceRequest) request)
//					.getGauceInputStream();
//			gos = ((HttpGauceResponse) response)
//					.getGauceOutputStream();
//
//			GauceDataSet dataSet = gis.read("ds_01");
//
//			// 그리드 데이터셋 메핑
//			ResponseTimeTopTenVO vo = new ResponseTimeTopTenVO();
//
//			for (int i = 0; i < dailyData.size(); i++) {
//				vo = (ResponseTimeTopTenVO) dailyData.get(i);
//				dataSet.put("Order", i+1, 3,
//						GauceDataColumn.TB_INT);
//				dataSet.put("EAIBzwkDstcd", vo.getEaiBzwkName(), 4,
//						GauceDataColumn.TB_STRING);
//				dataSet.put("EAISvcName", vo.getEaiSvcName(), 30,
//						GauceDataColumn.TB_STRING);
//				dataSet.put("EAISvcDesc", vo.getEaiSvcDesc(), 200,
//						GauceDataColumn.TB_STRING);
//				dataSet.put("slowTotalCount", vo.getSlowCount(), 15,
//						GauceDataColumn.TB_INT);
//				dataSet.put("SlowCount", vo.getSlowTotalCount(), 15,
//						GauceDataColumn.TB_INT);
//				dataSet.put("Bigo", "", 200,
//						GauceDataColumn.TB_STRING);
//
//				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;
//				}
//			}
//		}
	}
}
