package sgc.portal.mobile.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

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

import sgc.portal.base.exception.BusinessException;
import sgc.portal.base.util.SessionUtil;
import sgc.portal.com.sym.mail.service.MailService;
import sgc.portal.com.sym.user.model.UserDetails;
import sgc.portal.mobile.dto.RoomSearchVo;
import sgc.portal.mobile.model.CodeVo;
import sgc.portal.mobile.model.ZehrRomDisplVo;
import sgc.portal.mobile.model.ZehrRomInfoVo;
import sgc.portal.mobile.model.ZehrRomLoctnVo;
import sgc.portal.mobile.model.ZehrRomResrvtnVo;
import sgc.portal.mobile.persistence.RoomMapper;

/**
 * 회의실 예약 서비스
 * 
 * @author 5364
 * @since 2022-08-11
 */
@Service
public class RoomService {

	/**
	 * 회의실 예약 Mapper
	 */
	@Autowired
	private RoomMapper mapper;

	/**
	 * 메일 서비스
	 */
	@Autowired
	private MailService mailService;

	/**
	 * 회의실 위치 목록
	 * 
	 * @param search
	 * @return
	 */
	public List<ZehrRomLoctnVo> selectLocationList(RoomSearchVo search) {
		return mapper.selectLocationList(search);
	}

	/**
	 * 회의실 목록
	 * 
	 * @param search
	 * @return
	 */
	public List<ZehrRomInfoVo> selectRomInfoList(RoomSearchVo search) {
		return mapper.selectRomInfoList(search);
	}

	/**
	 * 회의실) 회의실 코드 리스트
	 * 
	 * @return
	 */
	public List<CodeVo> selectCodeRoomList(RoomSearchVo vo) {
		return mapper.selectCodeRoomList(vo);
	}
	
	/**
	 * 회의실 예약 디스플레이 정보
	 * 
	 * @param search
	 * @return
	 */
	public List<ZehrRomDisplVo> selectRomDayList(RoomSearchVo search) {
		return mapper.selectRomDayList(search);
	}

	/**
	 * 회의실 예약 정보 목록
	 * 
	 * @param search
	 * @return
	 */
	public List<ZehrRomResrvtnVo> selectRomResrvList(RoomSearchVo search) {
		return setRemAuth(mapper.selectRomResrvList(search));
	}

	/**
	 * 회의실 예약 정보 가져오기
	 * 
	 * @param search
	 * @return
	 */
	public ZehrRomResrvtnVo selectRomResrvView(RoomSearchVo search) {
		ZehrRomResrvtnVo view = mapper.selectRomResrvView(search);
		if (view != null) {
			List<ZehrRomResrvtnVo> list = new ArrayList<>();
			list.add(view);
			setRemAuth(list);
		}
		return view;
	}

	/**
	 * 회의실 예약 권한 확인
	 * 
	 * @param list
	 * @return
	 */
	private List<ZehrRomResrvtnVo> setRemAuth(List<ZehrRomResrvtnVo> list) {
		UserDetails userDtail = SessionUtil.getUserDetails();
		String empNo = "NONE";
		if (userDtail != null) {
			empNo = userDtail.getEmpNo();
		}
		for (ZehrRomResrvtnVo item : list) {
			String subscSabun = (String) item.getSubscSabun();
			item.setMyRomResrv(subscSabun != null && !"".equals(subscSabun) && subscSabun.equals(empNo));
			if ("N".equals(item.getCancelYn())) {
				switch (item.getStatus()) {
				case "40":
					item.setCancelCn("[반려]된 예약은 취소가 안됩니다.");
					break;
				case "50":
					item.setCancelCn("[종료]된 예약은 취소가 안됩니다.");
					break;
				case "60":
					item.setCancelCn("이미 취소한 예약입니다.");
					break;
				default:
					item.setCancelCn("지난 예약과 진행중인 예약은 취소가 안됩니다.");
					break;
				}
			} else {
				item.setCancelCn("예약취소 가능.");
			}
			if ("N".equals(item.getCloseYn())) {
				switch (item.getStatus()) {
				case "20":
					item.setCloseCn("[승인요청]중인 예약은 사용후기 작성이 안됩니다.");
					break;
				case "40":
					item.setCloseCn("[반려]된 예약은 사용후기 작성이 안됩니다.");
					break;
				case "50":
					item.setCloseCn("이미 종료한 예약입니다.");
					break;
				case "60":
					item.setCloseCn("[취소]된 예약은 사용후기 작성이 안됩니다.");
					break;
				default:
					item.setCloseCn("지난 예약과 진행중인 예약만 종료 가능합니다.");
					break;
				}
			} else {
				item.setCloseCn("예약종료 가능.");
			}

		}

		return list;
	}

