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

import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.madeu.dao.web.webhospital.WebHospitalSqlMapDAO;
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.webattendance.WebAttendanceSqlMapDAO;
import com.madeu.dao.web.webauthmenurelation.WebAuthMenuRelationSqlMapDAO;
import com.madeu.dao.web.webmember.WebMemberSqlMapDAO;
import com.madeu.dao.web.webvacation.WebVacationSqlMapDAO;
import com.madeu.dao.web.webvacationmanagement.WebVacationManagementSqlMapDAO;
import com.madeu.service.web.webattendance.WebAttendanceService;
import com.madeu.util.ValidationCheckUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("WebAttendanceService")
public class WebAttendanceServiceImpl implements WebAttendanceService {
	
	@Autowired
	private WebAttendanceSqlMapDAO webAttendanceSqlMapDAO;
	
	@Autowired
	private WebMemberSqlMapDAO webMemberSqlMapDAO;
	
	@Autowired
	private WebAuthMenuRelationSqlMapDAO webAuthMenuRelationSqlMapDAO;
	
	@Autowired
	private WebVacationManagementSqlMapDAO webVacationManagementSqlMapDAO;
	
	@Autowired
	private WebVacationSqlMapDAO webVacationSqlMapDAO;

	@Autowired
	private WebHospitalSqlMapDAO webHospitalSqlMapDAO;
	
