package com.madeu.service.web.webusermedicalchart.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 org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
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.dao.web.webusermedicalchart.WebUserMedicalChartSqlMapDAO;
import com.madeu.dao.web.webuserpushhistory.WebUserPushHistorySqlMapDAO;
import com.madeu.service.web.webusermedicalchart.WebUserMedicalChartService;
import com.madeu.util.ValidationCheckUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("WebUserMedicalChartService")
public class WebUserMedicalChartServiceImpl implements WebUserMedicalChartService {
	
	@Autowired
	private WebUserMedicalChartSqlMapDAO webUserMedicalChartSqlMapDAO;
	
	@Autowired
	private WebMemberSqlMapDAO webMemberSqlMapDAO;
	
	@Autowired
	private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;
	
	/**
	 * 고객 시술차트 리스트 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListUserMedicalChartIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserMedicalChartServiceImpl selectListUserMedicalChartIntro 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("WebUserMedicalChartServiceImpl selectListUserMedicalChartIntro END");
		return map;
	}
	
	/**
	 * 고객 시술차트 리스트 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListUserMedicalChart(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserMedicalChartServiceImpl selectListUserMedicalChart START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("searchKeywordParam  :"+paramMap.get("searchKeywordParam"));
		log.debug("sort                :"+paramMap.get("sort"));
		log.debug("start               :"+paramMap.get("start"));
		log.debug("limit               :"+paramMap.get("limit"));
		log.debug("sort                :"+paramMap.get("sort"));
		log.debug("dir                 :"+paramMap.get("dir"));
		log.debug("currentPage         :"+paramMap.get("currentPage"));
		
		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("dir")||("").equals(paramMap.get("dir"))){
					
				}
				else{
					String dir = String.valueOf(paramMap.get("dir"));
					if(("A").equals(dir)){
						paramMap.put("dir", "DESC");
					}
					else if(("B").equals(dir)){
						paramMap.put("dir", "ASC");
					}
					else {
						paramMap.put("dir", "DESC");
					}
				}
				
				paramMap.put("useYn", "Y");
				
				List<Map<String, Object>> totalCountListMap = webUserMedicalChartSqlMapDAO.selectTotalUserMedicalChartCount(paramMap);
				int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0).get("totalCount")));
				
				if(0 < totalCount) {
					// 리스트 조회
					listMap = webUserMedicalChartSqlMapDAO.selectListUserMedicalChart(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("WebUserMedicalChartServiceImpl selectListUserMedicalChart END");
		return map;
	}
	
	/**
	 * 고객 상세 - 고객 시술차트 리스트 조회 (List, Excel)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map<String, Object>> selectListUserMedicalChartExcel(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserMedicalChartServiceImpl selectListUserMedicalChartExcel 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("searchKeywordParam  :"+paramMap.get("searchKeywordParam"));
		log.debug("sort                :"+paramMap.get("sort"));
		log.debug("start               :"+paramMap.get("start"));
		log.debug("limit               :"+paramMap.get("limit"));
		log.debug("sort                :"+paramMap.get("sort"));
		log.debug("dir                 :"+paramMap.get("dir"));
		log.debug("currentPage         :"+paramMap.get("currentPage"));
		
		log.debug("searchStartDate     :"+paramMap.get("searchStartDate"));
		log.debug("searchEndDate       :"+paramMap.get("searchEndDate"));
		
		log.debug("muTreatmentId          :"+paramMap.get("muTreatmentId"));
		log.debug("muTreatmentProcedureId :"+paramMap.get("muTreatmentProcedureId"));
		log.debug("reserveMemberId        :"+paramMap.get("reserveMemberId"));
		
		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("dir")||("").equals(paramMap.get("dir"))){
					
				}
				else{
					String dir = String.valueOf(paramMap.get("dir"));
					if(("A").equals(dir)){
						paramMap.put("dir", "DESC");
					}
					else if(("B").equals(dir)){
						paramMap.put("dir", "ASC");
					}
					else {
						paramMap.put("dir", "DESC");
					}
				}
				
				paramMap.put("useYn", "Y");
				
				listMap = webUserMedicalChartSqlMapDAO.selectListUserMedicalChartExcel(paramMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebUserMedicalChartServiceImpl selectListUserMedicalChartExcel END");
		return listMap;
	}
	
	/**
	 * 고객 시술차트 상세 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> updateUserMedicalChartIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserMedicalChartServiceImpl updateUserMedicalChartIntro START");

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

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

		log.debug("muUserMedicalChartId    :"+paramMap.get("muUserMedicalChartId"));
		log.debug("muUserId                :"+paramMap.get("muUserId"));
		
		try{
			boolean check  = true;
			
			String menuClass               = String.valueOf(paramMap.get("menuClass"));
			String muUserMedicalChartId    = String.valueOf(paramMap.get("muUserMedicalChartId"));
			String muUserId                = String.valueOf(paramMap.get("muUserId"));
			
			if(true != ValidationCheckUtil.emptyCheck(menuClass)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","메뉴 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muUserMedicalChartId)){
				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("WebUserMedicalChartServiceImpl updateUserMedicalChartIntro END");
		return map;
	}
	
	/**
	 * 고객 시술차트 정보 상세 조회 (one)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectUserMedicalChart(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserMedicalChartServiceImpl selectUserMedicalChart START");

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

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

		try{
			boolean check  = true;
			String muUserMedicalChartId = String.valueOf(paramMap.get("muUserMedicalChartId"));
			String muUserId                = String.valueOf(paramMap.get("muUserId"));
			
			if(true != ValidationCheckUtil.emptyCheck(muUserMedicalChartId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시술차트 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muUserId)){
				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("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=new ArrayList<>();
				listMap.add(webUserMedicalChartSqlMapDAO.selectUserMedicalChart(paramMap));
				
				// 최근 시술차트내역 Top5
				List<Map<String, Object>> userMedicalChartListMap = webUserMedicalChartSqlMapDAO.selectListUserMedicalChartTop5(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
				map.put("userMedicalChartList",userMedicalChartListMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebUserMedicalChartServiceImpl selectUserMedicalChart END");
		return map;
	}

	/**
	 * 고객 시술차트 정보 상세 조회 (List)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectUserMedicalChartList(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserMedicalChartServiceImpl selectUserMedicalChartList START");

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

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

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

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

		try{
			boolean check  = true;
			JSONParser jsonParser = new JSONParser();
			JSONArray detailArray = (JSONArray) jsonParser.parse(String.valueOf(paramMap.get("muUserMedicalDataList")));

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

				String muUserMedicalChartId = String.valueOf(detailObject.get("muUserMedicalChartId"));
				String muUserId = String.valueOf(detailObject.get("muUserId"));

				if (true != ValidationCheckUtil.emptyCheck(muUserMedicalChartId)) {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "시술차트 정보가 없습니다.");
				}

				if (true != ValidationCheckUtil.emptyCheck(muUserId)) {
					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("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 = new ArrayList<>();
				for(int j=0; j<detailArray.size(); j++) {
					JSONObject detailObject = (JSONObject) detailArray.get(j);
					HashMap<String, Object> medicalParamMap = new HashMap<String, Object>();

					medicalParamMap.put("muUserId",detailObject.get("muUserId"));
					medicalParamMap.put("muUserMedicalChartId",detailObject.get("muUserMedicalChartId"));
					listMap.add(webUserMedicalChartSqlMapDAO.selectUserMedicalChart(medicalParamMap));
				}

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

	/**
	 * 고객 시술차트 정보 수정
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateUserMedicalChart(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebUserMedicalChartServiceImpl updateUserMedicalChart START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		log.debug("loginMemberId           :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass               :"+paramMap.get("menuClass"));
		
		log.debug("muUserMedicalChartId    :"+paramMap.get("muUserMedicalChartId"));

		// 상담 내용
		log.debug("content                 :"+paramMap.get("content"));

		try{
			boolean check  = true;

			String muUserMedicalChartId  = String.valueOf(paramMap.get("muUserMedicalChartId"));
			String content               = String.valueOf(paramMap.get("content"));

			if(true != ValidationCheckUtil.emptyCheck(muUserMedicalChartId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","고객 시술차트 식별자 정보가 없습니다.");
			}

			if(true != ValidationCheckUtil.emptyCheck(content)){
				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){
				webUserMedicalChartSqlMapDAO.updateUserMedicalChart(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "저장되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebUserMedicalChartServiceImpl updateUserMedicalChart END");
		return map;
	}
	
}
