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

import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
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 com.madeu.constants.Constants;
import com.madeu.dao.web.webauthmenurelation.WebAuthMenuRelationSqlMapDAO;
import com.madeu.dao.web.webhospital.WebHospitalSqlMapDAO;
import com.madeu.dao.web.webhospitalholiday.WebHospitalHolidaySqlMapDAO;
import com.madeu.dao.web.webmember.WebMemberSqlMapDAO;
import com.madeu.service.web.webhospital.WebHospitalService;
import com.madeu.util.ValidationCheckUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service("WebHospitalService")
public class WebHospitalServiceImpl implements WebHospitalService {
	
	@Autowired
	private WebHospitalSqlMapDAO webHospitalSqlMapDAO;
	
	@Autowired
	private WebHospitalHolidaySqlMapDAO webHospitalHolidaySqlMapDAO;
	
	@Autowired
	private WebMemberSqlMapDAO webMemberSqlMapDAO;
	
	@Autowired
	private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;


	/**
	 * 병원 상세 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectHospitalIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebHospitalServiceImpl selectHospitalIntro 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("WebHospitalServiceImpl selectHospitalIntro END");
		return map;
	}
	
	
	/**
	 * 병원 정보 상세 조회 (one)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectHospital(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebHospitalServiceImpl selectHospital 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;
			
			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>> hospitalListMap = webHospitalSqlMapDAO.selectHospital(paramMap);
				int hospitalListMapSize = hospitalListMap.size();
				
				if(1 == hospitalListMapSize){
					// 병원 휴일 정보 조회
					paramMap.put("muHospitalId", hospitalListMap.get(0).get("muHospitalId"));
					List<Map<String, Object>> hospitalHolidayListMap = webHospitalHolidaySqlMapDAO.selectListHospitalHoliday(paramMap);
					
					hospitalListMap.get(0).put("holidayRows", hospitalHolidayListMap);
					
					map.put("msgCode", Constants.OK);
					map.put("success","true");
					map.put("rows",hospitalListMap);
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "병원 정보가 없습니다.");
				}
				
			}

		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebHospitalServiceImpl selectHospital END");
		return map;
	}

	/**
	 * 병원 운영시간 정보 (option)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectWorkTime(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebHospitalServiceImpl selectWorkTime 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;

			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>> hospitalListMap = webHospitalSqlMapDAO.selectHospital(paramMap);
				int hospitalListMapSize = hospitalListMap.size();

				if(1 == hospitalListMapSize){
					// 병원 휴일 정보 조회
					paramMap.put("muHospitalId", hospitalListMap.get(0).get("muHospitalId"));
					List<Map<String, Object>> hospitalHolidayListMap = webHospitalHolidaySqlMapDAO.selectListHospitalHoliday(paramMap);

					hospitalListMap.get(0).put("holidayRows", hospitalHolidayListMap);

					map.put("msgCode", Constants.OK);
					map.put("success","true");
					map.put("rows",hospitalListMap);
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "병원 정보가 없습니다.");
				}

			}

		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		log.debug("WebHospitalServiceImpl selectWorkTime END");
		return map;
	}
	
	/**
	 * 병원 정보 수정
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateHospital(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebHospitalServiceImpl updateHospital START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("muHospitalId        :"+paramMap.get("muHospitalId"));
		
		log.debug("monOpenYn           :"+paramMap.get("monOpenYn"));
		log.debug("monOpenStartTime    :"+paramMap.get("monOpenStartTime"));
		log.debug("monOpenEndTime      :"+paramMap.get("monOpenEndTime"));
		log.debug("monBreakStartTime   :"+paramMap.get("monBreakStartTime"));
		log.debug("monBreakEndTime     :"+paramMap.get("monBreakEndTime"));
		log.debug("tueOpenYn           :"+paramMap.get("tueOpenYn"));
		log.debug("tueOpenStartTime    :"+paramMap.get("tueOpenStartTime"));
		log.debug("tueOpenEndTime      :"+paramMap.get("tueOpenEndTime"));
		log.debug("tueBreakStartTime   :"+paramMap.get("tueBreakStartTime"));
		log.debug("tueBreakEndTime     :"+paramMap.get("tueBreakEndTime"));
		log.debug("wedOpenYn           :"+paramMap.get("wedOpenYn"));
		log.debug("wedOpenStartTime    :"+paramMap.get("wedOpenStartTime"));
		log.debug("wedOpenEndTime      :"+paramMap.get("wedOpenEndTime"));
		log.debug("wedBreakStartTime   :"+paramMap.get("wedBreakStartTime"));
		log.debug("wedBreakEndTime     :"+paramMap.get("wedBreakEndTime"));
		log.debug("thuOpenYn           :"+paramMap.get("thuOpenYn"));
		log.debug("thuOpenStartTime    :"+paramMap.get("thuOpenStartTime"));
		log.debug("thuOpenEndTime      :"+paramMap.get("thuOpenEndTime"));
		log.debug("thuBreakStartTime   :"+paramMap.get("thuBreakStartTime"));
		log.debug("thuBreakEndTime     :"+paramMap.get("thuBreakEndTime"));
		log.debug("friOpenYn           :"+paramMap.get("friOpenYn"));
		log.debug("friOpenStartTime    :"+paramMap.get("friOpenStartTime"));
		log.debug("friOpenEndTime      :"+paramMap.get("friOpenEndTime"));
		log.debug("friBreakStartTime   :"+paramMap.get("friBreakStartTime"));
		log.debug("friBreakEndTime     :"+paramMap.get("friBreakEndTime"));
		log.debug("satOpenYn           :"+paramMap.get("satOpenYn"));
		log.debug("satOpenStartTime    :"+paramMap.get("satOpenStartTime"));
		log.debug("satOpenEndTime      :"+paramMap.get("satOpenEndTime"));
		log.debug("satBreakStartTime   :"+paramMap.get("satBreakStartTime"));
		log.debug("satBreakEndTime     :"+paramMap.get("satBreakEndTime"));
		log.debug("sunOpenYn           :"+paramMap.get("sunOpenYn"));
		log.debug("sunOpenStartTime    :"+paramMap.get("sunOpenStartTime"));
		log.debug("sunOpenEndTime      :"+paramMap.get("sunOpenEndTime"));
		log.debug("sunBreakStartTime   :"+paramMap.get("sunBreakStartTime"));
		log.debug("sunBreakEndTime     :"+paramMap.get("sunBreakEndTime"));
		log.debug("publicHolidayUseYn  :"+paramMap.get("publicHolidayUseYn"));
		
		log.debug("holidayRows         :"+paramMap.get("holidayRows"));

		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 muHospitalId     = String.valueOf(paramMap.get("muHospitalId"));
			
			String monOpenYn           = String.valueOf(paramMap.get("monOpenYn"));
			String monOpenStartTime    = String.valueOf(paramMap.get("monOpenStartTime"));
			String monOpenEndTime      = String.valueOf(paramMap.get("monOpenEndTime"));
			String monBreakStartTime   = String.valueOf(paramMap.get("monBreakStartTime"));
			String monBreakEndTime     = String.valueOf(paramMap.get("monBreakEndTime"));
			String tueOpenYn           = String.valueOf(paramMap.get("tueOpenYn"));
			String tueOpenStartTime    = String.valueOf(paramMap.get("tueOpenStartTime"));
			String tueOpenEndTime      = String.valueOf(paramMap.get("tueOpenEndTime"));
			String tueBreakStartTime   = String.valueOf(paramMap.get("tueBreakStartTime"));
			String tueBreakEndTime     = String.valueOf(paramMap.get("tueBreakEndTime"));
			String wedOpenYn           = String.valueOf(paramMap.get("wedOpenYn"));
			String wedOpenStartTime    = String.valueOf(paramMap.get("wedOpenStartTime"));
			String wedOpenEndTime      = String.valueOf(paramMap.get("wedOpenEndTime"));
			String wedBreakStartTime   = String.valueOf(paramMap.get("wedBreakStartTime"));
			String wedBreakEndTime     = String.valueOf(paramMap.get("wedBreakEndTime"));
			String thuOpenYn           = String.valueOf(paramMap.get("thuOpenYn"));
			String thuOpenStartTime    = String.valueOf(paramMap.get("thuOpenStartTime"));
			String thuOpenEndTime      = String.valueOf(paramMap.get("thuOpenEndTime"));
			String thuBreakStartTime   = String.valueOf(paramMap.get("thuBreakStartTime"));
			String thuBreakEndTime     = String.valueOf(paramMap.get("thuBreakEndTime"));
			String friOpenYn           = String.valueOf(paramMap.get("friOpenYn"));
			String friOpenStartTime    = String.valueOf(paramMap.get("friOpenStartTime"));
			String friOpenEndTime      = String.valueOf(paramMap.get("friOpenEndTime"));
			String friBreakStartTime   = String.valueOf(paramMap.get("friBreakStartTime"));
			String friBreakEndTime     = String.valueOf(paramMap.get("friBreakEndTime"));
			String satOpenYn           = String.valueOf(paramMap.get("satOpenYn"));
			String satOpenStartTime    = String.valueOf(paramMap.get("satOpenStartTime"));
			String satOpenEndTime      = String.valueOf(paramMap.get("satOpenEndTime"));
			String satBreakStartTime   = String.valueOf(paramMap.get("satBreakStartTime"));
			String satBreakEndTime     = String.valueOf(paramMap.get("satBreakEndTime"));
			String sunOpenYn           = String.valueOf(paramMap.get("sunOpenYn"));
			String sunOpenStartTime    = String.valueOf(paramMap.get("sunOpenStartTime"));
			String sunOpenEndTime      = String.valueOf(paramMap.get("sunOpenEndTime"));
			String sunBreakStartTime   = String.valueOf(paramMap.get("sunBreakStartTime"));
			String sunBreakEndTime     = String.valueOf(paramMap.get("sunBreakEndTime"));
			String publicHolidayUseYn  = String.valueOf(paramMap.get("publicHolidayUseYn"));
			

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

			if(("Y").equals(monOpenYn)){
				if(true != ValidationCheckUtil.emptyCheck(monOpenStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","월요일 운영 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(monOpenEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","월요일 운영 종료시간 정보가 없습니다.");
				}

				if(true != ValidationCheckUtil.emptyCheck(monBreakStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","월요일 휴게 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(monBreakEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","월요일 휴게 종료시간 정보가 없습니다.");
				}
			}
			else {
				monOpenYn = "N";
				monOpenStartTime = "00:00";
				monOpenEndTime = "00:00";
				monBreakStartTime = "00:00";
				monBreakEndTime = "00:00";
			}
			
			if(("Y").equals(tueOpenYn)){
				if(true != ValidationCheckUtil.emptyCheck(tueOpenStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","화요일 운영 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(tueOpenEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","화요일 운영 종료시간 정보가 없습니다.");
				}

				if(true != ValidationCheckUtil.emptyCheck(tueBreakStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","화요일 휴게 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(tueBreakEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","화요일 휴게 종료시간 정보가 없습니다.");
				}
			}
			else {
				tueOpenYn = "N";
				tueOpenStartTime = "00:00";
				tueOpenEndTime = "00:00";
				tueBreakStartTime = "00:00";
				tueBreakEndTime = "00:00";
			}
			
			if(("Y").equals(wedOpenYn)){
				if(true != ValidationCheckUtil.emptyCheck(wedOpenStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","수요일 운영 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(wedOpenEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","수요일 운영 종료시간 정보가 없습니다.");
				}

				if(true != ValidationCheckUtil.emptyCheck(wedBreakStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","수요일 휴게 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(wedBreakEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","수요일 휴게 종료시간 정보가 없습니다.");
				}
			}
			else {
				wedOpenYn = "N";
				wedOpenStartTime = "00:00";
				wedOpenEndTime = "00:00";
				wedBreakStartTime = "00:00";
				wedBreakEndTime = "00:00";
			}
			
			if(("Y").equals(thuOpenYn)){
				if(true != ValidationCheckUtil.emptyCheck(thuOpenStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","목요일 운영 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(thuOpenEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","목요일 운영 종료시간 정보가 없습니다.");
				}

				if(true != ValidationCheckUtil.emptyCheck(thuBreakStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","목요일 휴게 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(thuBreakEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","목요일 휴게 종료시간 정보가 없습니다.");
				}
			}
			else {
				thuOpenYn = "N";
				thuOpenStartTime = "00:00";
				thuOpenEndTime = "00:00";
				thuBreakStartTime = "00:00";
				thuBreakEndTime = "00:00";
			}
			
			if(("Y").equals(friOpenYn)){
				if(true != ValidationCheckUtil.emptyCheck(friOpenStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","금요일 운영 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(friOpenEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","금요일 운영 종료시간 정보가 없습니다.");
				}

				if(true != ValidationCheckUtil.emptyCheck(friBreakStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","금요일 휴게 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(friBreakEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","금요일 휴게 종료시간 정보가 없습니다.");
				}
			}
			else {
				friOpenYn = "N";
				friOpenStartTime = "00:00";
				friOpenEndTime = "00:00";
				friBreakStartTime = "00:00";
				friBreakEndTime = "00:00";
			}
			
			if(("Y").equals(satOpenYn)){
				if(true != ValidationCheckUtil.emptyCheck(satOpenStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","토요일 운영 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(satOpenEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","토요일 운영 종료시간 정보가 없습니다.");
				}

				if(true != ValidationCheckUtil.emptyCheck(satBreakStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","토요일 휴게 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(satBreakEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","토요일 휴게 종료시간 정보가 없습니다.");
				}
			}
			else {
				satOpenYn = "N";
				satOpenStartTime = "00:00";
				satOpenEndTime = "00:00";
				satBreakStartTime = "00:00";
				satBreakEndTime = "00:00";
			}
			
			if(("Y").equals(sunOpenYn)){
				if(true != ValidationCheckUtil.emptyCheck(sunOpenStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","일요일 운영 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(sunOpenEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","일요일 운영 종료시간 정보가 없습니다.");
				}

				if(true != ValidationCheckUtil.emptyCheck(sunBreakStartTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","일요일 휴게 시작시간 정보가 없습니다.");
				}
				
				if(true != ValidationCheckUtil.emptyCheck(sunBreakEndTime)){
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc","일요일 휴게 종료시간 정보가 없습니다.");
				}
			}
			else {
				sunOpenYn = "N";
				sunOpenStartTime = "00:00";
				sunOpenEndTime = "00:00";
				sunBreakStartTime = "00:00";
				sunBreakEndTime = "00:00";
			}
			
			if(true != ValidationCheckUtil.emptyCheck(publicHolidayUseYn)){
				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){
				paramMap.put("tDate", tDate);
				paramMap.put("tId", tId);
				
				webHospitalSqlMapDAO.updateHospital(paramMap);
				
				// 휴일정보 삭제
				webHospitalHolidaySqlMapDAO.deleteHospitalHoliday(paramMap);
				
				// 휴일정보 등록
				JSONParser jsonParser = new JSONParser();
				JSONObject jsonObject = (JSONObject) jsonParser.parse(String.valueOf(paramMap.get("holidayRows")));
				JSONArray detailArray = (JSONArray) jsonObject.get("data");
				
				for(int j=0; j<detailArray.size(); j++){
					JSONObject detailObject = (JSONObject) detailArray.get(j);
					
					String hospitalHolidayName = String.valueOf(detailObject.get("hospitalHolidayName"));
					String locDate             = String.valueOf(detailObject.get("locDate"));
					String repeatYn            = String.valueOf(detailObject.get("repeatYn"));
					
					if((null!=hospitalHolidayName&&!("").equals(hospitalHolidayName))
							||(null!=locDate&&!("").equals(locDate))
							||(null!=repeatYn&&!("").equals(repeatYn))) {
						HashMap<String, Object> holidayParamMap = new HashMap<String, Object>();
						String muHospitalHolidayId = ("HH").concat(String.valueOf(System.currentTimeMillis()));
						holidayParamMap.put("muHospitalHolidayId",muHospitalHolidayId);
						holidayParamMap.put("muHospitalId", paramMap.get("muHospitalId"));
						holidayParamMap.put("hospitalHolidayName", hospitalHolidayName);
						holidayParamMap.put("locDate", locDate);
						holidayParamMap.put("repeatYn", repeatYn);
						holidayParamMap.put("regId", paramMap.get("regId"));
						holidayParamMap.put("modId", paramMap.get("modId"));
						holidayParamMap.put("tId", paramMap.get("tId"));
						holidayParamMap.put("tDate", paramMap.get("tDate"));
						webHospitalHolidaySqlMapDAO.insertHospitalHoliday(holidayParamMap);
					}
				}
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "수정되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		log.debug("WebHospitalServiceImpl updateHospital END");
		return map;
	}
}