	/**
	 * 근태관리 리스트 화면으로 이동.
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListAttendanceIntro(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebAttendanceServiceImpl selectListAttendanceIntro 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("WebAttendanceServiceImpl selectListAttendanceIntro END");
		return map;
	}
	
	/**
	 * 근태관리 리스트 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListAttendance(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebAttendanceServiceImpl selectListAttendance START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("attendanceSearchKeywordParam  :"+paramMap.get("attendanceSearchKeywordParam"));
		log.debug("attendanceSort                :"+paramMap.get("attendanceSort"));
		log.debug("attendanceDir                 :"+paramMap.get("attendanceDir"));
		log.debug("attendanceStart               :"+paramMap.get("attendanceStart"));
		log.debug("attendanceLimit               :"+paramMap.get("attendanceLimit"));
		
		log.debug("selectListAttendance          :"+paramMap.get("selectListAttendance"));
		log.debug("attendanceSearchGroupId       :"+paramMap.get("attendanceSearchGroupId"));

		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>> listMap = new ArrayList<Map<String, Object>>();
				
				// 직원 조회
				List<Map<String, Object>> memberListMap = webAttendanceSqlMapDAO.selectListAttendanceMember(paramMap);
				
				// 날짜 조회
				List<Map<String, Object>> dateListMap = webAttendanceSqlMapDAO.selectListAttendanceDate(paramMap);
				
				for (int j = 0; j < memberListMap.size(); j++) {
					String muMemberId = String.valueOf(memberListMap.get(j).get("muMemberId"));
					String memberName = String.valueOf(memberListMap.get(j).get("memberName"));
					String muGroupId  = String.valueOf(memberListMap.get(j).get("muGroupId"));
					String muDutyId   = String.valueOf(memberListMap.get(j).get("muDutyId"));
					paramMap.put("muMemberId", muMemberId);
					paramMap.put("muGroupId", muGroupId);
					paramMap.put("muDutyId", muDutyId);
					
					for (int i = 0; i < dateListMap.size(); i++) {
						Map<String, Object> addResultMap = new HashMap<String, Object>();
						
						String searchDate = String.valueOf(dateListMap.get(i).get("resultDate"));
						paramMap.put("searchDate", searchDate);
						
						// 근태 내역 조회
						List<Map<String, Object>> attendanceListMap = webAttendanceSqlMapDAO.selectListAttendance(paramMap);
						
						if(attendanceListMap.size()>0) {
							addResultMap.put("attendanceListMap", attendanceListMap);
						}
						else {
							addResultMap.put("attendanceListMap", null);
						}
						addResultMap.put("muGroupId", muGroupId);
						addResultMap.put("muDutyId", muDutyId);
						addResultMap.put("muMemberId", muMemberId);
						addResultMap.put("memberName", memberName);
						addResultMap.put("searchDate", searchDate);
						
						listMap.add(addResultMap);
					}
					
				}
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("dateRows",dateListMap);
				map.put("memberRows",memberListMap);
				map.put("rows",listMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}

		log.debug("WebAttendanceServiceImpl selectListAttendance END");
		return map;
	}
	
	/**
	 * 근태관리 리스트 조회 (Excel)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListAttendanceExcel(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebAttendanceServiceImpl selectListAttendanceExcel START");

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

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("attendanceSearchKeywordParam  :"+paramMap.get("attendanceSearchKeywordParam"));
		log.debug("attendanceSort                :"+paramMap.get("attendanceSort"));
		log.debug("attendanceDir                 :"+paramMap.get("attendanceDir"));
		log.debug("attendanceStart               :"+paramMap.get("attendanceStart"));
		log.debug("attendanceLimit               :"+paramMap.get("attendanceLimit"));
		
		log.debug("attendanceSearchStartDate     :"+paramMap.get("attendanceSearchStartDate"));
		log.debug("attendanceSearchEndDate       :"+paramMap.get("attendanceSearchEndDate"));
		log.debug("attendanceSearchDateType      :"+paramMap.get("attendanceSearchDateType"));
		log.debug("attendanceSearchGroupId       :"+paramMap.get("attendanceSearchGroupId"));

		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("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){
				List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
				
				// 직원 조회
				List<Map<String, Object>> memberListMap = webAttendanceSqlMapDAO.selectListAttendanceMember(paramMap);
				
				// 날짜 조회
				List<Map<String, Object>> dateListMap = webAttendanceSqlMapDAO.selectListAttendanceDate(paramMap);
				
				for (int j = 0; j < memberListMap.size(); j++) {
					String muMemberId = String.valueOf(memberListMap.get(j).get("muMemberId"));
					String memberName = String.valueOf(memberListMap.get(j).get("memberName"));
					String muGroupId  = String.valueOf(memberListMap.get(j).get("muGroupId"));
					String muDutyId   = String.valueOf(memberListMap.get(j).get("muDutyId"));
					paramMap.put("muMemberId", muMemberId);
					paramMap.put("muGroupId", muGroupId);
					paramMap.put("muDutyId", muDutyId);
					
					for (int i = 0; i < dateListMap.size(); i++) {
						Map<String, Object> addResultMap = new HashMap<String, Object>();
						
						String searchDate = String.valueOf(dateListMap.get(i).get("resultDate"));
						paramMap.put("searchDate", searchDate);
						
						// 근태 내역 조회
						List<Map<String, Object>> attendanceListMap = webAttendanceSqlMapDAO.selectListAttendance(paramMap);
						
						if(attendanceListMap.size()>0) {
							addResultMap.put("attendanceListMap", attendanceListMap);
						}
						else {
							addResultMap.put("attendanceListMap", null);
						}
						addResultMap.put("muGroupId", muGroupId);
						addResultMap.put("muDutyId", muDutyId);
						addResultMap.put("muMemberId", muMemberId);
						addResultMap.put("memberName", memberName);
						addResultMap.put("searchDate", searchDate);
						
						listMap.add(addResultMap);
					}
					
				}
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("dateRows",dateListMap);
				map.put("memberRows",memberListMap);
				map.put("rows",listMap);
			}

		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}

		log.debug("WebAttendanceServiceImpl selectListAttendanceExcel END");
		return map;
	}
	
	/**
	 * 금일 근무현황 리스트 조회
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectListTodayAttendance(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebAttendanceServiceImpl selectListTodayAttendance 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>> listMap = webAttendanceSqlMapDAO.selectListTodayAttendance(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
			}
		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}

		log.debug("WebAttendanceServiceImpl selectListTodayAttendance END");
		return map;
	}
	
	/**
	 * 근태관리 정보 등록 (출퇴근/휴무)
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> insertAttendance(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebAttendanceServiceImpl insertAttendance START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("muMemberId          :"+paramMap.get("muMemberId"));
		log.debug("attendanceType      :"+paramMap.get("attendanceType"));
		log.debug("startDate           :"+paramMap.get("startDate"));
		log.debug("endDate             :"+paramMap.get("endDate"));
		log.debug("attendanceTime      :"+paramMap.get("attendanceTime"));
		log.debug("etc                 :"+paramMap.get("etc"));

		try{
			boolean check  = true;
			String tId = String.valueOf(System.currentTimeMillis());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c1 = Calendar.getInstance();
			String tDate = sdf.format(c1.getTime());

			String muMemberId        = String.valueOf(paramMap.get("muMemberId"));
			String attendanceType    = String.valueOf(paramMap.get("attendanceType"));
			String startDate         = String.valueOf(paramMap.get("startDate"));
			String endDate           = String.valueOf(paramMap.get("endDate"));
			String attendanceTime    = String.valueOf(paramMap.get("attendanceTime"));
			String etc               = String.valueOf(paramMap.get("etc"));
			
			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직원 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(attendanceType)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","근태유형 정보가 없습니다.");
			}
			else {
				if(("C").equals(attendanceType)) {
					// 휴무일경우
					attendanceTime = null;
					paramMap.put("attendanceTime", null);
				}
				else {
					if(true != ValidationCheckUtil.emptyCheck(attendanceTime)){
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc","시간 정보가 없습니다.");
					}
				}
			}
			
			if(true != ValidationCheckUtil.emptyCheck(startDate)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시작일자 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(endDate)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","종료일자 정보가 없습니다.");
			}
			
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
				int authMenuRelationlistMapSize = authMenuRelationlistMap.size();
				
				if(1==authMenuRelationlistMapSize){
					
					if(("Y").equals(authMenuRelationlistMap.get(0).get("insertUseYn"))) {
						
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "등록 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}
			
			if(true == check){
				// 직원 조회
				List<Map<String, Object>> memberListMap = webMemberSqlMapDAO.selectMember(paramMap);
				int memberListMapSize = memberListMap.size();
				
				if(1 == memberListMapSize){
					paramMap.put("muGroupId", memberListMap.get(0).get("muGroupId"));
					paramMap.put("muDutyId", memberListMap.get(0).get("muDutyId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "직원 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 겹치는 일자 안 들어가도록 조회
				List<Map<String, Object>> attendanceListMap = webAttendanceSqlMapDAO.selectAttendanceDate(paramMap);
				int attendanceListMapSize = Integer.parseInt(String.valueOf(attendanceListMap.get(0).get("totalCount")));
				
				if(0 == attendanceListMapSize){
					
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "이미 등록된 근태정보가 있습니다.");
				}
			}

			if(true == check){
				// 휴일 확인
				List<Map<String, Object>> hospitalListMap = webHospitalSqlMapDAO.selectHospitalWeek2(paramMap);
				int hospitalListMapSize = hospitalListMap.size();

				if(0 < hospitalListMapSize) {
					for(int i=0; i<hospitalListMapSize; i++){
						String openYn = String.valueOf(hospitalListMap.get(i).get("openYn"));
						String holidayYn = String.valueOf(hospitalListMap.get(i).get("holidayYn"));

						if(("N").equals(openYn)||("Y").equals(holidayYn)){
							check = false;
							map.put("msgCode", Constants.FAIL);
							map.put("msgDesc", "운영시간이 아닌 일자를 포함하고 있어 등록할 수 없습니다.");

							break;
						}
					}
				}
			}
			
			if(true == check){
				paramMap.put("tDate", tDate);
				paramMap.put("tId", tId);
				
				String muAttendanceId = ("A").concat(String.valueOf(System.currentTimeMillis()));
				paramMap.put("muAttendanceId",muAttendanceId);
				webAttendanceSqlMapDAO.insertAttendance(paramMap);
				log.debug("muAttendanceId :"+paramMap.get("id"));
				paramMap.put("muAttendanceId", paramMap.get("id"));
				map.put("muAttendanceId", paramMap.get("muAttendanceId"));
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "등록되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebAttendanceServiceImpl insertAttendance END");
		return map;
	}
	
	/**
	 * 근태관리 상세 조회 (출/퇴근 조회)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectAttendanceCommute(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebAttendanceServiceImpl selectAttendanceCommute START");

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

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

		try{
			boolean check  = true;
			
			String muAttendanceId  = String.valueOf(paramMap.get("muAttendanceId"));
			String muAttendanceId2 = String.valueOf(paramMap.get("muAttendanceId2"));
			
			if(true != ValidationCheckUtil.emptyCheck(muAttendanceId) && true != ValidationCheckUtil.emptyCheck(muAttendanceId2)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","근태 정보가 없습니다.");
			}
			
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}

			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);

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

					if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "조회 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}
			
			if(true == check){
				List<Map<String, Object>> listMap = webAttendanceSqlMapDAO.selectAttendanceCommute(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
			}

		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}

		log.debug("WebAttendanceServiceImpl selectAttendanceCommute END");
		return map;
	}

	/**
	 * 근태관리 수정 (출/퇴근)
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateAttendanceCommute(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebAttendanceServiceImpl updateAttendanceCommute START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("muAttendanceId      :"+paramMap.get("muAttendanceId"));
		log.debug("muAttendanceId2     :"+paramMap.get("muAttendanceId2"));
		log.debug("muMemberId          :"+paramMap.get("muMemberId"));
		log.debug("attendanceDate      :"+paramMap.get("attendanceDate"));
		log.debug("startTime           :"+paramMap.get("startTime"));
		log.debug("endTime             :"+paramMap.get("endTime"));

		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 muAttendanceId   = String.valueOf(paramMap.get("muAttendanceId"));
			String muAttendanceId2  = String.valueOf(paramMap.get("muAttendanceId2"));
			String muMemberId       = String.valueOf(paramMap.get("muMemberId"));
			String attendanceDate   = String.valueOf(paramMap.get("attendanceDate"));
			String startTime        = String.valueOf(paramMap.get("startTime"));
			String endTime          = String.valueOf(paramMap.get("endTime"));
			DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
			LocalTime fommat_startTime = LocalTime.parse(startTime, formatter);
			LocalTime fommat_endTime = LocalTime.parse(endTime, formatter);

			if(true != ValidationCheckUtil.emptyCheck(muAttendanceId) && true != ValidationCheckUtil.emptyCheck(muAttendanceId2)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","근태 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직원 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(attendanceDate)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","날짜 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(startTime)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","출근시간 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(endTime)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","퇴근시간 정보가 없습니다.");
			}
			if(fommat_startTime.isAfter(fommat_endTime)||fommat_startTime.equals(fommat_endTime)){
				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){
				// 직원 조회
				List<Map<String, Object>> memberListMap = webMemberSqlMapDAO.selectMember(paramMap);
				int memberListMapSize = memberListMap.size();
				
				if(1 == memberListMapSize){
					paramMap.put("muGroupId", memberListMap.get(0).get("muGroupId"));
					paramMap.put("muDutyId", memberListMap.get(0).get("muDutyId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "직원 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				paramMap.put("tDate", tDate);
				paramMap.put("tId", tId);
				
				// 출근시간 처리
				if(true != ValidationCheckUtil.emptyCheck(muAttendanceId)) {
					String attendanceId = ("A").concat(String.valueOf(System.currentTimeMillis()));
					paramMap.put("muAttendanceId",attendanceId);
					paramMap.put("attendanceType", "A");
					paramMap.put("startDate", attendanceDate);
					paramMap.put("endDate", attendanceDate);
					paramMap.put("attendanceTime", startTime);
					webAttendanceSqlMapDAO.insertAttendance(paramMap);
				}
				else {
					paramMap.put("muAttendanceId", muAttendanceId);
					paramMap.put("attendanceTime", startTime);
					webAttendanceSqlMapDAO.updateAttendanceCommute(paramMap);
				}
				
				// 퇴근시간 처리
				if(true != ValidationCheckUtil.emptyCheck(muAttendanceId2)) {
					String attendanceId = ("A").concat(String.valueOf(System.currentTimeMillis()));
					paramMap.put("muAttendanceId",attendanceId);
					paramMap.put("attendanceType", "B");
					paramMap.put("startDate", attendanceDate);
					paramMap.put("endDate", attendanceDate);
					paramMap.put("attendanceTime", endTime);
					webAttendanceSqlMapDAO.insertAttendance(paramMap);
				}
				else {
					paramMap.put("muAttendanceId", muAttendanceId2);
					paramMap.put("attendanceTime", endTime);
					webAttendanceSqlMapDAO.updateAttendanceCommute(paramMap);
				}

				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "수정되었습니다.");
			}
			
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebAttendanceServiceImpl updateAttendanceCommute END");
		return map;
	}
	
	/**
	 * 근태관리 상세 조회 (연차 조회)
	 *
	 *
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	@Override
	public HashMap<String, Object> selectAttendanceVacation(
			HashMap<String, Object> paramMap) throws Exception {
		log.debug("WebAttendanceServiceImpl selectAttendanceVacation START");

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

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

		try{
			boolean check  = true;
			
			String muAttendanceId  = String.valueOf(paramMap.get("muAttendanceId"));
			String muMemberId      = String.valueOf(paramMap.get("muMemberId"));
			
			if(true != ValidationCheckUtil.emptyCheck(muAttendanceId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","근태 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직원 정보가 없습니다.");
			}
			
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);

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

					if(("Y").equals(authMenuRelationlistMap.get(0).get("selectUseYn"))) {

					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "조회 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}
			if(true == check){
				List<Map<String, Object>> listMap = webAttendanceSqlMapDAO.selectAttendanceVacation(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("success","true");
				map.put("rows",listMap);
			}

		}
		catch(Exception e){
			e.printStackTrace();
			throw e;
		}

		log.debug("WebAttendanceServiceImpl selectAttendanceVacation END");
		return map;
	}
	
	/**
	 * 근태관리 정보 등록 (연차)
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> insertAttendanceVacation(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebAttendanceServiceImpl insertAttendanceVacation START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();

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

		log.debug("muMemberId          :"+paramMap.get("muMemberId"));
		log.debug("muVacationId        :"+paramMap.get("muVacationId"));
		log.debug("startDate           :"+paramMap.get("startDate"));
		log.debug("endDate             :"+paramMap.get("endDate"));
		log.debug("startTime           :"+paramMap.get("startTime"));
		log.debug("endTime             :"+paramMap.get("endTime"));
		log.debug("etc                 :"+paramMap.get("etc"));

		try{
			boolean check  = true;
			String tId = String.valueOf(System.currentTimeMillis());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c1 = Calendar.getInstance();
			String tDate = sdf.format(c1.getTime());

			String muMemberId       = String.valueOf(paramMap.get("muMemberId"));
			String muVacationId     = String.valueOf(paramMap.get("muVacationId"));
			String startDate        = String.valueOf(paramMap.get("startDate"));
			String endDate          = String.valueOf(paramMap.get("endDate"));
			String startTime        = String.valueOf(paramMap.get("startTime"));
			String endTime          = String.valueOf(paramMap.get("endTime"));
			
			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직원 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muVacationId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","연차사용단위 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(startDate)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시작일자 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(endDate)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","종료일자 정보가 없습니다.");
			}
			
			if(true == check){
				// 사용자 확인
				List<Map<String, Object>> userListMap = webMemberSqlMapDAO.checkMember(paramMap);
				int userListMapSize = userListMap.size();
				
				if(1==userListMapSize){
					paramMap.put("menuClassAuthId", userListMap.get(0).get("muAuthId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "사용자 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 권한 조회
				HashMap<String, Object> authCheckParamMap = new HashMap<String, Object>();
				authCheckParamMap.put("menuClass",paramMap.get("menuClass"));
				authCheckParamMap.put("muAuthId",paramMap.get("menuClassAuthId"));
				List<Map<String, Object>> authMenuRelationlistMap = webAuthMenuRelationSqlMapDAO.selectAuthMenuRelation(authCheckParamMap);
				int authMenuRelationlistMapSize = authMenuRelationlistMap.size();
				
				if(1==authMenuRelationlistMapSize){
					
					if(("Y").equals(authMenuRelationlistMap.get(0).get("insertUseYn"))) {
						
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "등록 권한 정보가 없습니다.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "권한 정보가 없습니다.");
				}
			}
			
			if(true == check){
				// 직원 조회
				List<Map<String, Object>> memberListMap = webMemberSqlMapDAO.selectMember(paramMap);
				int memberListMapSize = memberListMap.size();
				
				if(1 == memberListMapSize){
					paramMap.put("muGroupId", memberListMap.get(0).get("muGroupId"));
					paramMap.put("muDutyId", memberListMap.get(0).get("muDutyId"));
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "직원 정보가 올바르지 않습니다.");
				}
			}
			
			if(true == check){
				// 연차사용단위 정보 조회
				List<Map<String, Object>> vacationListMap = webVacationSqlMapDAO.selectVacation(paramMap);
				int vacationListMapSize = vacationListMap.size();
				
				if(1 == vacationListMapSize) {
					String hourType = String.valueOf(vacationListMap.get(0).get("hourType"));
					
					if(("A").equals(hourType)) {
						paramMap.put("attendanceType", "D");
					}
					else {
						// 반차
						paramMap.put("attendanceType", "E");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "연차사용단위 정보가 없습니다.");
				}
			}
			
			if(true == check){
				// 겹치는 일자 안 들어가도록 조회
				List<Map<String, Object>> attendanceListMap = webAttendanceSqlMapDAO.selectAttendanceDate(paramMap);
				int attendanceListMapSize = Integer.parseInt(String.valueOf(attendanceListMap.get(0).get("totalCount")));
				
				if(0 == attendanceListMapSize){
					
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "이미 등록된 근태정보가 있습니다.");
				}
			}

			if(true == check){
				// 휴일 확인
				List<Map<String, Object>> hospitalListMap = webHospitalSqlMapDAO.selectHospitalWeek2(paramMap);
				int hospitalListMapSize = hospitalListMap.size();

				if(0 < hospitalListMapSize) {
					for(int i=0; i<hospitalListMapSize; i++){
						String openYn = String.valueOf(hospitalListMap.get(i).get("openYn"));
						String holidayYn = String.valueOf(hospitalListMap.get(i).get("holidayYn"));

						if(("N").equals(openYn)||("Y").equals(holidayYn)){
							check = false;
							map.put("msgCode", Constants.FAIL);
							map.put("msgDesc", "운영시간이 아닌 일자를 포함하고 있어 등록할 수 없습니다.");

							break;
						}
					}
				}
			}

			if(true == check){
				// 잔여 연차 확인
				List<Map<String, Object>> vacationManagementListMap = webVacationManagementSqlMapDAO.selectVacationManagementLeftDays(paramMap);
				int vacationManagementListMapListMapSize = vacationManagementListMap.size();
				
				if(vacationManagementListMapListMapSize==1){
					double leftDays = Double.parseDouble(String.valueOf(vacationManagementListMap.get(0).get("leftDays")));
					double useDays = 0.5;
					if("D".equals(paramMap.get("attendanceType"))){
						useDays  = getDateDays(startDate, endDate);
					}

					if(leftDays>=useDays) {
						paramMap.put("muVacationManagementId", vacationManagementListMap.get(0).get("muVacationManagementId"));
						paramMap.put("days", useDays);
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "잔여연차는 "+leftDays+"일 입니다. 연차기간을 확인해주세요.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "발행된 연차 정보가 없습니다. 관리자에게 문의하십시오.");
				}
			}
			
			if(true == check){
				paramMap.put("tDate", tDate);
				paramMap.put("tId", tId);
				
				String muAttendanceId = ("A").concat(String.valueOf(System.currentTimeMillis()));
				paramMap.put("muAttendanceId",muAttendanceId);
				webAttendanceSqlMapDAO.insertAttendance(paramMap);
				log.debug("muAttendanceId :"+paramMap.get("id"));
				paramMap.put("muAttendanceId", paramMap.get("id"));
				map.put("muAttendanceId", paramMap.get("muAttendanceId"));
				
				// 잔여연차 업데이트
				webVacationManagementSqlMapDAO.updateVacationManagementLeftDays(paramMap);
				
				map.put("msgCode", Constants.OK);
				map.put("msgDesc", "등록되었습니다.");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebAttendanceServiceImpl insertAttendanceVacation END");
		return map;
	}

	/**
	 * 근태관리 수정 (연차)
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateAttendanceVacation(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebAttendanceServiceImpl updateAttendanceVacation START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		log.debug("loginMemberId       :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass           :"+paramMap.get("menuClass"));
		
		log.debug("muAttendanceId      :"+paramMap.get("muAttendanceId"));
		log.debug("muMemberId          :"+paramMap.get("muMemberId"));
		log.debug("muVacationId        :"+paramMap.get("muVacationId"));
		log.debug("startDate           :"+paramMap.get("startDate"));
		log.debug("endDate             :"+paramMap.get("endDate"));
		log.debug("startTime           :"+paramMap.get("startTime"));
		log.debug("endTime             :"+paramMap.get("endTime"));
		log.debug("etc                 :"+paramMap.get("etc"));

		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 muAttendanceId   = String.valueOf(paramMap.get("muAttendanceId"));
			String muMemberId       = String.valueOf(paramMap.get("muMemberId"));
			String muVacationId     = String.valueOf(paramMap.get("muVacationId"));
			String startDate        = String.valueOf(paramMap.get("startDate"));
			String endDate          = String.valueOf(paramMap.get("endDate"));
			String startTime        = String.valueOf(paramMap.get("startTime"));
			String endTime          = String.valueOf(paramMap.get("endTime"));

			if(true != ValidationCheckUtil.emptyCheck(muAttendanceId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","근태 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muMemberId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","직원 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(muVacationId)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","연차사용단위 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(startDate)){
				check = false;
				map.put("msgCode", Constants.FAIL);
				map.put("msgDesc","시작일자 정보가 없습니다.");
			}
			
			if(true != ValidationCheckUtil.emptyCheck(endDate)){
				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){
				// 연차사용단위 정보 조회
				List<Map<String, Object>> vacationListMap = webVacationSqlMapDAO.selectVacation(paramMap);
				int vacationListMapSize = vacationListMap.size();
				
				if(1 == vacationListMapSize) {
					String hourType = String.valueOf(vacationListMap.get(0).get("hourType"));
					
					if(("A").equals(hourType)) {
						paramMap.put("attendanceType", "D");
					}
					else {
						// 반차
						paramMap.put("attendanceType", "E");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "연차사용단위 정보가 없습니다.");
				}
			}
			
			if(true == check){
				// 겹치는 일자 안 들어가도록 조회
				List<Map<String, Object>> attendanceListMap = webAttendanceSqlMapDAO.selectAttendanceDate(paramMap);
				int attendanceListMapSize = Integer.parseInt(String.valueOf(attendanceListMap.get(0).get("totalCount")));
				
				if(0 == attendanceListMapSize){
					
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "이미 등록된 근태정보가 있습니다.");
				}
			}
			
			if(true == check){
				// 연차정보 조회
				List<Map<String, Object>> attendanceListMap = webAttendanceSqlMapDAO.selectAttendanceVacation(paramMap);
				int attendanceListMapSize = attendanceListMap.size();
				
				if(1 == attendanceListMapSize) {
					// 수정 전 데이터
					String oldMuVacationManagementId = String.valueOf(attendanceListMap.get(0).get("muVacationManagementId"));
					Double oldDays                     = Double.parseDouble(String.valueOf(attendanceListMap.get(0).get("days")));
					// 발행된 연차 및 잔여 연차 확인
					// 수정 시 기존연차와 남은 연차 합해서 확인 
					List<Map<String, Object>> vacationManagementListMap = webVacationManagementSqlMapDAO.selectVacationManagementLeftDays(paramMap);
					int vacationManagementListMapListMapSize = vacationManagementListMap.size();
					
					if(vacationManagementListMapListMapSize==1){
						String muVacationManagementId = String.valueOf(vacationManagementListMap.get(0).get("muVacationManagementId"));
						double leftDays = Double.parseDouble(String.valueOf(vacationManagementListMap.get(0).get("leftDays")));
						double useDays = 0.5;
						if("D".equals(paramMap.get("attendanceType"))){
							useDays  = getDateDays(startDate, endDate);
						}

						if((leftDays+oldDays)>=useDays) {
							
							paramMap.put("muVacationManagementId", vacationManagementListMap.get(0).get("muVacationManagementId"));
							paramMap.put("days", useDays);
							
							webAttendanceSqlMapDAO.updateAttendanceVacation(paramMap);
							map.put("msgCode", Constants.OK);
							map.put("msgDesc", "수정되었습니다.");
							
							// 잔여연차 업데이트
							if(oldMuVacationManagementId == muVacationManagementId) {
								// 연차사용단위가 변경되지 않았을 경우
								paramMap.put("days", useDays-oldDays);
								paramMap.put("muVacationManagementId", muVacationManagementId);
								webVacationManagementSqlMapDAO.updateVacationManagementLeftDays(paramMap);
							}
							else {
								// 연차사용단위가 변경되었을 경우
								// 1. 이전 남은연차 갯수 수정
								paramMap.put("days", -oldDays);
								paramMap.put("muVacationManagementId", oldMuVacationManagementId);
								webVacationManagementSqlMapDAO.updateVacationManagementLeftDays(paramMap);
								
								// 2. 수정 남은연차 갯수 수정
								paramMap.put("days", useDays);
								paramMap.put("muVacationManagementId", muVacationManagementId);
								webVacationManagementSqlMapDAO.updateVacationManagementLeftDays(paramMap);
							}
						}
						else {
							check = false;
							map.put("msgCode", Constants.FAIL);
							map.put("msgDesc", "잔여연차가 없거나 부족합니다. 연차기간을 확인해주세요.");
						}
					}
					else {
						check = false;
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "발행된 연차 정보가 없습니다. 관리자에게 문의하십시오.");
					}
				}
				else {
					check = false;
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "연차 정보가 없습니다.");
				}
			}
			
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebAttendanceServiceImpl updateAttendanceVacation END");
		return map;
	}

	/**
	 * 근태관리 정보 취소 (연차)
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception 
	 */
	@Override
	@Transactional(rollbackFor={Exception.class}, propagation = Propagation.REQUIRES_NEW)
	public HashMap<String, Object> updateAttendanceVacationCancel(
			HashMap<String, Object> paramMap) throws Exception{
		log.debug("WebAttendanceServiceImpl updateAttendanceVacationCancel START");
		
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		log.debug("loginMemberId         :"+paramMap.get("loginMemberId"));
		
		log.debug("menuClass             :"+paramMap.get("menuClass"));
		
		log.debug("muAttendanceId        :"+paramMap.get("muAttendanceId"));
		log.debug("cancelEtc             :"+paramMap.get("cancelEtc"));

		try{
			boolean check  = true;

			String muAttendanceId        = String.valueOf(paramMap.get("muAttendanceId"));
			String cancelEtc             = String.valueOf(paramMap.get("cancelEtc"));

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

			if(true != ValidationCheckUtil.emptyCheck(cancelEtc)){
				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){
				// 휴무 정보 확인
				List<Map<String, Object>> attendanceListMap = webAttendanceSqlMapDAO.selectAttendanceVacation(paramMap);
				
				if(attendanceListMap.size()==1) {
					Double days                   = Double.parseDouble(String.valueOf(attendanceListMap.get(0).get("days")));
					String muVacationManagementId = String.valueOf(attendanceListMap.get(0).get("muVacationManagementId"));
					String muMemberId             = String.valueOf(attendanceListMap.get(0).get("muMemberId"));
					String status                 = String.valueOf(attendanceListMap.get(0).get("status"));


					if(("D").equals(status)){
						map.put("msgCode", Constants.FAIL);
						map.put("msgDesc", "이미 취소된 연차입니다.");
					}else{
						// 취소가 아닐 경우만 업데이트
						// 취소처리
						webAttendanceSqlMapDAO.updateAttendanceCancel(paramMap);

						// 남은 연차 되돌리기
						paramMap.put("days", -days);
						paramMap.put("muVacationManagementId", muVacationManagementId);
						paramMap.put("muMemberId", muMemberId);
						webVacationManagementSqlMapDAO.updateVacationManagementLeftDays(paramMap);

						map.put("msgCode", Constants.OK);
						map.put("msgDesc", "처리되었습니다.");
					}
				}else{
					map.put("msgCode", Constants.FAIL);
					map.put("msgDesc", "휴무관리 정보가 없습니다.");
				}
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
		log.debug("WebAttendanceServiceImpl updateAttendanceVacationCancel END");
		return map;
	}
	
	public long getDateDays(String startDate, String endDate) throws Exception {
		Date format1 = new SimpleDateFormat("yyyy-MM-dd").parse(endDate);
		Date format2 = new SimpleDateFormat("yyyy-MM-dd").parse(startDate);
		
		long diffSec = (format1.getTime() - format2.getTime()) / 1000; //초 차이
		long diffDays = diffSec / (24*60*60); //일자수 차이
		
		return diffDays+1; 
	}
}
