package com.madeu.controller.web.webuser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.webuser.WebUserService;
import com.madeu.util.HttpUtil;
import com.madeu.util.RequestLogUtil;
import com.madeu.view.web.WebUserAgreementView;
import com.madeu.view.web.WebUserPhysicalView;
import com.madeu.view.web.WebUserView;

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

@Slf4j
@Controller
public class WebUserController extends ManagerDraftAction {

    @Autowired
    private WebUserService webUserService;

    @Autowired
    private WebLogHistoryService webLogHistoryService;

    /**
     * 고객 정보 리스트 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectListUserIntro.do")
    public String selectListUserIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("WebUserController  selectListUserIntro 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 = webUserService.selectListUserIntro(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"));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return "/web/login/logout";
        }
        log.debug("WebUserController  selectListUserIntro END");
        return "/web/user/userSelectList";
    }

    /**
     * 고객 등록.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/insertUser.do")
    public ModelAndView insertUser(HttpSession session, HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {

        log.debug("WebUserController insertUser 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 = webUserService.insertUser(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", "/webuser/insertUser.do");
                insertMap.put("func", "insertUser");
                insertMap.put("funcName", "고객 등록");
                insertMap.put("service", "webUserService");
                insertMap.put("serviceName", "고객 등록");
                insertMap.put("requestValue", String.valueOf(paramMap));
                insertMap.put("responseValue", String.valueOf(map));
                insertMap.put("tId", map.get("tId"));
                if (("").equals(String.valueOf(errorMsg)) || null == (String.valueOf(errorMsg)) || 0 == String.valueOf(errorMsg).length()) {
                    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("WebUserController insertUser END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 고객 검색 조회 (상단 검색)
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectUserSearch.do")
    public ModelAndView selectUserSearch(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebUserController selectUserSearch 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 = webUserService.selectUserSearch(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("WebUserController selectUserSearch END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 고객 정보 리스트 조회 (option)
     * 예약등록 팝업
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectListUserOption.do")
    public ModelAndView selectListUserOption(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebCustomerController selectListUser 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 = webUserService.selectListUserOption(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("WebUserController selectListUserOption END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    /**
     * 고객 정보 리스트 조회 (List)
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectListUser.do")
    public ModelAndView selectListUser(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebCustomerController selectListUser 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 = webUserService.selectListUser(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("WebUserController selectListUser END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 마케팅 - 고객 정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectListUserMarketing.do")
    public ModelAndView selectListUserMarketing(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebCustomerController selectListUserMarketing 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 = webUserService.selectListUserMarketing(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("WebUserController selectListUserMarketing END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 마케팅 - 고객 정보 리스트 조회 (푸시)
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectListUserMarketingPush.do")
    public ModelAndView selectListUserMarketingPush(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebCustomerController selectListUserMarketingPush 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 = webUserService.selectListUserMarketingPush(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("WebUserController selectListUserMarketingPush END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 고객 정보 엑셀 다운로드
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/downloadUserExcel.do")
    public ModelAndView downloadUserExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file, Model model) {
        log.debug("WebUserController downloadUserExcel 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 = webUserService.selectListUserExcel(paramMap);
                map.put("selectListUser", selectListReport);
                map.put("name", "user");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        log.debug("WebMemberController downloadUserExcel END");
        return new ModelAndView(new WebUserView(), "map", map);
    }

    /**
     * 고객 정보 수정 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/updateUserIntro.do")
    public String updateUserIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {

        log.debug("WebUserController  updateUserIntro 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 = webUserService.updateUserIntro(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("muUserId", map.get("muUserId"));
                model.addAttribute("muMemberId", map.get("loginMemberId"));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return "/web/login/logout";
        }
        log.debug("WebMemberController  updateMemberIntro END");
        return "/web/user/userUpdate";
    }
    /**
     * 고객 정보 상세 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectUser.do")
    public ModelAndView selectUser(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebUserController selectUser 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("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.selectUser(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("WebMemberController selectMember END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 고객 정보 수정
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/updateUser.do")
    public ModelAndView updateUser(HttpSession session, HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {

        log.debug("WebMemberController updateMember 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("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.updateUser(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", "/webuser/updateUser.do");
                insertMap.put("func", "updateUser");
                insertMap.put("funcName", "고객 수정");
                insertMap.put("service", "webUserService");
                insertMap.put("serviceName", "고객 수정");
                insertMap.put("requestValue", String.valueOf(paramMap));
                insertMap.put("responseValue", String.valueOf(map));
                insertMap.put("tId", map.get("tId"));
                if (("").equals(String.valueOf(errorMsg)) || null == (String.valueOf(errorMsg)) || 0 == String.valueOf(errorMsg).length()) {
                    insertMap.put("resultCode", "SUCCESS");
                } else {
                    insertMap.put("resultCode", "ERROR");
                }
                insertMap.put("resultMsg", String.valueOf(errorMsg));

                webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        log.debug("WebMemberController updateUser END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 고객 정보 수정2 (간편예약고객 -> 신환등록)
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/updateUser2.do")
    public ModelAndView updateUser2(HttpSession session, HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {

        log.debug("WebMemberController updateUser2 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("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.updateUser2(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", "/webuser/updateUser2.do");
                insertMap.put("func", "updateUser2");
                insertMap.put("funcName", "고객 정보 수정2 (간편예약고객 -> 신환등록)");
                insertMap.put("service", "webUserService");
                insertMap.put("serviceName", "고객 정보 수정2 (간편예약고객 -> 신환등록)");
                insertMap.put("requestValue", String.valueOf(paramMap));
                insertMap.put("responseValue", String.valueOf(map));
                insertMap.put("tId", map.get("tId"));
                if (("").equals(String.valueOf(errorMsg)) || null == (String.valueOf(errorMsg)) || 0 == String.valueOf(errorMsg).length()) {
                    insertMap.put("resultCode", "SUCCESS");
                } else {
                    insertMap.put("resultCode", "ERROR");
                }
                insertMap.put("resultMsg", String.valueOf(errorMsg));

                webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        log.debug("WebUserController updateUser2 END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    /**
     * 고객 신체 정보 리스트 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectListUserPhysicalIntro.do")
    public String selectListUserPhysicalIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("WebUserController  selectListUserPhysicalIntro 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 = webUserService.selectListUserPhysicalIntro(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("WebMemberController  selectListUserPhysicalIntro END");
        return "/web/user/userPhysicalSelectList";
    }

    /**
     * 고객 신체정보 등록.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/insertPhysical.do")
    public ModelAndView insertPhysical(HttpSession session, HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {

        log.debug("WebUserController insertPhysical 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("regId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.insertPhysical(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", "/webuser/insertPhysical.do");
                insertMap.put("func", "insertPhysical");
                insertMap.put("funcName", "고객 신체정보 등록");
                insertMap.put("service", "webUserService");
                insertMap.put("serviceName", "고객 신체정보 등록");
                insertMap.put("requestValue", String.valueOf(paramMap));
                insertMap.put("responseValue", String.valueOf(map));
                insertMap.put("tId", map.get("tId"));
                if (("").equals(String.valueOf(errorMsg)) || null == (String.valueOf(errorMsg)) || 0 == String.valueOf(errorMsg).length()) {
                    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("WebUserController insertPhysical END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    /**
     * 고객 신체정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectUserPhysicalList.do")
    public ModelAndView selectUserPhysicalList(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebCustomerController selectUserPhysicalList 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("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.selectUserPhysicalList(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("WebUserController selectUserPhysicalList END");
        return HttpUtil.makeHashToJsonModelAndView(map);
//            return map;
    }

    /**
     * <b>고객 신체정보 엑셀 다운로드 </b>
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/downloadPhysicalExcel.do")
    public ModelAndView downloadPhysicalExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file, Model model) {
        log.debug("WebUserController downloadPhysicalExcel 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")));
                paramMap.put("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                selectListReport = webUserService.selectUserPhysicalListExcel(paramMap);
                map.put("selectListUserPhysical", selectListReport);
                map.put("name", "userPhysical");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        log.debug("WebMemberController downloadPhysicalExcel END");
        return new ModelAndView(new WebUserPhysicalView(), "map", map);
    }
	
	/**
	 * 고객 신체정보 상세 조회
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webuser/selectUserPhysical.do")
	public ModelAndView selectUserPhysical(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
		log.debug("WebUserController selectUserPhysical 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 = webUserService.selectUserPhysical(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("WebUserController selectUserPhysical END");
		return HttpUtil.makeHashToJsonModelAndView(map);
	}

    /**
     * 고객 신체정보 수정 (담당자)
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/updateUserPhysical.do")
    public ModelAndView updateUserPhysical(HttpSession session, HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {

        log.debug("WebMemberController updateUserPhysical 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 = webUserService.updateUserPhysical(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", "/webuser/updateUserPhysical.do");
                insertMap.put("func", "updateUser");
                insertMap.put("funcName", "고객 신체정보 수정");
                insertMap.put("service", "webUserService");
                insertMap.put("serviceName", "고객 신체정보 수정");
                insertMap.put("requestValue", String.valueOf(paramMap));
                insertMap.put("responseValue", String.valueOf(map));
                insertMap.put("tId", map.get("tId"));
                if (("").equals(String.valueOf(errorMsg)) || null == (String.valueOf(errorMsg)) || 0 == String.valueOf(errorMsg).length()) {
                    insertMap.put("resultCode", "SUCCESS");
                } else {
                    insertMap.put("resultCode", "ERROR");
                }
                insertMap.put("resultMsg", String.valueOf(errorMsg));

                webLogHistoryService.insertLogHistory(insertMap, visitLogParamMap);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        log.debug("WebMemberController updateUserPhysical END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
	
    /**
     * 고객 신체정보 불러오기 (인바디 정보 불러오기, api 연동)
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/insertUserPhysicalInbodyApi.do")
    public ModelAndView insertUserPhysicalInbodyApi(HttpSession session, HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {

        log.debug("WebUserController insertUserPhysicalInbodyApi 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("regId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.insertUserPhysicalInbodyApi(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", "/webuser/insertUserPhysicalInbodyApi.do");
                insertMap.put("func", "insertUserPhysicalInbodyApi");
                insertMap.put("funcName", "고객 신체정보 불러오기");
                insertMap.put("service", "webUserService");
                insertMap.put("serviceName", "고객 신체정보 불러오기");
                insertMap.put("requestValue", String.valueOf(paramMap));
                insertMap.put("responseValue", String.valueOf(map));
                insertMap.put("tId", map.get("tId"));
                if (("").equals(String.valueOf(errorMsg)) || null == (String.valueOf(errorMsg)) || 0 == String.valueOf(errorMsg).length()) {
                    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("WebUserController insertUserPhysicalInbodyApi END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    
    /**
     * 고객 동의서 리스트 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectListUserAgreementIntro.do")
    public String selectListUserAgreementIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("WebUserController  selectListUserAgreementIntro 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 = webUserService.selectListUserAgreementIntro(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("WebMemberController  selectListUserAgreementIntro END");
        return "/web/user/userAgreementList";
    }
    /**
     * 고객 동의서 등록.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/insertUserAgreement.do")
    public ModelAndView insertUserAgreement(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file) {

        log.debug("WebUserController insertUserAgreement 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 = webUserService.insertUserAgreement(paramMap, file);
            }
        }
        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", "/webuser/insertUserAgreement.do");
                insertMap.put("func", "insertUserAgreement");
                insertMap.put("funcName", "고객 동의서 등록");
                insertMap.put("service", "webUserService");
                insertMap.put("serviceName", "고객 동의서 등록");
                insertMap.put("requestValue", String.valueOf(paramMap));
                insertMap.put("responseValue", String.valueOf(map));
                insertMap.put("tId", map.get("tId"));
                if (("").equals(String.valueOf(errorMsg)) || null == (String.valueOf(errorMsg)) || 0 == String.valueOf(errorMsg).length()) {
                    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("WebUserController insertUserAgreement END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 고객 신체정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectUserAgreementList.do")
    public ModelAndView selectUserAgreementList(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebCustomerController selectUserAgreementList 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("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.selectUserAgreementList(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("WebUserController selectUserAgreementList END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * <b>고객 동의서 리스트 엑셀 다운로드 </b>
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/downloadAgreementExcel.do")
    public ModelAndView downloadAgreementExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file, Model model) {
        log.debug("WebUserController downloadAgreementExcel 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 = webUserService.selectUserAgreementListExcel(paramMap);
                map.put("selectListUserAgreement", selectListReport);
                map.put("name", "useragreement");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        log.debug("WebMemberController downloadAgreementExcel END");
        return new ModelAndView(new WebUserAgreementView(), "map", map);
    }

    /**
     * 고객 동의서 상세 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/webuser/selectUserAgreement.do")
    public ModelAndView selectUserAgreement(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebUserController selectUserAgreement 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("muMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
                map = webUserService.selectUserAgreement(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("WebUserController selectUserAgreement END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
}
