package com.madeu.service.web.webmembership.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.madeu.constants.Constants;
import com.madeu.dao.web.webauthmenurelation.WebAuthMenuRelationSqlMapDAO;
import com.madeu.dao.web.webdevice.WebDeviceSqlMapDAO;
import com.madeu.dao.web.webkakao.WebKakaoSqlMapDAO;
import com.madeu.dao.web.webkakaotemplate.WebKakaoTemplateSqlMapDAO;
import com.madeu.dao.web.webmember.WebMemberSqlMapDAO;
import com.madeu.dao.web.webmembership.WebMembershipSqlMapDAO;
import com.madeu.dao.web.webpayment.WebPaymentSqlMapDAO;
import com.madeu.dao.web.webpush.WebPushSqlMapDAO;
import com.madeu.dao.web.webtreatmentprocedure.WebTreatmentProcedureSqlMapDAO;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import com.madeu.service.common.autokakao.AutoKakaoService;
import com.madeu.service.common.autopush.AutoPushService;
import com.madeu.service.web.webmembership.WebMembershipService;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import com.madeu.util.ValidationCheckUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service("WebMembershipService")
public class WebMembershipServiceImpl implements WebMembershipService {
    @Autowired
    private WebPaymentSqlMapDAO webPaymentSqlMapDAO;
    @Autowired
    private WebMembershipSqlMapDAO webMembershipSqlMapDAO;
    @Autowired
    private WebMemberSqlMapDAO webMemberSqlMapDAO;
    @Autowired
    private WebUserSqlMapDAO webUserSqlMapDAO;
    @Autowired
    private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;

	@Autowired
	private WebKakaoSqlMapDAO webKakaoSqlMapDAO;

	@Autowired
	private WebKakaoTemplateSqlMapDAO webKakaoTemplateSqlMapDAO;

	@Autowired
	private WebDeviceSqlMapDAO webDeviceSqlMapDAO;

	@Autowired
	private WebPushSqlMapDAO webPushSqlMapDAO;

	@Autowired
	private AutoPushService autoPushService;

	@Autowired
	private AutoKakaoService autoKakaoService;

	@Value("${popbill.sender-phone-num}")
	String senderPhoneNumber;