	/**
	 * 회의실 예약 - 기존 예약 확인하기
	 * 
	 * @param search
	 * @param oldReservationId
	 * @return
	 */
	private ZehrRomDisplVo getUpdateZehrRomDisplVo(RoomSearchVo search, String oldReservationId) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd", Locale.KOREA);
		if (search.getEndYyyymmdd() == null || "".equals(search.getEndYyyymmdd())) {
			search.setEndYyyymmdd(search.getStartYyyymmdd());
		}
		if (search.getStartHhmm() == null || "".equals(search.getStartHhmm())) {
			search.setStartHhmm("0700");
		}
		if (search.getEndHhmm() == null || "".equals(search.getEndHhmm())) {
			search.setEndHhmm("2230");
		}
		if (search.getWeekList() != null && !search.getWeekList().isEmpty()) {
			for (String week : search.getWeekList()) {
				switch (week) {
				case "FR":
					search.setWeekFr("Y");
					break;
				case "MU":
					search.setWeekMu("Y");
					break;
				case "TH":
					search.setWeekTh("Y");
					break;
				case "TU":
					search.setWeekTu("Y");
					break;
				case "WE":
					search.setWeekWe("Y");
					break;
				}
			}
		}

		if (search.getWeekFr() == null || "".equals(search.getWeekFr())) {
			search.setWeekFr("N");
		}
		if (search.getWeekMu() == null || "".equals(search.getWeekMu())) {
			search.setWeekMu("N");
		}
		if (search.getWeekTh() == null || "".equals(search.getWeekTh())) {
			search.setWeekTh("N");
		}
		if (search.getWeekTu() == null || "".equals(search.getWeekTu())) {
			search.setWeekTu("N");
		}
		if (search.getWeekWe() == null || "".equals(search.getWeekWe())) {
			search.setWeekWe("N");
		}
		if (search.getKeyYn() == null || "".equals(search.getKeyYn())) {
			search.setKeyYn("N");
		}
		if (search.getKeysendYn() == null || "".equals(search.getKeysendYn())) {
			search.setKeysendYn("N");
		}
		search.setReservationId(oldReservationId);
		ZehrRomResrvtnVo reservationCheck = mapper.selectReservationCheck(search);
		if (reservationCheck != null) {
			throw new BusinessException("예약이 중복됩니다. 예약현황을 확인하세요. <br>" + reservationCheck.getMeetingName() + " / "
					+ reservationCheck.getPymd());
            //throw new BusinessException("예약이 중복됩니다. 예약현황을 확인하세요. <br>" + reservationCheck.getMeetingName() + " / "
            //        + reservationCheck.getPymd() + "[" + reservationCheck.getPhm() + "]");
		}

		List<String> checkColunmList = new ArrayList<>();
		Date startYyyymmdd = null;
		Date endYyyymmdd = null;
		Calendar calT = Calendar.getInstance();
		try {
			startYyyymmdd = dateFormat.parse(search.getStartYyyymmdd());
			endYyyymmdd = dateFormat.parse(search.getEndYyyymmdd());
		} catch (ParseException e) {
			throw new BusinessException("날자 형식에 오류가 있습니다.");
		}

