package com.madeu.controller.web.webreserve;

import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.madeu.constants.Constants;
import com.madeu.init.ManagerDraftAction;
import com.madeu.service.web.webloghistory.WebLogHistoryService;
import com.madeu.service.web.webreserve.WebReserveService;
import com.madeu.util.HttpUtil;
import com.madeu.util.RequestLogUtil;
import com.madeu.view.web.WebReserveColumnView;
import com.madeu.view.web.WebReserveUserHistoryView;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@Controller
public class WebReserveController extends ManagerDraftAction{

	@Autowired
	private WebReserveService webReserveService;
	
	@Autowired
	private WebLogHistoryService webLogHistoryService;
	
	@Autowired
	ResourceLoader resourceLoader;

	/**
	 * 고객 - 1년간 진료내역 조회 (수납완료건) (List, option)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectListReserveUserOption.do")
	public ModelAndView selectListReserveUserOption(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectListReserveUserOption START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectListReserveUserOption(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectListReserveUserOption END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 예약현황 상태별 건수 조회 (count)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectTotalReserveStatusCount.do")
	public ModelAndView selectTotalReserveStatusCount(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectTotalReserveStatusCount START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectTotalReserveStatusCount(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectTotalReserveStatusCount END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 예약현황 정보 리스트 조회
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectListReserve.do")
	public ModelAndView selectListReserve(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectListReserve START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectListReserve(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectListReserve END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	/**
	 * 병원휴일 정보 리스트 조회
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectHospitalHoliday.do")
	public ModelAndView selectListHospitalHoliday(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectListHospitalHoliday START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectHospitalHoliday(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectListHospitalHoliday END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 상태별 예약현황 정보 리스트 조회
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectListReserveStatus.do")
	public ModelAndView selectListReserveStatus(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectListReserveStatus START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectListReserveStatus(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectListReserveStatus END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 예약현황 정보 상세 조회 (one)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectReserve.do")
	public ModelAndView selectReserve(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectReserve START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectReserve(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectReserve END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 고객 해당 일자 예약현황 정보 상세 조회 (one)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectReserveUser.do")
	public ModelAndView selectReserveUser(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectReserveUser START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectReserveUser(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectReserveUser END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 고객 해당 일자 미수납건 조회(List)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectListReserveUserNoPayment.do")
	public ModelAndView selectListReserveUserNoPayment(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectListReserveUserNoPayment START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectListReserveUserNoPayment(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectListReserveUserNoPayment END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 고객 상세 - 고객 예약내역 리스트 화면으로 이동.
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/webreserve/selectListReserveUserHistoryIntro.do")
	public String selectListReserveUserHistoryIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
		log.debug("WebReserveController  selectListReserveUserHistoryIntro START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try {
			if (!webCheckLogin(session)) {
				return "/web/login/logout";
			} else {
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectListReserveUserHistoryIntro(paramMap);
				
				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
				model.addAttribute("muMemberId", paramMap.get("loginMemberId"));
			}
		}
			catch (Exception e) {
			e.printStackTrace();
			return "/web/login/logout";
		}
		log.debug("WebReserveController  selectListReserveUserHistoryIntro END");
		return "/web/user/userReserveHistorySelectList";
	}
	
	/**
	 * 고객 상세 - 고객 예약내역 리스트 조회 (List)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/selectListReserveUserHistory.do")
	public ModelAndView selectListReserveUserHistory(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController selectListReserveUserHistory START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.selectListReserveUserHistory(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
		}
		log.debug("WebReserveController selectListReserveUserHistory END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * <b>고객 상세 - 고객 예약내역 리스트 엑셀 다운로드 </b>
	 * 페이지 처리 없음 
	 * request: 
	 * response : msgCode, msgDesc
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/downloadReserveUserHistoryExcel.do")
	public ModelAndView downloadReserveUserHistoryExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file, Model model) {
		log.debug("WebReserveController downloadReserveUserHistoryExcel START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		List<Map<String, Object>> selectListReport = new ArrayList<Map<String,Object>>();
		Map<String, Object> map = new HashMap<String,Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				selectListReport = webReserveService.selectListReserveUserHistoryExcel(paramMap);
				map.put("selectListReserveUserHistory", selectListReport);
				map.put("name", "reserveUserHistory");
			}
		}
		catch(Exception e){
			e.printStackTrace();
			return null;
		}
		log.debug("WebReserveController downloadReserveUserHistoryExcel END");
		return new ModelAndView(new WebReserveUserHistoryView(),"map",map);
	}
	
	/**	
	 * 예약현황 정보 등록 (예약 등록)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/insertReserve.do")
	public ModelAndView insertReserve(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebReserveController insertReserve START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();

		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.insertReserve(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}

			try {
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				HashMap<String, Object> insertMap = new HashMap<String, Object>();
	
				insertMap.put("url", "/webreserve/insertReserve.do");
				insertMap.put("func", "insertReserve");
				insertMap.put("funcName", "예약현황 등록");
				insertMap.put("service", "webReserveService");
				insertMap.put("serviceName", "예약현황 등록");
				insertMap.put("requestValue", String.valueOf(paramMap));
				insertMap.put("responseValue", String.valueOf(map));
				insertMap.put("tId", map.get("tId"));
				if((String.valueOf(errorMsg)).equals("") || (String.valueOf(errorMsg) == null) || String.valueOf(errorMsg).length() == 0){
					insertMap.put("resultCode", "SUCCESS");
				}
				else{
					insertMap.put("resultCode", "ERROR");
				}
				insertMap.put("resultMsg", String.valueOf(errorMsg));
				insertMap.put("muMemberId", paramMap.get("loginMemberId"));
	
				webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		log.debug("WebReserveController insertReserve END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**	
	 * 예약현황 정보 등록 (간편예약 등록)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/insertReserveSimple.do")
	public ModelAndView insertReserveSimple(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebReserveController insertReserveSimple START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();

		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.insertReserveSimple(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}

			try {
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				HashMap<String, Object> insertMap = new HashMap<String, Object>();
	
				insertMap.put("url", "/webreserve/insertReserveSimple.do");
				insertMap.put("func", "insertReserveSimple");
				insertMap.put("funcName", "간편예약 등록");
				insertMap.put("service", "webReserveService");
				insertMap.put("serviceName", "간편예약 등록");
				insertMap.put("requestValue", String.valueOf(paramMap));
				insertMap.put("responseValue", String.valueOf(map));
				insertMap.put("tId", map.get("tId"));
				if((String.valueOf(errorMsg)).equals("") || (String.valueOf(errorMsg) == null) || String.valueOf(errorMsg).length() == 0){
					insertMap.put("resultCode", "SUCCESS");
				}
				else{
					insertMap.put("resultCode", "ERROR");
				}
				insertMap.put("resultMsg", String.valueOf(errorMsg));
				insertMap.put("muMemberId", paramMap.get("loginMemberId"));
	
				webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		log.debug("WebReserveController insertReserveSimple END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**	
	 * 예약현황 정보 등록 (바로접수 등록)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/insertReserveReady.do")
	public ModelAndView insertReserveReady(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebReserveController insertReserveReady START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();

		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.insertReserveReady(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}

			try {
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				HashMap<String, Object> insertMap = new HashMap<String, Object>();
	
				insertMap.put("url", "/webreserve/insertReserveReady.do");
				insertMap.put("func", "insertReserveReady");
				insertMap.put("funcName", "바로접수 등록");
				insertMap.put("service", "webReserveService");
				insertMap.put("serviceName", "바로접수 등록");
				insertMap.put("requestValue", String.valueOf(paramMap));
				insertMap.put("responseValue", String.valueOf(map));
				insertMap.put("tId", map.get("tId"));
				if((String.valueOf(errorMsg)).equals("") || (String.valueOf(errorMsg) == null) || String.valueOf(errorMsg).length() == 0){
					insertMap.put("resultCode", "SUCCESS");
				}
				else{
					insertMap.put("resultCode", "ERROR");
				}
				insertMap.put("resultMsg", String.valueOf(errorMsg));
				insertMap.put("muMemberId", paramMap.get("loginMemberId"));
	
				webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		log.debug("WebReserveController insertReserveReady END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**	
	 * 예약현황 정보 수정
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/updateReserve.do")
	public ModelAndView updateReserve(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebReserveController updateReserve START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();

		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.updateReserve(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}

			try {
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				HashMap<String, Object> insertMap = new HashMap<String, Object>();
	
				insertMap.put("url", "/webreserve/updateReserve.do");
				insertMap.put("func", "updateReserve");
				insertMap.put("funcName", "예약현황 수정");
				insertMap.put("service", "webReserveService");
				insertMap.put("serviceName", "예약현황 수정");
				insertMap.put("requestValue", String.valueOf(paramMap));
				insertMap.put("responseValue", String.valueOf(map));
				insertMap.put("tId", map.get("tId"));
				if((String.valueOf(errorMsg)).equals("") || (String.valueOf(errorMsg) == null) || String.valueOf(errorMsg).length() == 0){
					insertMap.put("resultCode", "SUCCESS");
				}
				else{
					insertMap.put("resultCode", "ERROR");
				}
				insertMap.put("resultMsg", String.valueOf(errorMsg));
				insertMap.put("muMemberId", paramMap.get("loginMemberId"));
	
				webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		log.debug("WebReserveController updateReserve END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}

	/**
	 * 예약현황 정보 상태 수정 (진료상태)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/updateReserveStatus.do")
	public ModelAndView updateReserveStatus(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebReserveController updateReserveStatus START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.updateReserveStatus(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
			
			try {
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				HashMap<String, Object> insertMap = new HashMap<String, Object>();
	
				insertMap.put("url", "/webreserve/updateReserveStatus.do");
				insertMap.put("func", "updateReserve");
				insertMap.put("funcName", "예약현황 상태수정(진료상태)");
				insertMap.put("service", "webReserveService");
				insertMap.put("serviceName", "예약현황 상태수정(진료상태");
				insertMap.put("requestValue", String.valueOf(paramMap));
				insertMap.put("responseValue", String.valueOf(map));
				insertMap.put("tId", map.get("tId"));
				if((String.valueOf(errorMsg)).equals("") || (String.valueOf(errorMsg) == null) || String.valueOf(errorMsg).length() == 0){
					insertMap.put("resultCode", "SUCCESS");
				}
				else{
					insertMap.put("resultCode", "ERROR");
				}
				insertMap.put("resultMsg", String.valueOf(errorMsg));
				insertMap.put("muMemberId", paramMap.get("loginMemberId"));
	
				webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		log.debug("WebReserveController updateReserveStatus END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}

	/**
	 * 예약현황 정보 상태 수정 (수납상태)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/updateReserveStatus2.do")
	public ModelAndView updateReserveStatus2(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebReserveController updateReserveStatus2 START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.updateReserveStatus2(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
			
			try {
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				HashMap<String, Object> insertMap = new HashMap<String, Object>();
	
				insertMap.put("url", "/webreserve/updateReserveStatus2.do");
				insertMap.put("func", "updateReserve");
				insertMap.put("funcName", "예약현황 상태수정(수납상태)");
				insertMap.put("service", "webReserveService");
				insertMap.put("serviceName", "예약현황 상태수정(수납상태");
				insertMap.put("requestValue", String.valueOf(paramMap));
				insertMap.put("responseValue", String.valueOf(map));
				insertMap.put("tId", map.get("tId"));
				if((String.valueOf(errorMsg)).equals("") || (String.valueOf(errorMsg) == null) || String.valueOf(errorMsg).length() == 0){
					insertMap.put("resultCode", "SUCCESS");
				}
				else{
					insertMap.put("resultCode", "ERROR");
				}
				insertMap.put("resultMsg", String.valueOf(errorMsg));
				insertMap.put("muMemberId", paramMap.get("loginMemberId"));
	
				webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		log.debug("WebReserveController updateReserveStatus2 END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 예약현황 정보 삭제
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/deleteReserve.do")
	public ModelAndView deleteReserve(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController deleteReserve START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.deleteReserve(paramMap);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}
		finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}
			
			try {
				HashMap<String, Object> visitLogParamMap = RequestLogUtil.getVisitLogParameterMap(request);
				HashMap<String, Object> insertMap = new HashMap<String, Object>();
	
				insertMap.put("url", "/webreserve/deleteReserve.do");
				insertMap.put("func", "deleteReserve");
				insertMap.put("funcName", "예약현황 삭제");
				insertMap.put("service", "webReserveService");
				insertMap.put("serviceName", "예약현황 삭제");
				insertMap.put("requestValue", String.valueOf(paramMap));
				insertMap.put("responseValue", String.valueOf(map));
				insertMap.put("tId", map.get("tId"));
				if((String.valueOf(errorMsg)).equals("") || (String.valueOf(errorMsg) == null) || String.valueOf(errorMsg).length() == 0){
					insertMap.put("resultCode", "SUCCESS");
				}
				else{
					insertMap.put("resultCode", "ERROR");
				}
				insertMap.put("resultMsg", String.valueOf(errorMsg));
				insertMap.put("muMemberId", paramMap.get("loginMemberId"));
	
				webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		log.debug("WebReserveController deleteReserve END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 예약 일괄 등록 (업로드 엑셀) 
	 * 
	 * response : msgCode, msgDesc		
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	//@RequestMapping(value="/webreserve/uploadReserveExcel.do", method=RequestMethod.POST)
	@RequestMapping(value="/webreserve/uploadReserveExcel.do")
	public ModelAndView uploadReserveExcel(HttpSession session,HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file) {
		log.debug("WebReserveController uploadReserveExcel START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
				paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webReserveService.uploadReserveExcel(paramMap,file);
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		log.debug("WebReserveController uploadReserveExcel END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}

	
	/**
	 * 예약 샘플 파일 다운로드 (업로드 양식 다운로드)
	 * 
	 * response : msgCode, msgDesc		
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	//@RequestMapping(value="/webreserve/downloadReserveSampleExcel.do", method=RequestMethod.POST)
	@RequestMapping(value="/webreserve/downloadReserveSampleExcel.do")
	public void downloadReserveSampleExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebReserveController downloadReserveSampleExcel START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				
			}else{
				String fileName = String.valueOf(paramMap.get("fileName"));
				
				Resource resource = resourceLoader.getResource("classpath:static/sample/"+ fileName);
				File file = resource.getFile();
				
				byte[] fileByte = FileUtils.readFileToByteArray(file);

				response.setContentType("application/octet-stream");
				response.setHeader("Content-Disposition", "attachment; fileName=\"" + URLEncoder.encode(fileName, "UTF-8")+"\";");
				response.setHeader("Content-Transfer-Encoding", "binary");

				response.getOutputStream().write(fileByte);
				response.getOutputStream().flush();
				response.getOutputStream().close();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		log.debug("WebReserveController downloadReserveSampleExcel END");
	}
	
	/**
	 * <b>예약 컬럼 참고 양식 다운로드 (Excel 다운로드) </b>
	 * 페이지 처리 없음 
	 * request: 
	 * response : msgCode, msgDesc
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webreserve/downloadReserveColumnExcel.do")
	public ModelAndView downloadReserveColumnExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file, Model model) {
		log.debug("WebReserveController downloadReserveColumnExcel START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		Map<String, Object> selectListReport = new HashMap<String,Object>();
		Map<String, Object> map = new HashMap<String,Object>();
		
		try{
			if(!webCheckLogin(session)){
				return null;
			}
			else{
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				selectListReport = webReserveService.selectListReserveColumnExcel(paramMap);
				map.put("selectListReserveColumn", selectListReport);
				map.put("name", "reserveColumn");
			}
		}
		catch(Exception e){
			e.printStackTrace();
			return null;
		}
		log.debug("WebReserveController downloadReserveColumnExcel END");
		return new ModelAndView(new WebReserveColumnView(),"map",map);
	}
}
