package com.eactive.eai.rms.onl.statistics.eaisvcname.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.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.google.gson.Gson;

@Controller
public class EaiSvcNameDailyController extends BaseController {

	private EaiSvcNameDailyService service;

	@Autowired
	public EaiSvcNameDailyController(EaiSvcNameDailyService service) {
		this.service = service;
	}

	@RequestMapping(value = "/onl/statistics/eaisvcname/eaiSvcNameDailyMan.view")
	public String viewList() {
		return "/onl/statistics/eaisvcname/eaiSvcNameDailyMan";
	}

	@RequestMapping(value = "/onl/statistics/eaisvcname/eaiSvcNameDailyMan.view", params = "cmd=DETAIL")
	public String viewDetail() {
		return "/onl/statistics/eaisvcname/eaiSvcNameDailyManDetail";
	}

	@RequestMapping(value = "/onl/statistics/eaisvcname/eaiSvcNameDailyMan.json", params = "cmd=LIST")
	public ModelAndView handleRequest(@RequestParam Map<String, Object> paramMap) throws Exception {

		Map<String, Object> map = service.selectByEaiSvcNameDaily(paramMap);

		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("rows", map.get("list"));
		resultMap.put("totalSum", map.get("totalSum"));

		return new ModelAndView("jsonView", resultMap);

	}

	@RequestMapping(value = "/onl/statistics/eaisvcname/eaiSvcNameDailyMan.excel", params = "cmd=LIST_GRID_TO_EXCEL")
	public ModelAndView listGridToExcel(HttpServletRequest request, HttpServletResponse response, String gridData,
			String header, String headerTitle, String fileName) {

		HashMap<String, Object> resultMap = new HashMap<>();

		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);

		return new ModelAndView("excelView", resultMap);

	}

}