		String startHhmm = search.getStartHhmm();
		String endHhmm = search.getEndHhmm();
		calT.setTime(startYyyymmdd);
		List<String> baseColunmList = Arrays.asList(
				"0700,0730,0800,0830,0900,0930,1000,1030,1100,1130,1200,1230,1300,1330,1400,1430,1500,1530,1600,1630,1700,1730,1800,1830,1900,1930,2000,2030,2100,2130,2200,2230"
						.split(","));
		int starIdx = baseColunmList.indexOf(startHhmm);
		int endIdx = baseColunmList.indexOf(endHhmm);
		if ("30".equals(search.getGubun())) {
			starIdx = 0;
			endIdx = baseColunmList.size();
		}
		for (String key : baseColunmList) {
			int currIdx = baseColunmList.indexOf(key);
			if (currIdx >= starIdx && currIdx < endIdx) {
				checkColunmList.add(key);
			}
		}
		List<Integer> validWeekDay = new ArrayList<>();
		if ("Y".equals(search.getWeekFr())) {
			validWeekDay.add(Calendar.FRIDAY);
		}
		if ("Y".equals(search.getWeekMu())) {
			validWeekDay.add(Calendar.MONDAY);
		}
		if ("Y".equals(search.getWeekTh())) {
			validWeekDay.add(Calendar.THURSDAY);
		}
		if ("Y".equals(search.getWeekTu())) {
			validWeekDay.add(Calendar.TUESDAY);
		}
		if ("Y".equals(search.getWeekWe())) {
			validWeekDay.add(Calendar.WEDNESDAY);
		}
		if (validWeekDay.isEmpty()) {
			validWeekDay.add(Calendar.FRIDAY);
			validWeekDay.add(Calendar.MONDAY);
			validWeekDay.add(Calendar.THURSDAY);
			validWeekDay.add(Calendar.TUESDAY);
			validWeekDay.add(Calendar.WEDNESDAY);
		}
		int periodDate = (int) ((endYyyymmdd.getTime() - startYyyymmdd.getTime()) / (24 * 60 * 60 * 1000));
		Date currYyyymmdd = new Date();
		long startTime = startYyyymmdd.getTime();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
		ZehrRomDisplVo romDisplVo = new ZehrRomDisplVo();
		romDisplVo.setMeetingroomId(search.getMeetingroomId());
		romDisplVo.setReYyyymmdd(search.getStartYyyymmdd());
		List<String> reYyyymmddList = new ArrayList<>();
		romDisplVo.setReYyyymmddList(reYyyymmddList);
		for (String colunm : checkColunmList) {
			switch (colunm) {
			case "0700":
				romDisplVo.setT070("UPDATE");
				break;
			case "0730":
				romDisplVo.setT073("UPDATE");
				break;
			case "0800":
				romDisplVo.setT080("UPDATE");
				break;
			case "0830":
				romDisplVo.setT083("UPDATE");
				break;
			case "0900":
				romDisplVo.setT090("UPDATE");
				break;
			case "0930":
				romDisplVo.setT093("UPDATE");
				break;
			case "1000":
				romDisplVo.setT100("UPDATE");
				break;
			case "1030":
				romDisplVo.setT103("UPDATE");
				break;
			case "1100":
				romDisplVo.setT110("UPDATE");
				break;
			case "1130":
				romDisplVo.setT113("UPDATE");
				break;
			case "1200":
				romDisplVo.setT120("UPDATE");
				break;
			case "1230":
				romDisplVo.setT123("UPDATE");
				break;
			case "1300":
				romDisplVo.setT130("UPDATE");
				break;
			case "1330":
				romDisplVo.setT133("UPDATE");
				break;
			case "1400":
				romDisplVo.setT140("UPDATE");
				break;
			case "1430":
				romDisplVo.setT143("UPDATE");
				break;
			case "1500":
				romDisplVo.setT150("UPDATE");
				break;
			case "1530":
				romDisplVo.setT153("UPDATE");
				break;
			case "1600":
				romDisplVo.setT160("UPDATE");
				break;
			case "1630":
				romDisplVo.setT163("UPDATE");
				break;
			case "1700":
				romDisplVo.setT170("UPDATE");
				break;
			case "1730":
				romDisplVo.setT173("UPDATE");
				break;
			case "1800":
				romDisplVo.setT180("UPDATE");
				break;
			case "1830":
				romDisplVo.setT183("UPDATE");
				break;
			case "1900":
				romDisplVo.setT190("UPDATE");
				break;
			case "1930":
				romDisplVo.setT193("UPDATE");
				break;
			case "2000":
				romDisplVo.setT200("UPDATE");
				break;
			case "2030":
				romDisplVo.setT203("UPDATE");
				break;
			case "2100":
				romDisplVo.setT210("UPDATE");
				break;
			case "2130":
				romDisplVo.setT213("UPDATE");
				break;
			case "2200":
				romDisplVo.setT220("UPDATE");
				break;
			case "2230":
				romDisplVo.setT223("UPDATE");
				break;
			}
		}

