package com.dbs.mplus.controller.mobile;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dbs.mplus.exception.mobile.ApiCallException;
import com.dbs.mplus.exception.mobile.MobileControllerException;
import com.dbs.mplus.framework.exception.MPlusServiceException;
import com.dbs.mplus.framework.service.menu.ServiceMenu;
import com.dbs.mplus.framework.template.AbstractController;
import com.dbs.mplus.service.api.MPlusApi;
import com.dbs.mplus.service.api.MPlusApiCallService;

/**
 * 진료
 * 
 * @author seokhwan.chon
 *
 */
@Controller
@RequestMapping("/mobile/deployment")
@ServiceMenu(menuId="deployment", description="APP배포")
public class DeploymentController extends AbstractController {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private MPlusApiCallService apiCallService;
	
	/**
	 * 재원환자 조회
	 * 
	 * @param request
	 * @param response
	 * @param reqMap
	 */
	@RequestMapping(value = "/inputDownloadLog.json", method = RequestMethod.POST)
	public Map<String, Object> inputDownloadLog(HttpServletRequest request, HttpServletResponse response,
			@RequestBody Map<String, Object> reqMap) throws MobileControllerException {
		// 접근권한 및 파라미터 정리
		try {
			reqMap = super.isAccessableMenu(this.getClass(), request, reqMap);
			
		} catch (MPlusServiceException ex) {
			throw new MobileControllerException(ex.getCode(), ex.getMessage());
		}
		
		// 20180612 shinsunwoo 세션에서 병원구분코드를 가져와서 추가함
		reqMap.put("hospitalCd", reqMap.get("mpUserHospital"));

		// 실행
		try {
			return this.apiCallService.call(MPlusApi.DEPLOYMENT_INPUTDOWNLOADLOG , reqMap);
		} catch (ApiCallException ex) {
			if (this.logger.isDebugEnabled()) {
				this.logger.debug("예외발생", ex);
			}

			throw new MobileControllerException(ex.getCode(), ex.getMessage());
		}
	}

}
