<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="WebHospitalHoliday">

	<select id="selectListHospitalHoliday" parameterType="hashmap" resultType="hashmap">
		SELECT MHH.MU_HOSPITAL_HOLIDAY_ID               AS "muHospitalHolidayId"
			  ,MHH.MU_HOSPITAL_ID                       AS "muHospitalId"
			  ,MHH.HOSPITAL_HOLIDAY_NAME                AS "hospitalHolidayName"
			  ,DATE_FORMAT(MHH.LOC_DATE, '%Y-%m-%d')    AS "locDate"
			  ,MHH.REPEAT_YN                            AS "repeatYn"
		  FROM MU_HOSPITAL_HOLIDAY AS MHH
		 WHERE MHH.USE_YN          = 'Y'
		   AND MHH.MU_HOSPITAL_ID  = #{muHospitalId}
	</select>
	
	<select id="selectHospitalHolidayDate" parameterType="hashmap" resultType="hashmap">
		SELECT COUNT(*)               AS "totalCount"
		  FROM MU_HOSPITAL_HOLIDAY AS MHH
		 WHERE MHH.USE_YN          = 'Y'
		   AND MHH.MU_HOSPITAL_ID  = #{muHospitalId}
		   AND MHH.LOC_DATE        = #{locDate}
	</select>

	<insert id="insertHospitalHoliday" parameterType="hashmap">
		<selectKey resultType="string" keyProperty="id" order="BEFORE">
			SELECT CONCAT(#{muHospitalHolidayId},LPAD((SELECT NEXTVAL(MU_HOSPITAL_HOLIDAY_SEQ)), 10, 0))
		</selectKey>
		INSERT INTO MU_HOSPITAL_HOLIDAY(
					 MU_HOSPITAL_HOLIDAY_ID
					,MU_HOSPITAL_ID
					,HOSPITAL_HOLIDAY_NAME
					,LOC_DATE
					,REPEAT_YN
					,WRITE_DATE
					,WRITE_TIME
					,CUD_FLAG
					,USE_YN
					,REG_ID
					,REG_DATE
					,MOD_ID
					,MOD_DATE
					,T_ID
					,T_DATE
		)VALUES(
					 #{id}
					,#{muHospitalId}
					,#{hospitalHolidayName}
					,#{locDate}
					,#{repeatYn}
					,CURDATE()
					,CURTIME()
					,'C'
					,'Y'
					,#{regId}
					,NOW()
					,#{modId}
					,NOW()
					,#{tId}
					,#{tDate}
		)
	</insert>
	
	<update id="updateHospitalHoliday" parameterType="hashmap">
		UPDATE MU_HOSPITAL_HOLIDAY
		   SET MOD_ID                    = #{modId}
			  ,MOD_DATE                  = NOW()
			  ,CUD_FLAG            = 'U'
			  ,HOSPITAL_HOLIDAY_NAME     = #{hospitalHolidayName}
			  ,LOC_DATE                  = #{locDate}
			  ,REPEAT_YN                 = #{repeatYn}
		 WHERE USE_YN                 = 'Y'
		   AND MU_HOSPITAL_ID         = #{muHospitalId}
		   AND MU_HOSPITAL_HOLIDAY_ID = #{muHospitalHolidayId}
	</update>
	
	<update id="deleteHospitalHoliday" parameterType="hashmap">
		UPDATE MU_HOSPITAL_HOLIDAY
		   SET MOD_ID                    = #{modId}
			  ,MOD_DATE                  = NOW()
			  ,CUD_FLAG                  = 'D'
			  ,USE_YN                    = 'N'
		 WHERE USE_YN                 = 'Y'
		   AND MU_HOSPITAL_ID         = #{muHospitalId}
		   AND MU_HOSPITAL_HOLIDAY_ID = #{muHospitalHolidayId}
	</update>
	
</mapper>