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

	<select id="selectListTreatmentProcedureArea" parameterType="hashmap" resultType="hashmap">
		SELECT MTPA.MU_TREATMENT_PROCEDURE_AREA_ID       AS "muTreatmentProcedureAreaId"
			  ,MTPA.MU_TREATMENT_PROCEDURE_ID            AS "muTreatmentProcedureId"
			  ,MTPA.ORDER_NUMBER                         AS "orderNumber"
			  ,MTPA.PROCEDURE_AREA_NAME                  AS "procedureAreaName"
		  FROM MU_TREATMENT_PROCEDURE_AREA AS MTPA
		 WHERE MTPA.USE_YN                    = 'Y'
		   AND MTPA.MU_TREATMENT_PROCEDURE_ID = #{muTreatmentProcedureId}
	</select>

	<insert id="insertTreatmentProcedureArea" parameterType="hashmap">
		<selectKey resultType="string" keyProperty="id" order="BEFORE">
			SELECT CONCAT(#{muTreatmentProcedureAreaId},LPAD((SELECT NEXTVAL(MU_TREATMENT_PROCEDURE_AREA_SEQ)), 9, 0))
		</selectKey>
		INSERT INTO MU_TREATMENT_PROCEDURE_AREA(
					 MU_TREATMENT_PROCEDURE_AREA_ID
					,MU_TREATMENT_PROCEDURE_ID
					,ORDER_NUMBER
					,PROCEDURE_AREA_NAME
					,WRITE_DATE
					,WRITE_TIME
					,CUD_FLAG
					,USE_YN
					,REG_ID
					,REG_DATE
					,MOD_ID
					,MOD_DATE
					,T_ID
					,T_DATE
		)VALUES(
					 #{id}
					,#{muTreatmentProcedureId}
					,#{orderNumber}
					,#{procedureAreaName}
					,CURDATE()
					,CURTIME()
					,'C'
					,'Y'
					,#{regId}
					,NOW()
					,#{modId}
					,NOW()
					,#{tId}
					,#{tDate}
		)
	</insert>
	
	<update id="deleteTreatmentProcedureArea" parameterType="hashmap">
		UPDATE MU_TREATMENT_PROCEDURE_AREA
		   SET MOD_ID                    = #{modId}
			  ,MOD_DATE                  = NOW()
			  ,CUD_FLAG                  = 'D'
			  ,USE_YN                    = 'N'
		 WHERE USE_YN                          = 'Y'
		   AND MU_TREATMENT_PROCEDURE_ID       = #{muTreatmentProcedureId}
	</update>
	
</mapper>