package com.eactive.eai.rms.onl.manage.comm.mapping;

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

import javax.servlet.http.HttpServletRequest;

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.eactive.eai.rms.common.vo.JsonPageVo;

@Controller
public class TranCodeMapController extends BaseController {

    @Autowired
    @Qualifier("tranCodeMapService")
    private TranCodeMapService service;
    
	@RequestMapping(value= "/onl/admin/common/tranCodeMapMan.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;
	}    
	/**
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value= "/onl/admin/common/tranCodeMapMan.json", params = "cmd=LIST")
	private ModelAndView selectList(HttpServletRequest request,
			JsonPageVo pageVo ,String searchTranCode, String searchEaiSvcCode , String searchEaiSvcCodeDesc) throws Exception {
		
		HashMap map = new HashMap();
		if (searchTranCode != null && searchEaiSvcCode != null && searchEaiSvcCodeDesc != null) {
			map = service.selectList( pageVo.getStartNum(), pageVo.getEndNum(),searchTranCode, searchEaiSvcCode, searchEaiSvcCodeDesc);
		}
		
		pageVo.setTotalCount((Integer)map.get("totalCount"));
		
		Map resultMap = new HashMap();
		resultMap.put("total"  , pageVo.getTotal());  //전체 페이지수
		resultMap.put("page"   , pageVo.getPage());   //현재 페이지수
		resultMap.put("records", pageVo.getTotalCount());//전체 레코드건수	
		resultMap.put("rows"   , map.get("list"));
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;
	}
}