    /**
     * 멤버십 사용자 리스트 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListMembershipIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectListMembershipIntro START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        try{
            boolean check  = true;

            String menuClass    = String.valueOf(paramMap.get("menuClass"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(menuClass)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","메뉴 정보가 없습니다.");
            }

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){
                    map.put("msgCode", Constants.OK);
                    map.put("success","true");

                    map.put("selectUseYn", authMenuRelationlistMap.get(0).get("selectUseYn"));
                    map.put("insertUseYn", authMenuRelationlistMap.get(0).get("insertUseYn"));
                    map.put("updateUseYn", authMenuRelationlistMap.get(0).get("updateUseYn"));
                    map.put("deleteUseYn", authMenuRelationlistMap.get(0).get("deleteUseYn"));
                    map.put("downloadUseYn", authMenuRelationlistMap.get(0).get("downloadUseYn"));
                }
                else {
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectListMembershipIntro END");
        return map;
    }
    /**
     * 멤버십 상품 리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListMembershipProcedure(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectListMembershipProcedure START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId            :"+paramMap.get("loginMemberId"));

        log.debug("menuClass                :"+paramMap.get("menuClass"));

        log.debug("membershipProcedureSort  :"+paramMap.get("membershipProcedureSort"));

        List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }
            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "조회 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "조회 정보가 없습니다.");
                }
            }
            if(true == check){
                // 정렬
                if(null==paramMap.get("membershipProcedureDir")||("").equals(paramMap.get("membershipProcedureDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("membershipProcedureDir"));
                    if(("A").equals(dir)){
                        paramMap.put("membershipProcedureDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("membershipProcedureDir", "ASC");
                    }
                    else {
                        paramMap.put("membershipProcedureDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");

                List<Map<String, Object>> totalCountListMap = webMembershipSqlMapDAO.selectTotalMembershipProcedureCount();
                int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.getFirst()));

                if(0 < totalCount) {
                    // 리스트 조회
                    listMap = webMembershipSqlMapDAO.selectListMembershipProcedure(paramMap);
                }

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("totalCount", totalCount);
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectListMembershipProcedure END");
        return map;
    }
    /**
         * 멤버십 고객 리스트 조회
         *
         *
         * @param paramMap
         * @return
         * @throws Exception
         */
        @Override
        public HashMap<String, Object> selectListMembership(
                HashMap<String, Object> paramMap) throws Exception {
            log.debug("WebMembershipServiceImpl selectListMembership START");

            HashMap<String, Object> map = new HashMap<String, Object>();

            log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

            log.debug("menuClass           :"+paramMap.get("menuClass"));

            log.debug("membershipSearchKeywordParam  :"+paramMap.get("membershipSearchKeywordParam"));
            log.debug("membershipSort                :"+paramMap.get("membershipSort"));
            log.debug("membershipStart               :"+paramMap.get("membershipStart"));
            log.debug("membershipLimit               :"+paramMap.get("membershipLimit"));

            List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

            try{
                boolean check  = true;

                if(true == check){
                    // 사용자 확인
                    List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                    int userListMapSize = userListMap.size();

                    if(1==userListMapSize){
                        paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                    }
                }
                if(true == check){
                    // 권한 조회
                    HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                    authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                    authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                    List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                    int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                    if(1==authMenuRelationlistMapSize){

                        if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

                        }
                        else {
                            check = false;
                            map.put("msgCode", Constants.FAIL);
                            map.put("msgDesc", "조회 권한 정보가 없습니다.");
                        }
                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "조회 정보가 없습니다.");
                    }
                }
                if(true == check){
                    // 정렬
                    if(null==paramMap.get("membershipDir")||("").equals(paramMap.get("membershipDir"))){

                    }
                    else{
                        String dir = String.valueOf(paramMap.get("userDir"));
                        if(("A").equals(dir)){
                            paramMap.put("membershipDir", "DESC");
                        }
                        else if(("B").equals(dir)){
                            paramMap.put("membershipDir", "ASC");
                        }
                        else {
                            paramMap.put("membershipDir", "DESC");
                        }
                    }

                    paramMap.put("useYn", "Y");

                    // 총 갯수 조회
                    List<Map<String, Object>> totalCountListMap = webMembershipSqlMapDAO.selectTotalMembershipCount(paramMap);
                    List<Map<String, Object>> sumMembershipBalanceMap = webMembershipSqlMapDAO.selectSumMembershipBalance(paramMap);

                    //총 멤버십고객 조회
                    int totalMembershipCount = Integer.parseInt(String.valueOf(webMembershipSqlMapDAO.selectTotalMembershipCount().get(0)));
                    int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0)));

                    if(0 < totalCount) {
                        // 리스트 조회
                        listMap = webMembershipSqlMapDAO.selectListMembership(paramMap);
                    }

                    map.put("msgCode", Constants.OK);
                    map.put("success","true");
                    map.put("totalCount", totalCount);
                    map.put("totalMembershipCount", totalMembershipCount);
                    map.put("sumMembershipBalanceMap", sumMembershipBalanceMap);
                    map.put("rows",listMap);
                }
            }
            catch(Exception e){
                e.printStackTrace();
                throw e;
            }
            log.debug("WebMembershipServiceImpl selectListMembership END");
            return map;
        }

    /**
     * 멤버십고객 리스트 조회 (List, Excel)
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> downloadMembershipExcel(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl downloadMembershipExcel START");

        HashMap<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> listMap = null;

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("membershipSearchKeywordParam  :"+paramMap.get("membershipSearchKeywordParam"));
        log.debug("membershipSort                :"+paramMap.get("membershipSort"));

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("downloadUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "내려받기 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){
                // 정렬
                if(null==paramMap.get("membershipDir")||("").equals(paramMap.get("membershipDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("membershipDir"));
                    if(("A").equals(dir)){
                        paramMap.put("membershipDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("membershipDir", "ASC");
                    }
                    else {
                        paramMap.put("membershipDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");

                listMap = webMembershipSqlMapDAO.downloadMembershipExcel(paramMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl downloadMembershipExcel END");
        return listMap;
    }

    /**
     * 멤버십 사용내역 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListUseMembershipIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectListUseMembershipIntro START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        try{
            boolean check  = true;

            String menuClass    = String.valueOf(paramMap.get("menuClass"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(menuClass)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","메뉴 정보가 없습니다.");
            }

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){
                    map.put("msgCode", Constants.OK);
                    map.put("success","true");

                    map.put("selectUseYn", authMenuRelationlistMap.get(0).get("selectUseYn"));
                    map.put("insertUseYn", authMenuRelationlistMap.get(0).get("insertUseYn"));
                    map.put("updateUseYn", authMenuRelationlistMap.get(0).get("updateUseYn"));
                    map.put("deleteUseYn", authMenuRelationlistMap.get(0).get("deleteUseYn"));
                    map.put("downloadUseYn", authMenuRelationlistMap.get(0).get("downloadUseYn"));
                }
                else {
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectListUseMembershipIntro END");
        return map;
    }
    /**
     * 멤버십 상품추가 화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListMembershipProcedureIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectListMembershipProcedureIntro START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        try{
            boolean check  = true;

            String menuClass    = String.valueOf(paramMap.get("menuClass"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(menuClass)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","메뉴 정보가 없습니다.");
            }

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){
                    map.put("msgCode", Constants.OK);
                    map.put("success","true");

                    map.put("selectUseYn", authMenuRelationlistMap.get(0).get("selectUseYn"));
                    map.put("insertUseYn", authMenuRelationlistMap.get(0).get("insertUseYn"));
                    map.put("updateUseYn", authMenuRelationlistMap.get(0).get("updateUseYn"));
                    map.put("deleteUseYn", authMenuRelationlistMap.get(0).get("deleteUseYn"));
                    map.put("downloadUseYn", authMenuRelationlistMap.get(0).get("downloadUseYn"));
                }
                else {
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectListMembershipProcedureIntro END");
        return map;
    }

    /**
     * 멤버십 사용내역 리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectUseMembershipList(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectUseMembershipList START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("userSearchKeywordParam     :"+paramMap.get("userSearchKeywordParam"));
        log.debug("membershipSearchStartDate  :"+paramMap.get("membershipSearchStartDate"));
        log.debug("membershipSearchEndDate    :"+paramMap.get("membershipSearchEndDate"));
        log.debug("membershipSearchDateType   :"+paramMap.get("membershipSearchDateType"));
        log.debug("membershipSort             :"+paramMap.get("membershipSort"));
        log.debug("membershipDir              :"+paramMap.get("membershipDir"));
        log.debug("membershipStart            :"+paramMap.get("membershipStart"));
        log.debug("membershipLimit            :"+paramMap.get("membershipLimit"));
        log.debug("muTreatmentId              :"+paramMap.get("muTreatmentId"));

        List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }
            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "조회 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "조회 정보가 없습니다.");
                }
            }
            if(true == check){
                // 정렬
                if(null==paramMap.get("membershipDir")||("").equals(paramMap.get("membershipDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("membershipDir"));
                    if(("A").equals(dir)){
                        paramMap.put("membershipDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("membershipDir", "ASC");
                    }
                    else {
                        paramMap.put("membershipDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");

                // 총 갯수 조회
                List<Map<String, Object>> totalCountListMap = webMembershipSqlMapDAO.selectTotalUseMembershipCount(paramMap);
                int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0)));

                if(0 < totalCount) {
                    // 리스트 조회
                    listMap = webMembershipSqlMapDAO.selectUseMembershipList(paramMap);
                }

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("totalCount", totalCount);
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectUseMembershipList END");
        return map;
    }

    /**
     * 멤버십 사용내역 리스트 조회 (List, Excel)
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> selectUseMembershipExcel(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectUseMembershipExcel START");

        HashMap<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> listMap = null;


        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("userSearchKeywordParam     :"+paramMap.get("userSearchKeywordParam"));
        log.debug("membershipSearchStartDate  :"+paramMap.get("membershipSearchStartDate"));
        log.debug("membershipSearchEndDate    :"+paramMap.get("membershipSearchEndDate"));
        log.debug("membershipSearchDateType   :"+paramMap.get("membershipSearchDateType"));
        log.debug("membershipSort             :"+paramMap.get("membershipSort"));
        log.debug("membershipDir              :"+paramMap.get("membershipDir"));
        log.debug("membershipStart            :"+paramMap.get("membershipStart"));
        log.debug("membershipLimit            :"+paramMap.get("membershipLimit"));
        log.debug("muTreatmentId              :"+paramMap.get("muTreatmentId"));

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("downloadUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "내려받기 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){
                // 정렬
                if(null==paramMap.get("membershipDir")||("").equals(paramMap.get("membershipDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("membershipDir"));
                    if(("A").equals(dir)){
                        paramMap.put("membershipDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("membershipDir", "ASC");
                    }
                    else {
                        paramMap.put("membershipDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");

                listMap = webMembershipSqlMapDAO.selectUseMembershipExcel(paramMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectUseMembershipExcel END");
        return listMap;
    }

    /**
     * 멤버십 상세화면으로 이동.
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> updateMembershipIntro(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl updateMembershipintro START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        try{
            boolean check  = true;

            String menuClass    = String.valueOf(paramMap.get("menuClass"));

            // 정렬
            if(true != ValidationCheckUtil.emptyCheck(menuClass)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","메뉴 정보가 없습니다.");
            }

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){
                    map.put("msgCode", Constants.OK);
                    map.put("success","true");

                    map.put("selectUseYn", authMenuRelationlistMap.get(0).get("selectUseYn"));
                    map.put("insertUseYn", authMenuRelationlistMap.get(0).get("insertUseYn"));
                    map.put("updateUseYn", authMenuRelationlistMap.get(0).get("updateUseYn"));
                    map.put("deleteUseYn", authMenuRelationlistMap.get(0).get("deleteUseYn"));
                    map.put("downloadUseYn", authMenuRelationlistMap.get(0).get("downloadUseYn"));
                }
                else {
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl updateMembershipIntro END");
        return map;
    }
    /**
     * 멤버십 고객 상세리스트 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectListMembershipHistory(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectListMembershipHistory START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("membershipSearchStartDate        :"+paramMap.get("membershipSearchStartDate"));
        log.debug("membershipSearchEndDate          :"+paramMap.get("membershipSearchEndDate"));
        log.debug("muTreatmentId                    :"+paramMap.get("muTreatmentId"));
        log.debug("treatmentName                    :"+paramMap.get("treatmentName"));
        log.debug("membershipSort                   :"+paramMap.get("membershipSort"));
        log.debug("membershipStart                  :"+paramMap.get("membershipStart"));
        log.debug("membershipLimit                  :"+paramMap.get("membershipLimit"));

        List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }
            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "조회 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "조회 정보가 없습니다.");
                }
            }
            if(true == check){
                // 정렬
                if(null==paramMap.get("membershipDir")||("").equals(paramMap.get("membershipDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("userDir"));
                    if(("A").equals(dir)){
                        paramMap.put("membershipDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("membershipDir", "ASC");
                    }
                    else {
                        paramMap.put("membershipDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");

                // 총 갯수 조회
                List<Map<String, Object>> totalCountListMap = webMembershipSqlMapDAO.selectTotalMembershipHistoryCount(paramMap);
                List<Map<String, Object>> totalMembershipHistoryInfo = webMembershipSqlMapDAO.selectTotalMembershipHistoryInfo(paramMap);

                int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0)));

                if(0 < totalCount) {
                    // 리스트 조회
                    listMap = webMembershipSqlMapDAO.selectListMembershipHistory(paramMap);
                }

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("totalCount", totalCount);
                map.put("totalMembershipHistoryInfo", totalMembershipHistoryInfo);
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectListMembershipHistory END");
        return map;
    }
    /**
     * 멤버십 고객 멤버십 잔여금액 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectMembershipBalance(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectMembershipBalance START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("muUserId            :"+paramMap.get("muUserId"));

        List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 정렬
                if(null==paramMap.get("membershipDir")||("").equals(paramMap.get("membershipDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("userDir"));
                    if(("A").equals(dir)){
                        paramMap.put("membershipDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("membershipDir", "ASC");
                    }
                    else {
                        paramMap.put("membershipDir", "DESC");
                    }
                }
                listMap = webMembershipSqlMapDAO.selectTotalMembershipHistoryInfo(paramMap);

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("rows", listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectMembershipBalance END");
        return map;
    }

    /**
     * 멤버십고객 상세리스트 조회 (List, Excel)
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> downloadMembershipHistoryExcel(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl downloadMembershipHistoryExcel START");

        HashMap<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> listMap = null;

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("membershipSearchKeywordParam  :"+paramMap.get("membershipSearchKeywordParam"));
        log.debug("membershipSort                :"+paramMap.get("membershipSort"));

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("downloadUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "내려받기 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){
                // 정렬
                if(null==paramMap.get("membershipDir")||("").equals(paramMap.get("membershipDir"))){

                }
                else{
                    String dir = String.valueOf(paramMap.get("membershipDir"));
                    if(("A").equals(dir)){
                        paramMap.put("membershipDir", "DESC");
                    }
                    else if(("B").equals(dir)){
                        paramMap.put("membershipDir", "ASC");
                    }
                    else {
                        paramMap.put("membershipDir", "DESC");
                    }
                }

                paramMap.put("useYn", "Y");

                listMap = webMembershipSqlMapDAO.downloadMembershipHistoryExcel(paramMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl downloadMembershipHistoryExcel END");
        return listMap;
    }
    /**
     * 양수인 정보 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectToTransferUser(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectToTransferUser START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("membershipSearchKeywordParam        :"+paramMap.get("membershipSearchKeywordParam"));

        List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                paramMap.put("useYn", "Y");
                listMap = webMembershipSqlMapDAO.selectToTransferUser(paramMap);

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectToTransferUser END");
        return map;
    }
    /**
     * 양수/양도 상세 정보 조회
     *
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    public HashMap<String, Object> selectMembershipTransfer(
            HashMap<String, Object> paramMap) throws Exception {
        log.debug("WebMembershipServiceImpl selectMembershipTransfer START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        log.debug("muMembershipHistoryId        :"+paramMap.get("muMembershipHistoryId"));

        List<Map<String, Object>> listMap = new ArrayList<Map<String,Object>>();

        try{
            boolean check  = true;

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }
            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "조회 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "조회 정보가 없습니다.");
                }
            }
            if(true == check){
                paramMap.put("useYn", "Y");
                listMap = webMembershipSqlMapDAO.selectMembershipTransfer(paramMap);

                map.put("msgCode", Constants.OK);
                map.put("success","true");
                map.put("rows",listMap);
            }
        }
        catch(Exception e){
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl selectMembershipTransfer END");
        return map;
    }

    /**
     * 멤버십 양도
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> updateTransferMembership(
            HashMap<String, Object> paramMap) throws Exception{
        log.debug("WebMembershipServiceImpl updateTransferMembership START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId        :"+paramMap.get("loginMemberId"));
        log.debug("muMemberId           :"+paramMap.get("muMemberId"));
        log.debug("modId                :"+paramMap.get("modId"));
        log.debug("regId                :"+paramMap.get("regId"));

        log.debug("menuClass            :"+paramMap.get("menuClass"));

        log.debug("transferFromUserId               :"+paramMap.get("transferFromUserId"));
        log.debug("transferToUserId                 :"+paramMap.get("transferToUserId"));
        log.debug("finalAmount                      :"+paramMap.get("finalAmount"));
        log.debug("transferAmount                   :"+paramMap.get("transferAmount"));
        log.debug("remainingBalance                 :"+paramMap.get("remainingBalance"));
        log.debug("finalAmount                      :"+paramMap.get("finalAmount"));
        log.debug("transferAmount                   :"+paramMap.get("transferAmount"));
        log.debug("memo                             :"+paramMap.get("memo"));
        log.debug("membershipYn                     :"+paramMap.get("membershipYn"));


        try{
            boolean check  = true;
            String tId = String.valueOf(System.currentTimeMillis());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar c1 = Calendar.getInstance();
            String tDate = sdf.format(c1.getTime());

            String transferFromUserId         = String.valueOf(paramMap.get("transferFromUserId"));
            String transferToUserId        = String.valueOf(paramMap.get("transferToUserId"));
            String transferAmount        = String.valueOf(paramMap.get("transferAmount"));


            if(true != ValidationCheckUtil.emptyCheck(transferAmount)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","양도 멤버십 금액이 없습니다.");
            }


            if((transferFromUserId).equals(transferToUserId)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","본인에게 멤버십을 양도할 수 없습니다.");
            }



            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("insertUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "등록 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){
                paramMap.put("tDate", tDate);
                paramMap.put("tId", tId);

                HashMap<String, Object> paramData = new HashMap<>();
                //양수자가 기존 멤버십고객이 아닐때
                if(("N").equals(paramMap.get("membershipYn"))){
                    paramData.put("modId",paramMap.get("modId"));
                    paramData.put("muUserId",paramMap.get("transferToUserId"));
                    webUserSqlMapDAO.updateMembershipYn(paramData);
                    paramData.clear();
                    //양수자 멤버십테이블 추가
                    String muMembershipId = ("M").concat(String.valueOf(System.currentTimeMillis()));
                    paramData.put("muMembershipId",muMembershipId);
                    paramData.put("muUserId",transferToUserId);
                    paramData.put("membershipBalance",paramMap.get("finalAmount"));
                    paramData.put("regId",paramMap.get("regId"));
                    paramData.put("modId",paramMap.get("modId"));
                    paramData.put("tId",paramMap.get("tId"));
                    webMembershipSqlMapDAO.insertMembership(paramData);
                    paramData.clear();
                }else{
                    //양수자 멤버십테이블 수정
                    paramData.put("muUserId",transferToUserId);
                    paramData.put("membershipBalance",paramMap.get("finalAmount"));
                    paramData.put("lastRechargeDate",tDate);
                    paramData.put("tId",tId);
                    paramData.put("modId",paramMap.get("modId"));
                    webMembershipSqlMapDAO.updateMembership(paramData);
                    paramData.clear();
                }
                //양도자 멤버십테이블 수정
                paramData.put("muUserId",transferFromUserId);
                paramData.put("membershipBalance",paramMap.get("remainingBalance"));
                paramData.put("lastUseDate",tDate);
                paramData.put("tId",tId);
                paramData.put("modId",paramMap.get("modId"));
                webMembershipSqlMapDAO.updateMembership(paramData);
                paramData.clear();

                // 양도자 멤버십 내역 아이디
                String transmitterHistoryId = ("M").concat(String.valueOf(System.currentTimeMillis()));

                // 양수자 멤버십 내역 아이디
                String assigneeHistoryId = ("M").concat(String.valueOf(System.currentTimeMillis()));

                //양도자 멤버십 내역 추가
                paramData.put("muMembershipHistoryId",transmitterHistoryId);
                paramData.put("muUserId",transferFromUserId);
                paramData.put("transferToUserId",paramMap.get("transferToUserId"));
                paramData.put("muMemberId",paramMap.get("muMemberId"));
                paramData.put("beforeAmount",paramMap.get("availableBalance"));
                paramData.put("afterAmount",paramMap.get("remainingBalance"));
                paramData.put("usedAmount",paramMap.get("transferAmount"));
                paramData.put("memo",paramMap.get("memo"));
                paramData.put("regId",paramMap.get("regId"));
                paramData.put("modId",paramMap.get("modId"));
                paramData.put("tId",paramMap.get("tId"));
                paramData.put("usageType","T");
                webMembershipSqlMapDAO.insertMembershipHistory(paramData);
                paramMap.put("transferHistoryId",paramData.get("id"));
                paramData.clear();

                //양수자 멤버십 내역 추가
                paramData.put("muMembershipHistoryId",assigneeHistoryId);
                paramData.put("muUserId",transferToUserId);
                paramData.put("transferHistoryId",paramMap.get("transferHistoryId"));
                paramData.put("transferFromUserId",paramMap.get("transferFromUserId"));
                paramData.put("muMemberId",paramMap.get("muMemberId"));
                paramData.put("beforeAmount",paramMap.get("holdAmount"));
                paramData.put("afterAmount",paramMap.get("finalAmount"));
                paramData.put("rechargeAmount",paramMap.get("transferAmount"));
                paramData.put("memo",paramMap.get("memo"));
                paramData.put("regId",paramMap.get("regId"));
                paramData.put("modId",paramMap.get("modId"));
                paramData.put("tId",paramMap.get("tId"));
                paramData.put("usageType","P");
                webMembershipSqlMapDAO.insertMembershipHistory(paramData);

                log.debug("muMemberId :"+paramMap.get("id"));
                paramMap.put("muMemberId", paramMap.get("id"));
                map.put("muMemberId", paramMap.get("muMemberId"));

                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl updateTransferMembership END");
        return map;
    }
    /**
     * 멤버십 상품 정보 등록
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> insertMembershipProcedure(
            HashMap<String, Object> paramMap) throws Exception{
        log.debug("WebTreatmentProcedureServiceImpl insertMembershipProcedure START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId          :"+paramMap.get("loginMemberId"));

        log.debug("menuClass              :"+paramMap.get("menuClass"));

        log.debug("membershipProductRow            :"+paramMap.get("membershipProductRow"));

        try{
            boolean check  = true;
            String tId = String.valueOf(System.currentTimeMillis());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar c1 = Calendar.getInstance();
            String tDate = sdf.format(c1.getTime());

            // 상세 정보 확인
            // 약품
            JSONParser jsonParserTemp = new JSONParser();
            JSONObject jsonObjectTemp = (JSONObject) jsonParserTemp.parse(String.valueOf(paramMap.get("membershipProductRow")));
            if(jsonObjectTemp == null ||jsonObjectTemp.isEmpty()) {
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","멤버십 상품 정보가 없습니다.");
            }
            else {
                JSONArray detailArray = (JSONArray) jsonObjectTemp.get("data");

                for(int j=0; j<detailArray.size(); j++){
                    JSONObject detailObject = (JSONObject) detailArray.get(j);

                    String productName       = String.valueOf(detailObject.get("productName"));
                    String price 		     = String.valueOf(detailObject.get("price"));
                    String vat               = String.valueOf(detailObject.get("vat"));
                    String additionalAmount  = String.valueOf(detailObject.get("additionalAmount"));

                    if(true != ValidationCheckUtil.emptyCheck(productName)){
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc","멤버십 상품명 정보가 없습니다.");
                    }
                    if(true != ValidationCheckUtil.emptyCheck(price)){
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc","멤버십 상품금액 정보가 없습니다.");
                    }
                    if(true != ValidationCheckUtil.emptyCheck(vat)){
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc","멤버십 상품 VAT 정보가 없습니다.");
                    }

                    HashMap<String, Object> procedureDuplicateCheckMap = new HashMap<String, Object>();
                    procedureDuplicateCheckMap.put("procedureName",productName);
                    procedureDuplicateCheckMap.put("insuranceType",'N');
                    procedureDuplicateCheckMap.put("price",price);
                    procedureDuplicateCheckMap.put("vat",vat);
                    procedureDuplicateCheckMap.put("additionalAmount",additionalAmount);

        //			진료항목에 중복된 시술명 확인
                    if(0<webMembershipSqlMapDAO.selectMembershipProcedureCount(procedureDuplicateCheckMap)){
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "이미 등록된 시술입니다.");
                    }
                }
            }

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("insertUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "등록 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){
                paramMap.put("tDate", tDate);
                paramMap.put("tId", tId);

                JSONArray detailArray = (JSONArray) jsonObjectTemp.get("data");

                for(int j=0; j<detailArray.size(); j++) {
                    JSONObject detailObject = (JSONObject) detailArray.get(j);

                    String productName = String.valueOf(detailObject.get("productName"));
                    String price = String.valueOf(detailObject.get("price"));
                    String vat = String.valueOf(detailObject.get("vat"));
                    String additionalAmount = String.valueOf(detailObject.get("additionalAmount"));
                    String insuranceType = "N";

                    HashMap<String, Object> procedureMap = new HashMap<String, Object>();
                    procedureMap.put("procedureName", productName);
                    procedureMap.put("insuranceType", 'N');
                    procedureMap.put("price", price);
                    procedureMap.put("vat", vat);
                    procedureMap.put("additionalAmount", additionalAmount);


                    //  시술정보 등록
                    String muTreatmentProcedureId = ("TP").concat(String.valueOf(System.currentTimeMillis()));
                    procedureMap.put("muTreatmentProcedureId", muTreatmentProcedureId);
                    procedureMap.put("muMemberId", paramMap.get("loginMemberId"));
                    procedureMap.put("enableYn", "Y");
                    procedureMap.put("tId", tId);
                    procedureMap.put("tDate", tDate);
                    webMembershipSqlMapDAO.insertMembershipProcedure(procedureMap);

                    Object innerMapObj = procedureMap.get("key");
                    if (innerMapObj instanceof HashMap) {
                        @SuppressWarnings("unchecked")
                        HashMap<String, Object> innerMapCasted = (HashMap<String, Object>) innerMapObj;
                        String idValue = (String)innerMapCasted.get("id");
                        if (idValue != null) {
                            log.debug("muTreatmentProcedureId :" + idValue);
                            paramMap.put("muTreatmentProcedureId", idValue);
                            map.put("muTreatmentProcedureId", idValue);
                        }
                    }
                    //시술단가 등록
                    if ((null != insuranceType && !("").equals(insuranceType))
                            || (null != price && !("").equals(price))
                            || (null != vat && !("").equals(vat))
                            || (null != additionalAmount && !("").equals(additionalAmount))) {
                        HashMap<String, Object> TreatmentProcedurePriceParamMap = new HashMap<String, Object>();
                        String muTreatmentProcedurePriceId = ("TPP").concat(String.valueOf(System.currentTimeMillis()));
                        TreatmentProcedurePriceParamMap.put("tId", tId);
                        TreatmentProcedurePriceParamMap.put("muTreatmentProcedurePriceId", muTreatmentProcedurePriceId);
                        TreatmentProcedurePriceParamMap.put("muTreatmentProcedureId", paramMap.get("muTreatmentProcedureId"));
                        TreatmentProcedurePriceParamMap.put("insuranceType", insuranceType);
                        TreatmentProcedurePriceParamMap.put("price", price);
                        TreatmentProcedurePriceParamMap.put("vat", vat);
                        TreatmentProcedurePriceParamMap.put("additionalAmount", additionalAmount);
                        TreatmentProcedurePriceParamMap.put("regId", paramMap.get("regId"));
                        TreatmentProcedurePriceParamMap.put("modId", paramMap.get("modId"));
                        TreatmentProcedurePriceParamMap.put("tDate", paramMap.get("tDate"));
                        webMembershipSqlMapDAO.insertTreatmentProcedurePrice(TreatmentProcedurePriceParamMap);
                    }
                }

                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }

        log.debug("WebTreatmentProcedureServiceImpl insertMembershipProcedure END");
        return map;
    }

    /**
     * 멤버십 충전
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> insertMembership(
            HashMap<String, Object> paramMap) throws Exception{
        log.debug("WebMembershipServiceImpl insertMembership START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId        :"+paramMap.get("loginMemberId"));
        log.debug("muMemberId           :"+paramMap.get("muMemberId"));
        log.debug("modId                :"+paramMap.get("modId"));
        log.debug("regId                :"+paramMap.get("regId"));

        log.debug("menuClass            :"+paramMap.get("menuClass"));

        log.debug("muUserId                         :"+paramMap.get("muUserId"));
        log.debug("membershipBalance                :"+paramMap.get("membershipBalance"));
        log.debug("rechargeAmount                   :"+paramMap.get("rechargeAmount"));
        log.debug("membershipYn                     :"+paramMap.get("membershipYn"));


        try{
            boolean check  = true;
            String tId = String.valueOf(System.currentTimeMillis());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c1 = Calendar.getInstance();
            String tDate = sdf.format(c1.getTime());
            String tDate2 = sdf2.format(c1.getTime());

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("insertUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "등록 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){
                String paymentData          = String.valueOf(paramMap.get("paymentData"));
                String detailData           = String.valueOf(paramMap.get("detailData"));
                JSONParser parser = new JSONParser();

                paramMap.put("tDate", tDate);
                paramMap.put("tId", tId);

                // 고객 조회
                List<Map<String, Object>> userListMap = webUserSqlMapDAO.selectUser(paramMap);
                paramMap.put("userName", userListMap.get(0).get("userName"));
                paramMap.put("phoneNumber", userListMap.get(0).get("phoneNumber"));

				// 자동발송 (알림톡 + 푸시)
				// 템플릿 조회
				HashMap<String, Object> insertKakaoMap = new HashMap<String, Object>();
				insertKakaoMap.put("templateCode", "024110000458");
				List<Map<String, Object>> templateListMap = webKakaoTemplateSqlMapDAO.selectKakaoTemplate(insertKakaoMap);

				// 디바이스 리스트 조회
				List<Map<String, Object>> deviceListMap = webDeviceSqlMapDAO.selectListDevice2(paramMap);
				int deviceListMapSize = deviceListMap.size();

				// 고객명, 멤버십충전날짜, 멤버쉽충전금액
				String KakaoTemplateTitle = String.valueOf(templateListMap.get(0).get("title"));
				String KakaoTemplateContent = String.valueOf(templateListMap.get(0).get("content"));

                HashMap<String, Object> paramData = new HashMap<>();

                if(true == ValidationCheckUtil.emptyCheck(paymentData)) {
                    Object paymentObj = parser.parse( paymentData );
                    JSONArray paymentDataObj = (JSONArray) paymentObj;;
                    for (int i = 0; i < paymentDataObj.size(); i++) {
                        JSONObject jsonObject = (JSONObject) paymentDataObj.get(i);
                        HashMap<String, Object> dataMap = new HashMap<>();
                        String muPaymentId = ("PMT").concat(String.valueOf(System.currentTimeMillis()));
                        dataMap.put("muPaymentId", muPaymentId);
                        dataMap.put("paymentNumber", jsonObject.get("paymentNumber"));
                        dataMap.put("paymentApprovalId", jsonObject.get("paymentApprovalId"));
                        dataMap.put("muUserId", jsonObject.get("muUserId"));
                        dataMap.put("paymentCategoryItemId", jsonObject.get("paymentCategoryItemId"));
                        dataMap.put("paymentCategoryItemName", jsonObject.get("paymentCategoryItemName"));
                        dataMap.put("paymentCardInfo", jsonObject.get("paymentCardInfo"));
                        dataMap.put("cardInstallments", jsonObject.get("cardInstallments"));
                        dataMap.put("muMemberId", paramMap.get("muMemberId"));
                        dataMap.put("etc", jsonObject.get("etc"));
                        dataMap.put("refundEtc", jsonObject.get("refundEtc"));
                        dataMap.put("refundAccount", jsonObject.get("refundAccount"));
                        dataMap.put("amount", jsonObject.get("amount"));
                        dataMap.put("vat", jsonObject.get("vat"));
                        dataMap.put("paymentAmount", jsonObject.get("paymentAmount"));
                        dataMap.put("status",jsonObject.get("status") );
                        dataMap.put("modId", paramMap.get("modId"));
                        dataMap.put("regId", paramMap.get("modId"));
                        dataMap.put("tId", paramMap.get("tId"));
                        dataMap.put("tDate", paramMap.get("tDate"));
                        webPaymentSqlMapDAO.insertPayment(dataMap);
                        paramMap.put("muPaymentId", dataMap.get("id"));
                        paramMap.put("paymentNumber", dataMap.get("paymentNumber"));
                        paramMap.put("muUserId", dataMap.get("muUserId"));
                        paramMap.put("paymentCategoryItemName", jsonObject.get("paymentCategoryItemName"));
                        paramMap.put("paymentCategoryItemId", jsonObject.get("paymentCategoryItemId"));
                    }
                }
                if(true == ValidationCheckUtil.emptyCheck(detailData)) {
                    Object detailObj = parser.parse( detailData );
                    JSONArray detailDataObj = (JSONArray) detailObj;
                    for (int i = 0; i < 1; i++) {
                        JSONObject jsonObject = (JSONObject) detailDataObj.get(i);
                        HashMap<String, Object> dataMap = new HashMap<>();
                        String muPaymentDetailId = ("PMD").concat(String.valueOf(System.currentTimeMillis()));
                        dataMap.put("muPaymentDetailId", muPaymentDetailId);
                        dataMap.put("muPaymentId", paramMap.get("muPaymentId"));
                        dataMap.put("paymentNumber", paramMap.get("paymentNumber"));
                        dataMap.put("muReserveId", jsonObject.get("muReserveId"));
                        dataMap.put("muTreatmentId", jsonObject.get("muTreatmentId"));
                        dataMap.put("treatmentName", jsonObject.get("treatmentName"));
                        dataMap.put("treatmentProcedureName", jsonObject.get("treatmentProcedureName"));
                        dataMap.put("muTreatmentProcedureId", jsonObject.get("muTreatmentProcedureId"));
                        dataMap.put("reserveMemberId", jsonObject.get("reserveMemberId"));
                        dataMap.put("muMemberId", paramMap.get("muMemberId"));
                        dataMap.put("amount", jsonObject.get("amount"));
                        dataMap.put("vat", jsonObject.get("vat"));
                        dataMap.put("discountPrice", jsonObject.get("discountPrice"));
                        dataMap.put("membershipPrice", jsonObject.get("membershipPrice"));
                        dataMap.put("totalAmount", jsonObject.get("totalAmount"));
                        dataMap.put("status", 'Y');
                        dataMap.put("modId", paramMap.get("modId"));
                        dataMap.put("regId", paramMap.get("modId"));
                        dataMap.put("tId", paramMap.get("tId"));
                        dataMap.put("tDate", paramMap.get("tDate"));
                        webPaymentSqlMapDAO.insertPaymentDetail(dataMap);
                        paramMap.put("membershipPrice", dataMap.get("membershipPrice"));

                        //멤버십 내역 추가
                        String muMembershipHistoryId = ("M").concat(String.valueOf(System.currentTimeMillis()));
                        paramData.put("muMembershipHistoryId",muMembershipHistoryId);
                        paramData.put("muUserId",paramMap.get("muUserId"));
                        paramData.put("muMemberId",paramMap.get("muMemberId"));
                        paramData.put("muTreatmentId", jsonObject.get("muTreatmentId"));
                        paramData.put("muTreatmentProcedureId", jsonObject.get("muTreatmentProcedureId"));
                        paramData.put("rechargeAmount",paramMap.get("rechargeAmount"));
                        paramData.put("chargePaymentItemName",paramMap.get("paymentCategoryItemName"));
                        paramData.put("chargePaymentItemId",paramMap.get("paymentCategoryItemId"));
                        paramData.put("regId",paramMap.get("regId"));
                        paramData.put("modId",paramMap.get("modId"));
                        paramData.put("tId",paramMap.get("tId"));
                        paramData.put("usageType","C");
                        webMembershipSqlMapDAO.insertMembershipHistory(paramData);



						// 자동발송 (알림톡 + 푸시)
						// 고객명, 예약날짜, 예약시간, 시술명
						String kakaoContent = KakaoTemplateContent;
						kakaoContent = kakaoContent.replace("#{고객명}", String.valueOf(paramMap.get("userName")));
						kakaoContent = kakaoContent.replace("#{멤버십충전날짜}", tDate2);
						kakaoContent = kakaoContent.replace("#{멤버쉽충전금액}", String.valueOf(paramMap.get("rechargeAmount")));


						insertKakaoMap.put("muKakaoId", ("K").concat(String.valueOf(System.currentTimeMillis())));
						insertKakaoMap.put("muUserId", paramMap.get("muUserId"));
						insertKakaoMap.put("userName", paramMap.get("userName"));
						insertKakaoMap.put("phoneNumber", paramMap.get("phoneNumber"));
						insertKakaoMap.put("content", kakaoContent);
						insertKakaoMap.put("state", "R");
						insertKakaoMap.put("popbillState", "0");
						insertKakaoMap.put("sender", senderPhoneNumber);
						insertKakaoMap.put("regId", "SYSTEM");
						insertKakaoMap.put("modId", "SYSTEM");
						insertKakaoMap.put("tId", paramMap.get("tId"));
						insertKakaoMap.put("tDate", paramMap.get("tDate"));

						webKakaoSqlMapDAO.insertKakao(insertKakaoMap);
//                        autoKakaoService.send("membershipCharge", insertKakaoMap);

						// 푸시
						if(0<deviceListMapSize){
							HashMap<String, Object> insertPushMap = new HashMap<String, Object>();
							for(int j=0; j<deviceListMapSize; j++){
								insertPushMap.put("muPushId", ("P").concat(String.valueOf(System.currentTimeMillis())));
								insertPushMap.put("muUserId", paramMap.get("muUserId"));
								insertPushMap.put("userName", paramMap.get("userName"));
								insertPushMap.put("muDeviceId", deviceListMap.get(j).get("muDeviceId"));
								insertPushMap.put("deviceUuid", deviceListMap.get(j).get("deviceUuid"));
								insertPushMap.put("pushKey", deviceListMap.get(j).get("pushKey"));
								insertPushMap.put("pushType", "A");
								insertPushMap.put("phoneType", deviceListMap.get(j).get("phoneType"));
								insertPushMap.put("title", KakaoTemplateTitle);
								insertPushMap.put("content", kakaoContent);
								insertPushMap.put("state", "R");
								insertPushMap.put("regId", "SYSTEM");
								insertPushMap.put("modId", "SYSTEM");
								insertPushMap.put("tId", paramMap.get("tId"));
								insertPushMap.put("tDate", paramMap.get("tDate"));

								webPushSqlMapDAO.insertPush(insertPushMap);
//                                autoPushService.send("membershipCharge", insertPushMap);
							}
						}



                        paramData.clear();
                    }
                }

                //고객이 기존 멤버십고객이 아닐때
                if(("N").equals(paramMap.get("membershipYn"))){
                    paramData.put("modId",paramMap.get("modId"));
                    paramData.put("muUserId",paramMap.get("muUserId"));
                    webUserSqlMapDAO.updateMembershipYn(paramData);
                    paramData.clear();
                    //멤버십테이블 추가
                    String muMembershipId = ("M").concat(String.valueOf(System.currentTimeMillis()));
                    paramData.put("muMembershipId",muMembershipId);
                    paramData.put("muUserId",paramMap.get("muUserId"));
                    paramData.put("membershipBalance",paramMap.get("membershipBalance"));
                    paramData.put("regId",paramMap.get("regId"));
                    paramData.put("modId",paramMap.get("modId"));
                    paramData.put("tId",paramMap.get("tId"));
                    webMembershipSqlMapDAO.insertMembership(paramData);
                }else{
                    //멤버십테이블 수정
                    paramData.put("muUserId",paramMap.get("muUserId"));
                    paramData.put("membershipBalance",paramMap.get("membershipBalance"));
                    paramData.put("lastRechargeDate",tDate);
                    paramData.put("tId",tId);
                    paramData.put("modId",paramMap.get("modId"));
                    webMembershipSqlMapDAO.updateMembership(paramData);
                }
                log.debug("muMemberId :"+paramMap.get("id"));
                paramMap.put("muMemberId", paramMap.get("id"));
                map.put("muMemberId", paramMap.get("muMemberId"));

                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl insertMembership END");
        return map;
    }
    /**
     * 멤버십 포인트 충전
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> insertMembershipPoint(
            HashMap<String, Object> paramMap) throws Exception{
        log.debug("WebMembershipServiceImpl insertMembershipPoint START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId        :"+paramMap.get("loginMemberId"));
        log.debug("muMemberId           :"+paramMap.get("muMemberId"));
        log.debug("modId                :"+paramMap.get("modId"));
        log.debug("regId                :"+paramMap.get("regId"));

        log.debug("menuClass            :"+paramMap.get("menuClass"));

        log.debug("muUserId                         :"+paramMap.get("muUserId"));
        log.debug("membershipBalance                :"+paramMap.get("membershipBalance"));
        log.debug("rechargeAmount                   :"+paramMap.get("rechargeAmount"));
        log.debug("membershipYn                     :"+paramMap.get("membershipYn"));


        try{
            boolean check  = true;
            String tId = String.valueOf(System.currentTimeMillis());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar c1 = Calendar.getInstance();
            String tDate = sdf.format(c1.getTime());

            String muUserId                = String.valueOf(paramMap.get("muUserId"));
            String membershipBalance       = String.valueOf(paramMap.get("membershipBalance"));
            String rechargeAmount          = String.valueOf(paramMap.get("rechargeAmount"));
            String membershipYn            = String.valueOf(paramMap.get("membershipYn"));
            HashMap<String, Object> paramData = new HashMap<>();

            if(true != ValidationCheckUtil.emptyCheck(muUserId)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","고객 정보가 없습니다.");
            }
            if(true != ValidationCheckUtil.emptyCheck(membershipYn)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","멤버십 가입정보가 없습니다.");
            }
            if(true != ValidationCheckUtil.emptyCheck(membershipBalance)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","멤버십 잔액 정보가 없습니다.");
            }
            if(true != ValidationCheckUtil.emptyCheck(rechargeAmount)){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc","적립할 멤버십 포인트가 없습니다.");
            }

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("insertUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "등록 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){

                paramMap.put("tDate", tDate);
                paramMap.put("tId", tId);


                //고객이 기존 멤버십고객이 아닐때
                if(("N").equals(membershipYn)){
                    webUserSqlMapDAO.updateMembershipYn(paramMap);
                    //멤버십테이블 추가
                    String muMembershipId = ("M").concat(String.valueOf(System.currentTimeMillis()));
                    paramMap.put("muMembershipId",muMembershipId);
                    webMembershipSqlMapDAO.insertMembership(paramMap);
                }else{
                    //멤버십테이블 수정
                    webMembershipSqlMapDAO.updateMembership(paramMap);
                }

                //멤버십 내역 추가
                String muMembershipHistoryId = ("M").concat(String.valueOf(System.currentTimeMillis()));
                paramMap.put("muMembershipHistoryId",muMembershipHistoryId);
                paramMap.put("usageType","A");
                webMembershipSqlMapDAO.insertMembershipHistory(paramMap);

                log.debug("muMembershipHistoryId :"+paramMap.get("id"));
                paramMap.put("muMembershipHistoryId", paramMap.get("id"));
                map.put("muMembershipHistoryId", paramMap.get("muMemberId"));

                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "등록되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl insertMembershipPoint END");
        return map;
    }

    /**
     * 멤버십상품 정보 삭제
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
    public HashMap<String, Object> deleteMembershipProcedure(
            HashMap<String, Object> paramMap) throws Exception{
        log.debug("WebMembershipServiceImpl deleteMembershipProcedure START");

        HashMap<String, Object> map = new HashMap<String, Object>();

        log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));

        log.debug("menuClass           :"+paramMap.get("menuClass"));

        // ,로 구분
        log.debug("selectId            :"+paramMap.get("muTreatmentProcedureId"));

        try{
            boolean check  = true;

            if(null== paramMap.get("muTreatmentProcedureId") || ("").equals(paramMap.get("muTreatmentProcedureId"))){
                check = false;
                map.put("msgCode", Constants.FAIL);
                map.put("msgDesc", "삭제 대상이 없습니다.");
            }

            if(true == check){
                // 사용자 확인
                List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
                int userListMapSize = userListMap.size();

                if(1==userListMapSize){
                    paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
                }
            }

            if(true == check){
                // 권한 조회
                HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
                authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
                authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
                List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
                int authMenuRelationlistMapSize = authMenuRelationlistMap.size();

                if(1==authMenuRelationlistMapSize){

                    if(("Y").equals(authMenuRelationlistMap.get(0).get("deleteUseYn"))) {

                    }
                    else {
                        check = false;
                        map.put("msgCode", Constants.FAIL);
                        map.put("msgDesc", "삭제 권한 정보가 없습니다.");
                    }
                }
                else {
                    check = false;
                    map.put("msgCode", Constants.FAIL);
                    map.put("msgDesc", "권한 정보가 없습니다.");
                }
            }

            if(true == check){
                String selectId = String.valueOf(paramMap.get("muTreatmentProcedureId"));
                StringTokenizer selectData = new StringTokenizer(selectId, ",");
                while(selectData.hasMoreTokens()){//토큰이 계속 있을때 까지
                    String muTreatmentProcedureId = selectData.nextToken();

                    HashMap<String, Object> deleteParamMap = new HashMap<String, Object>();
                    deleteParamMap.put("muTreatmentProcedureId", muTreatmentProcedureId);
                    deleteParamMap.put("modId", paramMap.get("loginMemberId"));
                    webMembershipSqlMapDAO.deleteMembershipProcedure(deleteParamMap);
                }

                map.put("msgCode", Constants.OK);
                map.put("msgDesc", "삭제 되었습니다.");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        log.debug("WebMembershipServiceImpl deleteMembershipProcedure END");
        return map;
    }
}
