package com.madeu.controller.web.webtreatmentprocedure;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
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.webtreatmentprocedure.WebTreatmentProcedureService;
import com.madeu.util.HttpUtil;
import com.madeu.util.RequestLogUtil;

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


@Slf4j
@Controller
public class WebTreatmentProcedureController extends ManagerDraftAction{

	@Autowired
	private WebTreatmentProcedureService webTreatmentProcedureService;
	
	@Autowired
	private WebLogHistoryService webLogHistoryService;

	/**
	 * 진료 시술 정보 리스트 조회 (option)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/selectListTreatmentProcedureOption.do")
	public ModelAndView selectListTreatmentProcedureOption(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebTreatmentProcedureController selectListTreatmentProcedureOption 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 = webTreatmentProcedureService.selectListTreatmentProcedureOption(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("WebTreatmentProcedureController selectListTreatmentProcedureOption END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}

	/**
	 * 진료 시술 정보 리스트 조회 2 (option, 페이징처리X)
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/selectListTreatmentProcedureOption2.do")
	public ModelAndView selectListTreatmentProcedureOption2(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebTreatmentProcedureController selectListTreatmentProcedureOption2 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 = webTreatmentProcedureService.selectListTreatmentProcedureOption2(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("WebTreatmentProcedureController selectListTreatmentProcedureOption2 END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 진료 시술 정보 리스트 조회
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/selectListTreatmentProcedure.do")
	public ModelAndView selectListTreatmentProcedure(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebTreatmentProcedureController selectListTreatmentProcedure 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 = webTreatmentProcedureService.selectListTreatmentProcedure(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("WebTreatmentProcedureController selectListTreatmentProcedure END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 진료 시술 정보 상세 조회
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/selectTreatmentProcedure.do")
	public ModelAndView selectTreatmentProcedure(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebTreatmentProcedureController selectTreatmentProcedure 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 = webTreatmentProcedureService.selectTreatmentProcedure(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("WebTreatmentProcedureController selectTreatmentProcedure END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}

	/**	
	 * 진료 시술 정보 등록
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/insertTreatmentProcedure.do")
	public ModelAndView insertTreatmentProcedure(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebTreatmentProcedureController insertTreatmentProcedure 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 = webTreatmentProcedureService.insertTreatmentProcedure(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", "/webtreatmentprocedure/insertTreatmentProcedure.do");
				insertMap.put("func", "insertTreatmentProcedure");
				insertMap.put("funcName", "진료 시술 등록");
				insertMap.put("service", "webTreatmentProcedureService");
				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("WebTreatmentProcedureController insertTreatmentProcedure END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
	/**
	 * 진료 시술 정보 수정
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/updateTreatmentProcedure.do")
	public ModelAndView updateTreatmentProcedure(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
		log.debug("WebTreatmentProcedureController updateTreatmentProcedure 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 = webTreatmentProcedureService.updateTreatmentProcedure(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", "/webtreatmentprocedure/updateTreatmentProcedure.do");
				insertMap.put("func", "updateTreatmentProcedure");
				insertMap.put("funcName", "진료 시술 수정");
				insertMap.put("service", "webTreatmentProcedureService");
				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("WebTreatmentProcedureController updateTreatmentProcedure END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	

	/**
	 * 진료 시술 정보 활성/비활성 처리
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/updateTreatmentProcedureEnableYn.do")
	public ModelAndView updateTreatmentProcedureEnableYn(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebTreatmentProcedureController updateTreatmentProcedureEnableYn 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 = webTreatmentProcedureService.updateTreatmentProcedureEnableYn(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", "/webtreatmentprocedure/updateTreatmentProcedureEnableYn.do");
				insertMap.put("func", "updateTreatmentProcedureEnableYn");
				insertMap.put("funcName", "진료 시술 활성화/비활성화");
				insertMap.put("service", "webTreatmentProcedureService");
				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("WebTreatmentProcedureController updateTreatmentProcedureEnableYn END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	

	/**
	 * 진료 시술 정보 진료이동
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webtreatmentprocedure/updateTreatmentProcedureTreatmentId.do")
	public ModelAndView updateTreatmentProcedureTreatmentId(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebTreatmentProcedureController updateTreatmentProcedureTreatmentId 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 = webTreatmentProcedureService.updateTreatmentProcedureTreatmentId(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", "/webtreatmentprocedure/updateTreatmentProcedureTreatmentId.do");
				insertMap.put("func", "updateTreatmentProcedureTreatmentId");
				insertMap.put("funcName", "진료 시술 진료이동");
				insertMap.put("service", "webTreatmentProcedureService");
				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("WebTreatmentProcedureController updateTreatmentProcedureTreatmentId END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}
	
}
