package com.madeu.controller.web.webmembership;

import com.madeu.constants.Constants;
import com.madeu.init.ManagerDraftAction;
import com.madeu.service.web.webloghistory.WebLogHistoryService;
import com.madeu.service.web.webmembership.WebMembershipService;
import com.madeu.util.HttpUtil;
import com.madeu.util.RequestLogUtil;
import com.madeu.view.web.WebAppUserView;
import com.madeu.view.web.WebMembershipHistoryView;
import com.madeu.view.web.WebMembershipView;
import com.madeu.view.web.WebUseMembershipView;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
public class WebMembershipController extends ManagerDraftAction {
    @Autowired
    private WebMembershipService webMembershipService;

    @Autowired
    private WebLogHistoryService webLogHistoryService;

    /**
     * 멤버십 사용자 리스트 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectListMembershipIntro.do")
    public String  selectListMembershipIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("WebMembershipController  selectListMembershipIntro 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 = webMembershipService.selectListMembershipIntro(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("WebMembershipController  selectListMembershipIntro END");
        return "/web/membership/membershipSelectList";
    }

    /**
     * 멤버십 상품 정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectListMembershipProcedure.do")
    public ModelAndView selectListMembershipProcedure(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebMemberController selectListMembershipProcedure 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 = webMembershipService.selectListMembershipProcedure(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 selectListMembershipProcedure END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    /**
     * 멤버십고객 정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectListMembership.do")
    public ModelAndView selectListMembership(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebMemberController selectListMembership 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 = webMembershipService.selectListMembership(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 selectListMembership END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

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

    /**
     * 멤버십 상세화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/updateMembershipIntro.do")
    public String  updateMembershipIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("WebMembershipController  updateMembershipIntro 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 = webMembershipService.updateMembershipIntro(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";
        }
        String layout = "/web/layout/userSubMenuLayout";

        if ("userDetail".equals(String.valueOf(paramMap.get("pageType")))) {
            layout = "/web/layout/homeLayout";
        }
        model.addAttribute("layout", layout);
        log.debug("WebMembershipController  updateMembershipIntro END");
        return "/web/membership/membershipUpdate";
    }
    /**
     * 멤버십고객 상세정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectListMembershipHistory.do")
    public ModelAndView selectListMembershipHistory(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebMemberController selectListMembershipHistory 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 = webMembershipService.selectListMembershipHistory(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 selectListMembershipHistory END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 멤버십고객 멤버십 잔여금액 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectMembershipBalance.do")
    public ModelAndView selectMembershipBalance(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebMemberController selectMembershipBalance 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 = webMembershipService.selectMembershipBalance(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 selectMembershipBalance END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 멤버십고객 상세정보 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectToTransferUser.do")
    public ModelAndView selectToTransferUser(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebMemberController selectToTransferUser 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 = webMembershipService.selectToTransferUser(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 selectToTransferUser END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * <b>멤버십고객 상세정보 엑셀 다운로드 </b>
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/downloadMembershipHistoryExcel.do")
    public ModelAndView downloadMembershipHistoryExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file, Model model) {
        log.debug("WebMemberController downloadMembershipHistoryExcel 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 = webMembershipService.downloadMembershipHistoryExcel(paramMap);
                map.put("selectListMembershipHistory", selectListReport);
                map.put("name", "membershipHistory");
            }
        }
        catch(Exception e){
            e.printStackTrace();
            return null;
        }
        log.debug("WebMemberController downloadMembershipHistoryExcel END");
        return new ModelAndView(new WebMembershipHistoryView(),"map",map);
    }
    /**
     * 양도/양수 상세정보 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectMembershipTransfer.do")
    public ModelAndView selectMembershipTransfer(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebMemberController selectMembershipTransfer 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 = webMembershipService.selectMembershipTransfer(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 selectMembershipTransfer END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    /**
     * 멤버십 양도 및 양수
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/updateTransferMembership.do")
    public ModelAndView updateTransferMembership(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
        log.debug("WebMembershipController updateTransferMembership 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 = webMembershipService.updateTransferMembership(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", "/webmembership/updateTransferMembership.do");
                insertMap.put("func", "updateTransferMembership");
                insertMap.put("funcName", "멤버십 양도");
                insertMap.put("service", "webMembershipService");
                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("WebMembershipController updateTransferMembership END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 멤버십 충전
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/insertMembership.do")
    public ModelAndView insertMembership(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
        log.debug("WebMembershipController insertMembership 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 = webMembershipService.insertMembership(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", "/webmembership/insertMembership.do");
                insertMap.put("func", "insertMembership");
                insertMap.put("funcName", "멤버십 충전");
                insertMap.put("service", "webMembershipService");
                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("WebMembershipController insertMembership END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    /**
     * 멤버십 포인트 충전
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/insertMembershipPoint.do")
    public ModelAndView insertMembershipPoint(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
        log.debug("WebMembershipController insertMembershipPoint 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 = webMembershipService.insertMembershipPoint(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", "/webmembership/insertMembershipPoint.do");
                insertMap.put("func", "insertMembershipPoint");
                insertMap.put("funcName", "멤버십 포인트 충전");
                insertMap.put("service", "webMembershipService");
                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("WebMembershipController insertMembershipPoint END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }
    /**
     * 멤버십 상품등록
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/insertMembershipProcedure.do")
    public ModelAndView insertMembershipProcedure(HttpSession session,HttpServletRequest request, HttpServletResponse response, MultipartHttpServletRequest file) {
        log.debug("WebMembershipController insertMembershipProcedure 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 = webMembershipService.insertMembershipProcedure(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", "/webmembership/insertMembershipProcedure.do");
                insertMap.put("func", "insertMembership");
                insertMap.put("funcName", "멤버십 상품등록");
                insertMap.put("service", "webMembershipService");
                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("WebMembershipController insertMembershipProcedure END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * 멤버십 사용내역 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectListUseMembershipIntro.do")
    public String  selectListUseMembershipIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("WebMembershipController  selectListUseMembershipIntro 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 = webMembershipService.selectListUseMembershipIntro(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("WebMembershipController  selectListUseMembershipIntro END");
        return "/web/membership/useMembershipSelectList";
    }
    /**
     * 멤버십 상품등록 화면으로 이동.
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectListMembershipProcedureIntro.do")
    public String  selectListMembershipProcedureIntro(HttpSession session, HttpServletRequest request, HttpServletResponse response, Model model) {
        log.debug("WebMembershipController  selectListMembershipProcedureIntro 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 = webMembershipService.selectListMembershipProcedureIntro(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("WebMembershipController  selectListMembershipProcedureIntro END");
        return "/web/membership/membershipProcedureList";
    }
    /**
     * 맴버십 사용내역 리스트 조회
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectUseMembershipList.do")
    public ModelAndView selectUseMembershipList(HttpSession session, HttpServletRequest request, HttpServletResponse response) {

        log.debug("WebMemberController selectUseMembershipList 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 = webMembershipService.selectUseMembershipList(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 selectUseMembershipList END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

    /**
     * <b>맴버십 사용내역 엑셀 다운로드 </b>
     * 페이지 처리 없음
     * request:
     * response : msgCode, msgDesc
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/selectUseMembershipExcel.do")
    public ModelAndView selectUseMembershipExcel(HttpSession session, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file, Model model) {
        log.debug("WebMemberController selectUseMembershipExcel 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 = webMembershipService.selectUseMembershipExcel(paramMap);
                map.put("selectUseMembershipList", selectListReport);
                map.put("name", "useMembershipList");
            }
        }
        catch(Exception e){
            e.printStackTrace();
            return null;
        }
        log.debug("WebMemberController selectUseMembershipExcel END");
        return new ModelAndView(new WebUseMembershipView(),"map",map);
    }
    /**
     * 멤버십 상품 정보 삭제
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/webmembership/deleteMembershipProcedure.do")
    public ModelAndView deleteMembershipProcedure(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
        log.debug("WebWorkController deleteMembershipProcedure 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 = webMembershipService.deleteMembershipProcedure(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", "/webmembership/deleteMembershipProcedure.do");
                insertMap.put("func", "deleteMembershipProcedure");
                insertMap.put("funcName", "멤버십 상품 삭제");
                insertMap.put("service", "webMembershipService");
                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("WebMemberController deleteMembershipProcedure END");
        return HttpUtil.makeHashToJsonModelAndView(map);
    }

}
