<?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="com.interplug.qcast.biz.specialNote.SpecialNoteMapper">

	<insert id="setSpecialNoteSave" parameterType="com.interplug.qcast.biz.specialNote.dto.SpecialNoteRequest" >
	/* sqlid : com.interplug.qcast.specialNote.setSpecialNoteSave (견적 특이사항 정보 등록/수정 - 동기화) */
		MERGE T_OBJECT_SPECIAL_NOTE AS A
		USING
			(
				SELECT #{spnAttrCd} AS SPN_ATTR_CD
					, #{spnTypeCd} AS SPN_TYPE_CD
			) AS T
			ON (
				A.SPN_ATTR_CD = T.SPN_ATTR_CD
				AND A.SPN_TYPE_CD = T.SPN_TYPE_CD
			)
		WHEN MATCHED THEN
			UPDATE SET
				  USE_FLG = #{useFlg}
				, REMARKS	= #{remarks}
				, DEL_FLG = #{delFlg}
				, REGIST_DATETIME = #{registDatetime}
				, LAST_EDIT_DATETIME = #{lastEditDatetime}
		WHEN NOT MATCHED THEN
			INSERT (
				  SPN_ATTR_CD
				, SPN_TYPE_CD
				, USE_FLG
				, REMARKS
				, DEL_FLG
				, REGIST_DATETIME
				, LAST_EDIT_DATETIME
			) VALUES (
				  #{spnAttrCd}
				, #{spnTypeCd}
				, #{useFlg}
				, #{remarks}
				, #{delFlg}
				, #{registDatetime}
				, #{lastEditDatetime}
			);
    </insert>

    <insert id="setSpecialNoteItemSave" parameterType="com.interplug.qcast.biz.specialNote.dto.SpecialNoteItemRequest" >
	/* sqlid : com.interplug.qcast.specialNote.setStoreDisplayItemSave (견적 특이사항 ITEM 정보 등록/수정 - 동기화) */
		MERGE T_OBJECT_SPECIAL_NOTE_ITEM AS A
		USING
			(
				SELECT #{spnAttrCd} AS SPN_ATTR_CD
					, #{spnTypeCd} AS SPN_TYPE_CD
					, #{itemId} AS ITEM_ID
			) AS T
			ON (
				A.SPN_ATTR_CD = T.SPN_ATTR_CD
				AND A.SPN_TYPE_CD = T.SPN_TYPE_CD
				AND A.ITEM_ID = T.ITEM_ID
			)
		WHEN MATCHED THEN
			UPDATE SET
				  DEL_FLG = #{delFlg}
				, REGIST_DATETIME = #{registDatetime}
				, LAST_EDIT_DATETIME = #{lastEditDatetime}
		WHEN NOT MATCHED THEN
			INSERT (
				  SPN_ATTR_CD
				, SPN_TYPE_CD
				, ITEM_ID
				, DEL_FLG
				, REGIST_DATETIME
				, LAST_EDIT_DATETIME
			) VALUES (
				  #{spnAttrCd}
				, #{spnTypeCd}
				, #{itemId}
				, #{delFlg}
				, #{registDatetime}
				, #{lastEditDatetime}
			);
	</insert>

</mapper>
