package com.madeu.service.web.webuserconsultingchart.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.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.webuserconsultingchart.WebUserConsultingChartSqlMapDAO;
import com.madeu.dao.web.webuserpushhistory.WebUserPushHistorySqlMapDAO;
import com.madeu.service.web.webuserconsultingchart.WebUserConsultingChartService;
import com.madeu.util.ValidationCheckUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("WebUserConsultingChartService")
public class WebUserConsultingChartServiceImpl implements WebUserConsultingChartService {
	
	@Autowired
	private WebUserConsultingChartSqlMapDAO webUserConsultingChartSqlMapDAO;
	
	@Autowired
	private WebMemberSqlMapDAO webMemberSqlMapDAO;
	
	@Autowired
	private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;
	
	@Autowired
	private WebUserPushHistorySqlMapDAO webUserPushHistorySqlMapDAO;
	
	/**
	 * 고객 상담차트 리스트 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListUserConsultingChartIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserConsultingChartServiceImpl selectListUserConsultingChartIntro 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("WebUserConsultingChartServiceImpl selectListUserConsultingChartIntro END");
		return map;
	}
	
	/**
	 * 고객 상담차트 리스트 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListUserConsultingChart(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserConsultingChartServiceImpl selectListUserConsultingChart 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 = webUserConsultingChartSqlMapDAO.selectTotalUserConsultingChartCount(paramMap);
				int totalCount = Integer.parseInt(String.valueOf(totalCountListMap.get(0).get("totalCount")));
				
				if(0 < totalCount) {
					// 리스트 조회
					listMap = webUserConsultingChartSqlMapDAO.selectListUserConsultingChart(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("WebUserConsultingChartServiceImpl selectListUserConsultingChart END");
		return map;
	}

	/**
	 * 고객 상담차트 리스트 출력
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectUserConsultingChartList(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserMedicalChartServiceImpl selectUserConsultingChartList START");

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

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

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

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

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

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

				String muUserConsultingChartId = String.valueOf(detailObject.get("muUserConsultingChartId"));

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

					consultingParamMap.put("muUserConsultingChartId",detailObject.get("muUserConsultingChartId"));
					listMap.add(webUserConsultingChartSqlMapDAO.selectUserConsultingChart(consultingParamMap));
				}

				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;
	}

	/**
	 * 고객 상세 - 고객 상담차트 리스트 조회 (List, Excel)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map<String, Object>> selectListUserConsultingChartExcel(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserConsultingChartServiceImpl selectListUserConsultingChartExcel 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 = webUserConsultingChartSqlMapDAO.selectListUserConsultingChartExcel(paramMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebUserConsultingChartServiceImpl selectListUserConsultingChartExcel END");
		return listMap;
	}
	
	/**
	 * 고객 상담차트 상세 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> updateUserConsultingChartIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserConsultingChartServiceImpl updateUserConsultingChartIntro START");

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

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

		log.debug("muUserConsultingChartId :"+paramMap.get("muUserConsultingChartId"));
		log.debug("muUserId                :"+paramMap.get("muUserId"));
		
		try{
			boolean check  = true;
			
			String menuClass               = String.valueOf(paramMap.get("menuClass"));
			String muUserConsultingChartId = String.valueOf(paramMap.get("muUserConsultingChartId"));
			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(muUserConsultingChartId)){
				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("WebUserConsultingChartServiceImpl updateUserConsultingChartIntro END");
		return map;
	}
	
	/**
	 * 고객 상담차트 정보 상세 조회 (one)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectUserConsultingChart(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebUserConsultingChartServiceImpl selectUserConsultingChart START");

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

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

		try{
			boolean check  = true;
			String muUserConsultingChartId = String.valueOf(paramMap.get("muUserConsultingChartId"));
			String muUserId                = String.valueOf(paramMap.get("muUserId"));
			
			if(true != ValidationCheckUtil.emptyCheck(muUserConsultingChartId)){
				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){
				List<Map<String, Object>> listMap = new ArrayList<>();
				listMap.add(webUserConsultingChartSqlMapDAO.selectUserConsultingChart(paramMap));
				
				// 최근 상담차트내역 Top5
				List<Map<String, Object>> userConsultingChartListMap = webUserConsultingChartSqlMapDAO.selectListUserConsultingChartTop5(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
				map.put("userConsultingChartList",userConsultingChartListMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebUserConsultingChartServiceImpl selectUserConsultingChart END");
		return map;
	}
	
	/**
	 * 고객 상담차트 정보 등록
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> insertUserConsultingChart(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebUserConsultingChartServiceImpl insertUserConsultingChart START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		// 상담 내용
		log.debug("content             :"+paramMap.get("content"));
		
		// 알림 발송
		log.debug("pushDate            :"+paramMap.get("pushDate"));
		log.debug("pushTime            :"+paramMap.get("pushTime"));
		log.debug("pushContent         :"+paramMap.get("pushContent"));

		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 content         = String.valueOf(paramMap.get("content"));
			
			String pushDate        = String.valueOf(paramMap.get("pushDate"));
			String pushTime        = String.valueOf(paramMap.get("pushTime"));
			String pushContent     = String.valueOf(paramMap.get("pushContent"));
			
			
			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);
				
				String muUserConsultingChartId = ("UCC").concat(String.valueOf(System.currentTimeMillis()));
				paramMap.put("muUserConsultingChartId",muUserConsultingChartId);
				paramMap.put("muMemberId", paramMap.get("loginMemberId"));
				webUserConsultingChartSqlMapDAO.insertUserConsultingChart(paramMap);
				log.debug("muUserConsultingChartId :"+paramMap.get("id"));
				paramMap.put("muUserConsultingChartId", paramMap.get("id"));
				map.put("muUserConsultingChartId", paramMap.get("muUserConsultingChartId"));
				
				// 알림 등록
				// 디바이스 조회 추가 필요.
				//webUserPushHistorySqlMapDAO.insertUserPushHistory(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "저장되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebUserConsultingChartServiceImpl insertUserConsultingChart END");
		return map;
	}

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

		// 상담 내용
		log.debug("content                 :"+paramMap.get("content"));
		
		// 알림 발송
		log.debug("pushDate                :"+paramMap.get("pushDate"));
		log.debug("pushTime                :"+paramMap.get("pushTime"));
		log.debug("pushContent             :"+paramMap.get("pushContent"));

		try{
			boolean check  = true;

			String muUserConsultingChartId  = String.valueOf(paramMap.get("muUserConsultingChartId"));
			String muUserId                 = String.valueOf(paramMap.get("muUserId"));
			
			String content                  = String.valueOf(paramMap.get("content"));
			
			String pushDate                 = String.valueOf(paramMap.get("pushDate"));
			String pushTime                 = String.valueOf(paramMap.get("pushTime"));
			String pushContent              = String.valueOf(paramMap.get("pushContent"));

			if(true != ValidationCheckUtil.emptyCheck(muUserConsultingChartId)){
				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){
				webUserConsultingChartSqlMapDAO.updateUserConsultingChart(paramMap);
				map.put("muUserConsultingChartId", paramMap.get("muUserConsultingChartId"));
				
				// 알림 등록
				// 디바이스 조회 추가 필요.
				//webUserPushHistorySqlMapDAO.insertUserPushHistory(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "저장되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebUserConsultingChartServiceImpl updateUserConsultingChart END");
		return map;
	}
	
}
