package com.eactive.eai.rms.onl.statistics.system.daily;

import java.util.HashMap;
import java.util.Map;

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.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.eactive.eai.rms.common.spring.BaseController;
import com.eactive.eai.rms.common.util.CamelCaseUtil;
import com.google.gson.Gson;



/**
 * <pre>
 *     1. 기능 : 시스템별 일별 거래현황 통계 화면의 컨트롤러 
 * </pre>
 * 
 * @author : music75
 * @version : $Revision: 1.3 $
 * @since : rts 1.0
 */
@Controller
public class SystemDailyController extends BaseController  {
	
    @Autowired
    @Qualifier("systemDailyService")
    private SystemDailyService service ;
    
	@RequestMapping(value= "/onl/statistics/system/systemDailyMan.view")
	private String viewList(HttpServletRequest request, @RequestParam(value = "cmd", required = false ) String cmd ) throws Exception {
		if (cmd == null || "LIST".equals(cmd.toUpperCase())){
			cmd = "";
		}else {
			cmd = CamelCaseUtil.converCamelCase(cmd);
		}
		String path = request.getServletPath();
		return path.split("[.]")[0]+cmd;
	}      
    
    
    

	@RequestMapping(value= "/onl/statistics/system/systemDailyMan.json",params = "cmd=LIST")
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response,@RequestParam HashMap<String,Object> paramMap) throws Exception {
		
		HashMap<String, Object> map = service.selectList(paramMap);
		
		Map<String, Object> resultMap = new HashMap<String, Object>();

		resultMap.put("rows"		, map.get("list"));
		resultMap.put("totalSum"	, map.get("totalSum"));
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;
	}
	
	@RequestMapping(value= "/onl/statistics/system/systemDailyMan.excel",params = "cmd=LIST_GRID_TO_EXCEL")
	 public ModelAndView listGridToExcel(HttpServletRequest request, HttpServletResponse response, String gridData, String header, String headerTitle, String fileName) throws Exception {
		HashMap<String,Object> resultMap = new HashMap<String,Object>();
		
	   	Gson gson = new Gson();
	   	@SuppressWarnings("unchecked")
		HashMap<String, Object>[] list = gson.fromJson(gridData, HashMap[].class);
   	
		String[] headers = gson.fromJson(header, String[].class);
		String[] headerTitles = gson.fromJson(headerTitle, String[].class);
		
	   	resultMap.put("headers", headers);
	   	resultMap.put("headerTitles", headerTitles);
	   	resultMap.put("datas", list);
	   	resultMap.put("fileName", fileName);
		ModelAndView modelAndView = new ModelAndView("excelView",resultMap);	
       
       return modelAndView;
   }
}