		for (int i = 0; i <= periodDate; i++) {
			currYyyymmdd.setTime(startTime + (long) i * 24L * 60L * 60L * 1000L);
			calT.setTime(currYyyymmdd);
			Integer dayOfWeek = calT.get(Calendar.DAY_OF_WEEK);
			switch (dayOfWeek) {
			case Calendar.SUNDAY:
			case Calendar.SATURDAY:
				break;
			default:
				String keyDate = simpleDateFormat.format(currYyyymmdd);
				if (validWeekDay.contains(dayOfWeek)) {
					reYyyymmddList.add(keyDate);
				}
				break;
			}
		}
		return romDisplVo;
	}

	/**
	 * 회의실 예약 하기
	 * 
	 * @param search
	 * @param type
	 * @return
	 */
	@Transactional
	public ZehrRomResrvtnVo insertRomResrvtn(RoomSearchVo search, String type) {
		switch (type) {
		case "normal":
			search.setEndYyyymmdd(search.getStartYyyymmdd());
			search.setWeekFr("Y");
			search.setWeekMu("Y");
			search.setWeekTh("Y");
			search.setWeekTu("Y");
			search.setWeekWe("Y");
			search.setGubun("10");
			break;
		case "repeat":
			if (!"20".equals(search.getWeek())) {
				search.setWeekFr("Y");
				search.setWeekMu("Y");
				search.setWeekTh("Y");
				search.setWeekTu("Y");
				search.setWeekWe("Y");
			}
			search.setGubun("20");
			break;
		case "range":
			search.setWeekFr("Y");
			search.setWeekMu("Y");
			search.setWeekTh("Y");
			search.setWeekTu("Y");
			search.setWeekWe("Y");
			search.setGubun("30");
			search.setStartHhmm("0700");
			search.setEndHhmm("2230");
			break;
		}
		search.setStatus("10");
		UserDetails userDetail = SessionUtil.getUserDetails();
		if (userDetail != null) {
			String userId = userDetail.getEmpNo();
			search.setMdftPr(userId);
			search.setWrtePr(userId);
			search.setDeptCd(userDetail.getDeptCd());
			search.setDeptName(userDetail.getDeptNm());
		} else {
			throw new BusinessException("직원만 예약이 가능합니다.");
		}
		ZehrRomDisplVo updateRomDispl = this.getUpdateZehrRomDisplVo(search, "0");
		if (!updateRomDispl.getReYyyymmddList().isEmpty()) {
		    switch(search.getGubun()) {
		        case "10" :
		        case "30" :
		            if ("Y".equals(search.getKeyYn()) || updateRomDispl.getReYyyymmddList().size() > 3) {
		                search.setStatus("20");
		            } else {
		                search.setStatus("10");
		            }
		            mapper.insertRomResrvtn(search);
		            mapper.insertRomHistr(search);
		            String reservationDisName = mapper.getReservationDisName(search);
		            updateRomDispl.setReservationDisName(reservationDisName);
		            mapper.updateRomDispl(updateRomDispl);
		            break;
		        case "20" :
		            search.setStatus("10");
		            List<String> reYyyymmddList = updateRomDispl.getReYyyymmddList();
		            for(String currDate : reYyyymmddList) {
		                search.setStartYyyymmdd(currDate);
		                search.setEndYyyymmdd(currDate);
                        mapper.insertRomResrvtn(search);
	                    mapper.insertRomHistr(search);
	                    String dayReservationDisName = mapper.getReservationDisName(search);
	                    updateRomDispl.setReservationDisName(dayReservationDisName);
	                    List<String> dayReYyyymmddList = new ArrayList<>();
	                    dayReYyyymmddList.add(currDate);
	                    updateRomDispl.setReYyyymmddList(dayReYyyymmddList);
	                    mapper.updateRomDispl(updateRomDispl);
	                }
		            break;
		    }
		} else {
			throw new BusinessException("해당 일자에 해당하는 예약 사항이 없습니다. 관리자에게 문의하세요.");
		}
		ZehrRomResrvtnVo result = this.selectRomResrvView(search);
		if ("20".equals(result.getStatus())) {
			List<CodeVo> mailList = mapper.selectApprovalEmailList(search);
			if (!mailList.isEmpty()) {
				StringBuffer sContent = new StringBuffer();
				String cmpnCd = result.getSubscCmpnCd();
				String srecvAddress = "";
				String sSender = result.getSubscSabun();
				String sSubject = "승인요청한 회의실 예약이 있습니다.";
				String ssubSubject = "회의실 승인요청";
				sContent.append("[회의실]승인요청한 회의실 예약이 있습니다.<br><br>");
				sContent.append("회   의    명  : " + result.getMeetingCon() + "<br>");
				sContent.append("예   약    자  : " + result.getSubscName() + "<br>");
				sContent.append("부        서  : " + result.getDeptName() + "<br>");
				sContent.append("기        간  : " + result.getStartYyyymmdd() + " ~ " + result.getEndYyyymmdd() + "<br>");
				sContent.append("열쇠사용 여부  : " + result.getKeyYn() + "<br>");
				for (CodeVo item : mailList) {
					srecvAddress = (String) item.getValue();
					mailService.mailSend(cmpnCd, sSubject, ssubSubject, sContent, sSender, srecvAddress);
				}
			}
		}
		return result;
	}

	/**
	 * ZehrRomResrvtnVo 로 RoomSearchVo 채우기
	 * 
	 * @param search
	 * @param view
	 * @return
	 */
	private RoomSearchVo synkRomResrvtn2Search(RoomSearchVo search, ZehrRomResrvtnVo view, String synkType) {
		search.setMeetingroomId(view.getMeetingroomId());
		search.setReservationId(view.getReservationId());
		search.setStartYyyymmdd(view.getStartYyyymmdd());
		search.setStartHhmm(view.getStartHhmm());
		switch(synkType) {
		    case "CLOSE" :
		        Date currYyyymmdd = new Date();
		        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
		        search.setEndYyyymmdd(simpleDateFormat.format(currYyyymmdd));
                break;
		    default :
		        search.setEndYyyymmdd(view.getEndYyyymmdd());
		        search.setEndHhmm(view.getEndHhmm());
		        break;
		}
		if (search.getEndYyyymmdd() == null || "".equals(search.getEndYyyymmdd())) {
		    search.setEndYyyymmdd(view.getEndYyyymmdd());
        }
		if (search.getEndHhmm() == null || "".equals(search.getEndHhmm())) {
	        search.setEndHhmm(view.getEndHhmm());
	    }
 		search.setWeekFr(view.getWeekFr());
		search.setWeekMu(view.getWeekMu());
		search.setWeekTh(view.getWeekTh());
		search.setWeekTu(view.getWeekTu());
		search.setWeekWe(view.getWeekWe());
		search.setGubun(view.getGubun());
		search.setSubscCmpnCd(view.getSubscCmpnCd());
		search.setSubscSabun(view.getSubscSabun());
		return search;
	}

	/**
	 * 회의실 예약 상태 변경
	 * 
	 * @param search
	 * @param updateType
	 * @return
	 */
	@Transactional
	public ZehrRomResrvtnVo updateRomResrvtn(RoomSearchVo search, String updateType) {
		ZehrRomResrvtnVo oldRomResrvtn = this.selectRomResrvView(search);
		if (oldRomResrvtn != null) {
			UserDetails userDetail = SessionUtil.getUserDetails();
			if (userDetail != null) {
				String userId = userDetail.getEmpNo();
				search.setMdftPr(userId);
			} else {
				throw new BusinessException("직원만 예약이 가능합니다.");
			}
			switch (updateType) {
			case "APPROVAL":
				this.synkRomResrvtn2Search(search, oldRomResrvtn, "APPROVAL");
				if (!"20".equals(oldRomResrvtn.getStatus())) {
					throw new BusinessException("승인요청건만 승인 할 수 있습니다.");
				} else {
					search.setStatus("30");
				}
				break;
			case "REJECT":
				this.synkRomResrvtn2Search(search, oldRomResrvtn, "REJECT");
				if (!"20".equals(oldRomResrvtn.getStatus())) {
					throw new BusinessException("승인요청건만 반려 할 수 있습니다.");
				} else {
					search.setStatus("40");
				}
				break;
			case "CANCEL":
				this.synkRomResrvtn2Search(search, oldRomResrvtn, "CANCEL");
				if (!"Y".equals(oldRomResrvtn.getCancelYn())) {
					throw new BusinessException(oldRomResrvtn.getCancelCn());
				} else {
					search.setStatus("60");
				}
				break;
			case "CLOSE":
				this.synkRomResrvtn2Search(search, oldRomResrvtn, "CLOSE");
				if (!"Y".equals(oldRomResrvtn.getCloseYn())) {
					throw new BusinessException(oldRomResrvtn.getCloseCn());
				} else {
					search.setStatus("50");
				}
				break;
			default:
				search.setStatus(oldRomResrvtn.getStatus());
				break;
			}
			RoomSearchVo oldSearch = new RoomSearchVo();
			this.synkRomResrvtn2Search(oldSearch, oldRomResrvtn, "ALL");
			ZehrRomDisplVo oldUpdateRomDispl = this.getUpdateZehrRomDisplVo(oldSearch,
					oldRomResrvtn.getReservationId());
			if (!oldUpdateRomDispl.getReYyyymmddList().isEmpty()) {
				oldUpdateRomDispl.setReservationDisName("N");
				mapper.updateRomDispl(oldUpdateRomDispl);
			}
			ZehrRomDisplVo updateRomDispl = this.getUpdateZehrRomDisplVo(search, oldRomResrvtn.getReservationId());
			if (!updateRomDispl.getReYyyymmddList().isEmpty()) {
				mapper.updateRomResrvtn(search);
				mapper.insertRomHistr(search);
				switch (search.getStatus()) {
				case "10":
				case "20":
				case "30":
				case "50":
					String reservationDisName = mapper.getReservationDisName(search);
					updateRomDispl.setReservationDisName(reservationDisName);
					mapper.updateRomDispl(updateRomDispl);
					break;
				}
			} else {
				throw new BusinessException("해당 일자에 해당하는 예약 사항이 없습니다. 관리자에게 문의하세요.");
			}
			ZehrRomResrvtnVo result = this.selectRomResrvView(search);
			if ("30".equals(result.getStatus())) {
				List<CodeVo> mailList = mapper.selectRequestEmailList(search);
				if (!mailList.isEmpty()) {
					StringBuffer sContent = new StringBuffer();
					String cmpnCd = userDetail.getCmpnCd();
					String srecvAddress = "";
					String sSender = userDetail.getEmpNo();
					String sSubject = "회의실 예약이 승인되었습니다.";
					String ssubSubject = "예약 승인";
					sContent.append("회의실 예약이 승인되었습니다.<br>");
					sContent.append("회   의    명  : " + result.getMeetingCon() + "<br>");
					sContent.append("예   약    자  : " + result.getSubscName() + "<br>");
					sContent.append("부        서  : " + result.getDeptName() + "<br>");
					sContent.append(
							"기        간  : " + result.getStartYyyymmdd() + " ~ " + result.getEndYyyymmdd() + "<br>");
					sContent.append("열쇠사용 여부  : " + result.getKeyYn() + "<br>");
					for (CodeVo item : mailList) {
						srecvAddress = (String) item.getValue();
						mailService.mailSend(cmpnCd, sSubject, ssubSubject, sContent, sSender, srecvAddress);
					}
				}
			} else if ("40".equals(result.getStatus())) {
				List<CodeVo> mailList = mapper.selectRequestEmailList(search);
				if (!mailList.isEmpty()) {
					StringBuffer sContent = new StringBuffer();
					String cmpnCd = userDetail.getCmpnCd();
					String srecvAddress = "";
					String sSender = userDetail.getEmpNo();
					String sSubject = "회의실 예약이 반려되었습니다.";
					String ssubSubject = "예약 반려";
					sContent.append("회의실 예약이 반려되었습니다.<br>");
					sContent.append("회   의    명  : " + result.getMeetingCon() + "<br>");
					sContent.append("예   약    자  : " + result.getSubscName() + "<br>");
					sContent.append("부        서  : " + result.getDeptName() + "<br>");
					sContent.append(
							"기        간  : " + result.getStartYyyymmdd() + " ~ " + result.getEndYyyymmdd() + "<br>");
					sContent.append("열쇠사용 여부  : " + result.getKeyYn() + "<br>");
					for (CodeVo item : mailList) {
						srecvAddress = (String) item.getValue();
						mailService.mailSend(cmpnCd, sSubject, ssubSubject, sContent, sSender, srecvAddress);
					}
				}
			}
			return result;
		} else {
			throw new BusinessException("해당 일자에 해당하는 예약 사항이 없습니다. 관리자에게 문의하세요.");
		}
	}

}