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

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.madeu.constants.Constants;
import com.madeu.dao.web.webauthmenurelation.WebAuthMenuRelationSqlMapDAO;
import com.madeu.dao.web.webmember.WebMemberSqlMapDAO;
import com.madeu.service.web.webmember.WebMemberService;
import com.madeu.util.SecurityUtil;
import com.madeu.util.ValidationCheckUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("WebMemberService")
public class WebMemberServiceImpl implements WebMemberService {
	
	@Autowired
	private WebMemberSqlMapDAO webMemberSqlMapDAO;
	
	@Autowired
	private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;
	
	/**
	 * 직원 아이디 조회 (List, option)
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectMemberId(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMemberServiceImpl selectMemberId START");

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

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

		try{
			boolean check  = true;
			
			if(true == check){
				int totalCount = webMemberSqlMapDAO.selectMemberId(String.valueOf(paramMap.get("loginId")))==null?0:1;
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("totalCount",totalCount);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl selectMemberId END");
		return map;
		}

		/**
		 * 닥터 리스트 조회 (List, option)
		 *
		 * @param paramMap
		 * @return
		 * @throws Exception
		 */
		@Override
		public HashMap<String, Object> selectListMemberDoctorOption(
				HashMap<String, Object> paramMap) throws Exception {
			log.debug("WebMemberServiceImpl selectListMemberDoctorOption START");

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

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

			try{
				boolean check  = true;

				if(true == check){
					List<Map<String, Object>> listMap = webMemberSqlMapDAO.selectListMemberDoctorOption(paramMap);

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

	/**
	 * 해당 시술 닥터 및 해당과 상담자 조회 (List, option)
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListMemberDoctorConsultingOption(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMemberServiceImpl selectListMemberDoctorConsultingOption START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		// 선택
		log.debug("searchDate             :"+paramMap.get("searchDate"));
		log.debug("searchTime             :"+paramMap.get("searchTime"));

		// 필수
		log.debug("muTreatmentProcedureId :"+paramMap.get("muTreatmentProcedureId"));

		try{
			boolean check  = true;
			
			String searchDate             = String.valueOf(paramMap.get("searchDate"));
			String muTreatmentProcedureId = String.valueOf(paramMap.get("muTreatmentProcedureId"));
			String muTreatmentProcedureIdList = "";
			
			if(true != ValidationCheckUtil.emptyCheck(muTreatmentProcedureId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술 정보가 없습니다.");
			}else{
				String [] muTreatmentProcedureIdArr = muTreatmentProcedureId.split(",");
				for(int i=0; i<muTreatmentProcedureIdArr.length; i++){
					muTreatmentProcedureIdList = muTreatmentProcedureIdList.concat("'").concat(muTreatmentProcedureIdArr[i]).concat("',");
				}

				muTreatmentProcedureIdList = muTreatmentProcedureIdList.substring(0, muTreatmentProcedureIdList.lastIndexOf(","));
				paramMap.put("muTreatmentProcedureIdList", muTreatmentProcedureIdList);
			}
			
			if(true == check){
				List<Map<String, Object>> listMap = webMemberSqlMapDAO.selectListMemberDoctorConsultingOption(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl selectListMemberDoctorConsultingOption END");
		return map;
	}
	
	/**
	 * 직원 리스트 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListMemberIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMemberServiceImpl selectListMemberIntro 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("WebMemberServiceImpl selectListMemberIntro END");
		return map;
	}
	
	/**
	 * 직원 리스트 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListMember(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMemberServiceImpl selectListMember START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("memberSearchKeywordParam  :"+paramMap.get("memberSearchKeywordParam"));
		log.debug("memberSort                :"+paramMap.get("memberSort"));
		log.debug("memberDir                 :"+paramMap.get("memberDir"));
		log.debug("memberStart               :"+paramMap.get("memberStart"));
		log.debug("memberLimit               :"+paramMap.get("memberLimit"));
		
		log.debug("memberSearchGroupId       :"+paramMap.get("memberSearchGroupId"));
		log.debug("memberSearchDutyId        :"+paramMap.get("memberSearchDutyId"));
		log.debug("memberSearchAuthId        :"+paramMap.get("memberSearchAuthId"));
		
		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);

				if(1==authMenuRelationlistMap.size()){

					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("memberDir")||("").equals(paramMap.get("memberDir"))){
					
				}
				else{
					String dir = String.valueOf(paramMap.get("memberDir"));
					if(("A").equals(dir)){
						paramMap.put("memberDir", "DESC");
					}
					else if(("B").equals(dir)){
						paramMap.put("memberDir", "ASC");
					}
					else {
						paramMap.put("memberDir", "DESC");
					}
				}
				
				paramMap.put("useYn", "Y");
				
				// 총 갯수 조회
				List<Map<String, Object>> totalCountListMap = webMemberSqlMapDAO.selectTotalMemberCount(paramMap);
				int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0).get("totalCount")));
				
				if(0 < totalCount) {
					// 리스트 조회
					listMap = webMemberSqlMapDAO.selectListMember(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("WebMemberServiceImpl selectListMember END");
		return map;
	}
	
	/**
	 * 직원 리스트 조회 (List, Excel)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map<String, Object>> selectListMemberExcel(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMemberServiceImpl selectListMemberExcel 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("memberSearchKeywordParam  :"+paramMap.get("memberSearchKeywordParam"));
		log.debug("memberSort                :"+paramMap.get("memberSort"));
		log.debug("memberDir                 :"+paramMap.get("memberDir"));
		log.debug("memberStart               :"+paramMap.get("memberStart"));
		log.debug("memberLimit               :"+paramMap.get("memberLimit"));
		
		log.debug("memberSearchGroupId       :"+paramMap.get("memberSearchGroupId"));
		log.debug("memberSearchDutyId        :"+paramMap.get("memberSearchDutyId"));
		log.debug("memberSearchAuthId        :"+paramMap.get("memberSearchAuthId"));
		
		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("memberDir")||("").equals(paramMap.get("memberDir"))){
					
				}
				else{
					String dir = String.valueOf(paramMap.get("memberDir"));
					if(("A").equals(dir)){
						paramMap.put("memberDir", "DESC");
					}
					else if(("B").equals(dir)){
						paramMap.put("memberDir", "ASC");
					}
					else {
						paramMap.put("memberDir", "DESC");
					}
				}
				
				paramMap.put("useYn", "Y");
				
				listMap = webMemberSqlMapDAO.selectListMemberExcel(paramMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl selectListMemberExcel END");
		return listMap;
	}
	
	/**
	 * 직원 수정 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> updateMemberIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMemberServiceImpl updateMemberIntro START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("muMemberid          :"+paramMap.get("muMemberid"));
		
		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("WebMemberServiceImpl updateMemberIntro END");
		return map;
	}
	
	/**
	 * 직원 정보 상세 조회 (one)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectMember(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebMemberServiceImpl selectMember START");

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

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

		try{
			boolean check  = true;
			String muMemberId    = String.valueOf(paramMap.get("muMemberId"));
			
			// 정렬
			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				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);

				if(1==authMenuRelationlistMap.size()){

					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){
				List<Map<String, Object>> listMap = webMemberSqlMapDAO.selectMember(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl selectMember END");
		return map;
	}
	
	/**
	 * 직원 정보 등록
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> insertMember(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebMemberServiceImpl insertMember START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("orderNumber         :"+paramMap.get("orderNumber"));
		log.debug("loginId             :"+paramMap.get("loginId"));
		log.debug("password            :"+paramMap.get("password"));
		log.debug("passwordConfirm     :"+paramMap.get("passwordConfirm"));
		log.debug("memberName          :"+paramMap.get("memberName"));
		log.debug("phoneNumber         :"+paramMap.get("phoneNumber"));
		log.debug("email               :"+paramMap.get("email"));
		log.debug("muGroupId           :"+paramMap.get("muGroupId"));
		log.debug("muDutyId            :"+paramMap.get("muDutyId"));
		log.debug("muAuthId            :"+paramMap.get("muAuthId"));
		log.debug("type                :"+paramMap.get("type"));

		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 orderNumber        = String.valueOf(paramMap.get("orderNumber"));
			String loginId            = String.valueOf(paramMap.get("loginId"));
			String password           = String.valueOf(paramMap.get("password"));
			String passwordConfirm    = String.valueOf(paramMap.get("passwordConfirm"));
			String memberName         = String.valueOf(paramMap.get("memberName"));
			String phoneNumber        = String.valueOf(paramMap.get("phoneNumber"));
			String email              = String.valueOf(paramMap.get("email"));
			String muGroupId          = String.valueOf(paramMap.get("muGroupId"));
			String muDutyId           = String.valueOf(paramMap.get("muDutyId"));
			String muAuthId           = String.valueOf(paramMap.get("muAuthId"));
			String type               = String.valueOf(paramMap.get("type"));
			
			if(true != ValidationCheckUtil.emptyCheck(orderNumber)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","정렬순서가 없습니다.");
			}
			if(true != ValidationCheckUtil.emptyCheck(loginId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","로그인 아이디 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.lengthCheck(loginId,255)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","로그인 아이디 정보는 255자를 넘을 수 없습니다.");
				}
			}
			
			if(true != ValidationCheckUtil.emptyCheck(password)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","비밀번호 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.passwordCheck2(password)) {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","비밀번호는 숫자,영문 조합으로 입력해야합니다.");
				}
				else if(true != ValidationCheckUtil.lengthCheck(password,100)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","비밀번호 정보는 100자를 넘을 수 없습니다.");
				}
			}
			
			if(!(password).equals(passwordConfirm)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","비밀번호와 비밀번호 확인 정보가 다릅니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(memberName)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","이름 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.lengthCheck(memberName,35)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","이름 정보는 35자를 넘을 수 없습니다.");
				}
			}
			
			if(true != ValidationCheckUtil.emptyCheck(phoneNumber)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","연락처 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(email)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","이메일 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.emailCheck(email)) {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","이메일 형식에 맞게 입력해주세요.");
				}
				else if(true != ValidationCheckUtil.lengthCheck(email,255)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","이메일 정보는 255자를 넘을 수 없습니다.");
				}
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muGroupId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","조직 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muDutyId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직무 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muAuthId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","권한 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(type)){
				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);
				
				// 사번코드 조회
				List<Map<String, Object>> productCodeListMap = webMemberSqlMapDAO.selectMemberCountSeq(paramMap);
				String memberCode = String.valueOf(productCodeListMap.get(0).get("memberCode"));
				
				paramMap.put("memberCode", memberCode);
				
				paramMap.put("password", SecurityUtil.encryptSHA256((String) paramMap.get("password")));
				
				String muMemberId = ("M").concat(String.valueOf(System.currentTimeMillis()));
				paramMap.put("muMemberId",muMemberId);
				paramMap.put("status", "Y");
				webMemberSqlMapDAO.insertMember(paramMap);
				webMemberSqlMapDAO.updateMemberOrderNumber(paramMap);
				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("WebMemberServiceImpl insertMember END");
		return map;
	}

	/**
	 * 직원 정보 수정
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateMember(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebMemberServiceImpl updateMember START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("muMemberId          :"+paramMap.get("muMemberId"));
		log.debug("orderNumber         :"+paramMap.get("orderNumber"));
		log.debug("loginId             :"+paramMap.get("loginId"));
		log.debug("memberName          :"+paramMap.get("memberName"));
		log.debug("phoneNumber         :"+paramMap.get("phoneNumber"));
		log.debug("email               :"+paramMap.get("email"));
		log.debug("muGroupId           :"+paramMap.get("muGroupId"));
		log.debug("muDutyId            :"+paramMap.get("muDutyId"));
		log.debug("muAuthId            :"+paramMap.get("muAuthId"));
		log.debug("type                :"+paramMap.get("type"));

		try{
			boolean check  = true;

			String muMemberId         = String.valueOf(paramMap.get("muMemberId"));
			String loginId            = String.valueOf(paramMap.get("loginId"));
			String memberName         = String.valueOf(paramMap.get("memberName"));
			String phoneNumber        = String.valueOf(paramMap.get("phoneNumber"));
			String email              = String.valueOf(paramMap.get("email"));
			String muGroupId          = String.valueOf(paramMap.get("muGroupId"));
			String muDutyId           = String.valueOf(paramMap.get("muDutyId"));
			String muAuthId           = String.valueOf(paramMap.get("muAuthId"));
			String type               = String.valueOf(paramMap.get("type"));
			String orderNumber        = String.valueOf(paramMap.get("orderNumber"));

			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직원 식별자 정보가 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(loginId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","로그인 아이디 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.lengthCheck(loginId,255)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","로그인 아이디 정보는 255자를 넘을 수 없습니다.");
				}
			}
			
			if(true != ValidationCheckUtil.emptyCheck(memberName)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","이름 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.lengthCheck(memberName,35)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","이름 정보는 35자를 넘을 수 없습니다.");
				}
			}
			
			if(true != ValidationCheckUtil.emptyCheck(phoneNumber)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","연락처 정보가 없습니다.");
			}
			if(true != ValidationCheckUtil.emptyCheck(orderNumber)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","정렬순서가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(email)){
				
			}
			else{
				if(true != ValidationCheckUtil.emailCheck(email)) {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","이메일 형식에 맞게 입력해주세요.");
				}
				else if(true != ValidationCheckUtil.lengthCheck(email,255)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","이메일 정보는 255자를 넘을 수 없습니다.");
				}
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muGroupId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","조직 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muDutyId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직무 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muAuthId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","권한 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(type)){
				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("updateUseYn"))) {
						
					}
					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){
				webMemberSqlMapDAO.updateMember(paramMap);
				webMemberSqlMapDAO.updateMemberOrderNumber(paramMap);
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "수정되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl updateMember END");
		return map;
	}

	/**
	 * 직원 계정 비활성화 수정
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateMemberStatus(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebMemberServiceImpl updateMemberStatus 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("selectId"));

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

		try{
			boolean check  = true;

			String selectId         = String.valueOf(paramMap.get("selectId"));
			String status           = String.valueOf(paramMap.get("status"));

			if(true != ValidationCheckUtil.emptyCheck(selectId)){
				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("updateUseYn"))) {
						
					}
					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){
				StringTokenizer selectData = new StringTokenizer(selectId, ",");
				while(selectData.hasMoreTokens()){//토큰이 계속 있을때 까지
					String muMemberId = selectData.nextToken();
					
					HashMap<String, Object> deleteParamMap = new HashMap<String, Object>();
					deleteParamMap.put("muMemberId", muMemberId);
					deleteParamMap.put("status", status);
					deleteParamMap.put("modId", paramMap.get("loginMemberId"));paramMap.put("status", "N");
					webMemberSqlMapDAO.updateMemberStatus(deleteParamMap);
				}
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "수정되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl updateMemberStatus END");
		return map;
	}
	
	/**
	 * 직원 비밀번호 정보 수정
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateMemberPassword(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebMemberServiceImpl updateMemberPassword START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("muMemberId          :"+paramMap.get("muMemberId"));
		log.debug("password            :"+paramMap.get("password"));
		log.debug("newPassword         :"+paramMap.get("newPassword"));
		log.debug("newPasswordConfirm  :"+paramMap.get("newPasswordConfirm"));

		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 muMemberId         = String.valueOf(paramMap.get("muMemberId"));
			String password           = String.valueOf(paramMap.get("password"));
			String newPassword        = String.valueOf(paramMap.get("newPassword"));
			String newPasswordConfirm = String.valueOf(paramMap.get("newPasswordConfirm"));
			
			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직원 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(password)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","기존 비밀번호 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(newPassword)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","새 비밀번호 정보가 없습니다.");
			}
			else{
				if(true != ValidationCheckUtil.passwordCheck2(newPassword)) {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","비밀번호는 숫자,영문 조합으로 입력해야합니다.");
				}
				else if(true != ValidationCheckUtil.lengthCheck(password,100)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","비밀번호 정보는 100자를 넘을 수 없습니다.");
				}
			}
			
			if(!(newPassword).equals(newPasswordConfirm)){
				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("updateUseYn"))) {
						
					}
					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){
				// 비밀번호 확인
				HashMap<String, Object> passwordParamMap = new HashMap<String, Object>();
				passwordParamMap.put("muMemberId",paramMap.get("muMemberId"));
				passwordParamMap.put("password", SecurityUtil.encryptSHA256((String) paramMap.get("password")));
				List<Map<String, Object>> passwordListMap = webMemberSqlMapDAO.selectMemberPassword(passwordParamMap);
				int totalCount = Integer.parseInt(String.valueOf(passwordListMap.get(0).get("totalCount")));
				
				if(totalCount==1){
					
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "기존 비밀번호 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				paramMap.put("password", SecurityUtil.encryptSHA256((String) paramMap.get("newPassword")));
				webMemberSqlMapDAO.updateMemberPassword(paramMap);

				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "수정되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl updateMemberPassword END");
		return map;
	}

	/**
	 * 직원 정보 삭제
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> deleteMember(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebMemberServiceImpl deleteMember 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("selectId"));
		
		try{
			boolean check  = true;
			
			if(null== paramMap.get("selectId") || ("").equals(paramMap.get("selectId"))){
				check = false;
			}

			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("selectId"));
				StringTokenizer selectData = new StringTokenizer(selectId, ",");
				while(selectData.hasMoreTokens()){//토큰이 계속 있을때 까지
					String muMemberId = selectData.nextToken();
					
					HashMap<String, Object> deleteParamMap = new HashMap<String, Object>();
					deleteParamMap.put("muMemberId", muMemberId);
					deleteParamMap.put("modId", paramMap.get("modId"));
					webMemberSqlMapDAO.deleteMember(deleteParamMap);
				}
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "삭제 되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebMemberServiceImpl deleteMember END");
		return map;
	}
}
