<?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="WebDuty">

	<select id="selectListDutyOption" parameterType="hashMap" resultType="hashMap">
		SELECT MD.MU_DUTY_ID            AS "muDutyId"
			  ,MD.DUTY_NAME             AS "dutyName"
		  FROM MU_DUTY AS MD
		 WHERE MD.USE_YN     = 'Y'
 	  ORDER BY MD.DUTY_NAME ASC
	</select>
	
	<select id="selectTotalDutyCount" parameterType="hashmap" resultType="hashmap">
		SELECT COUNT(*)  AS "totalCount"
		  FROM MU_DUTY AS MD
		 WHERE MD.USE_YN     = 'Y'
	</select>
	
	<select id="selectListDuty" parameterType="hashmap" resultType="hashmap">
		SELECT MD.MU_DUTY_ID                 AS "muDutyId"
			  ,MD.ORDER_NUMBER                  AS "orderNumber"
			  ,MD.DUTY_NAME                  AS "dutyName"
			  ,IFNULL(MD.ETC, '')            AS "etc"
		  FROM MU_DUTY AS MD
		 WHERE MD.USE_YN     = 'Y'
 	  ORDER BY MD.ORDER_NUMBER ASC
	</select>

	<select id="selectDuty" parameterType="hashmap" resultType="hashmap">
		SELECT MD.MU_DUTY_ID                          AS "muDutyId"
			  ,MD.ORDER_NUMBER                           AS "orderNumber"
			  ,MD.DUTY_NAME                           AS "dutyName"
			  ,IFNULL(MD.ETC,'')                      AS "etc"
			  ,DATE_FORMAT(MD.WRITE_DATE, '%Y-%m-%d') AS "writeDate"
		  FROM MU_DUTY AS MD
		 WHERE MD.USE_YN     = 'Y'
		   AND MD.MU_DUTY_ID = #{muDutyId}
		 LIMIT 0, 1
	</select>

	<insert id="insertDuty" parameterType="hashmap">
		<selectKey resultType="string" keyProperty="id" order="BEFORE">
			SELECT CONCAT(#{muDutyId},LPAD((SELECT NEXTVAL(MU_DUTY_SEQ)), 11, 0))
		</selectKey>
		INSERT INTO MU_DUTY(
					 MU_DUTY_ID
					,ORDER_NUMBER
					,DUTY_NAME
					,ETC
					,WRITE_DATE
					,WRITE_TIME
					,CUD_FLAG
					,USE_YN
					,REG_ID
					,REG_DATE
					,MOD_ID
					,MOD_DATE
					,T_ID
					,T_DATE
		)VALUES(
					 #{id}
					,#{orderNumber}
					,#{dutyName}
					,#{etc,jdbcType=VARCHAR}
					,CURDATE()
					,CURTIME()
					,'C'
					,'Y'
					,#{regId}
					,NOW()
					,#{modId}
					,NOW()
					,#{tId}
					,#{tDate}
		)
	</insert>
	
	<update id="updateDuty" parameterType="hashmap">
		UPDATE MU_DUTY
		   SET MOD_ID              = #{modId}
			  ,MOD_DATE            = NOW()
			  ,CUD_FLAG            = 'U'
			  ,ORDER_NUMBER           = #{orderNumber}
			  ,DUTY_NAME           = #{dutyName}
			  ,ETC                 = #{etc,jdbcType=VARCHAR}
		 WHERE USE_YN        = 'Y'
		   AND MU_DUTY_ID  = #{muDutyId}
	</update>
	
	<update id="deleteDuty" parameterType="hashmap">
		UPDATE MU_DUTY
		   SET MOD_ID            = #{modId}
			  ,MOD_DATE	         = NOW()
			  ,CUD_FLAG          = 'D'
			  ,USE_YN            = 'N'
		 WHERE USE_YN        = 'Y'
		   AND MU_DUTY_ID  = #{muDutyId}
	</update>
</mapper>