package com.eactive.eai.rms.bap.adaptor.socket;

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.base.BapBaseAnnotationController;
import com.eactive.eai.rms.common.util.CamelCaseUtil;

@Controller
public class BapInstStatusController extends BapBaseAnnotationController  {

	@Autowired
	@Qualifier("bapInstStatusService")
	private BapInstStatusService bapInstStatusService;
	
	@RequestMapping(value= "/bap/adapter/socket/instStatus.view")
	public 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= "/bap/adapter/socket/instStatus.json", params = "cmd=LIST")
	public ModelAndView selectList(HttpServletRequest request) throws Exception {
		
		HashMap<String, Object> map = bapInstStatusService.selectList();
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("rows"   , map.get("list"));
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;
		
	}
}