<?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.canvasBasicSetting.CanvasBasicSettingMapper">
    
    <select id="selectCanvasBasicSetting" parameterType="string"
            resultType="com.interplug.qcast.biz.canvasBasicSetting.dto.CanvasBasicSettingResponse">
        /* sqlid : com.interplug.qcast.canvasBasicSetting.selectCanvasBasicSetting Canvas Basic Setting 조회 */
        SELECT cbs.object_no
		     , cbs.roof_size_set
		     , cbs.roof_angle_set
		     , crma.roof_apply
		     , crma.roof_seq
		     , crma.roof_type
		     , crma.roof_width
		     , crma.roof_height
		     , crma.roof_hajebichi
		     , crma.roof_gap
		     , crma.roof_layout
		  FROM TB_CANVAS_BASIC_SETUP cbs
		  LEFT JOIN TB_CANVAS_ROOF_MATERIALS_ADD crma
		    ON cbs.object_no = crma.object_no
		 WHERE cbs.object_no = #{objectNo}
    </select>    
    
    <insert id="insertCanvasBasicSetting" parameterType="com.interplug.qcast.biz.canvasBasicSetting.dto.CanvasBasicSettingInfo">
        /* sqlid : com.interplug.qcast.canvasBasicSetting.insertCanvasBasicSetting Canvas Basic Setting 등록 */
        MERGE TB_CANVAS_BASIC_SETUP AS target
		USING (SELECT #{objectNo} AS object_no) AS source
		   ON (target.object_no = source.object_no)
		WHEN MATCHED THEN
	    UPDATE 
	       SET roof_size_set = #{roofSizeSet}
	         , roof_angle_set = #{roofAngleSet}
	         , last_edit_datetime = GETDATE()
		
		WHEN NOT MATCHED THEN
	    INSERT 
	              ( 
					object_no
			 	  , roof_size_set
			 	  , roof_angle_set
	              , regist_datetime
	              , last_edit_datetime
	              )
	       VALUES ( 
					#{objectNo}	
	              , #{roofSizeSet}
	              , #{roofAngleSet}
	              , GETDATE()
	              , GETDATE()
	              );
    </insert>
    
    <insert id="insertRoofMaterialsAdd" parameterType="com.interplug.qcast.biz.canvasBasicSetting.dto.CanvasBasicSettingInfo">
        /* sqlid : com.interplug.qcast.canvasBasicSetting.insertRoofMaterialsAdd Canvas 지붕재추가 Setting 등록 */
	    INSERT INTO TB_CANVAS_ROOF_MATERIALS_ADD
	              ( 
					object_no
			 	  , roof_apply
			 	  , roof_seq
			 	  , roof_type
			 	  , roof_width
			 	  , roof_height
			 	  , roof_hajebichi
			 	  , roof_gap
			 	  , roof_layout
	              , regist_datetime
	              , last_edit_datetime
	              )
	       VALUES ( 
					#{objectNo}
				  , #{roofApply}
				  , #{roofSeq}
	              , #{roofType}
	              , #{roofWidth}
	              , #{roofHeight}
	              , #{roofHajebichi}
	              , #{roofGap}
	              , #{roofLayout}
	              , GETDATE()
	              , GETDATE()
	              );
    </insert>
    
    <delete id="deleteRoofMaterialsAdd" parameterType="string">
        /* sqlid : com.interplug.qcast.canvasBasicSetting.deleteRoofMaterialsAdd Canvas 지붕재추가 Setting 삭제 */
        DELETE FROM TB_CANVAS_ROOF_MATERIALS_ADD
         WHERE object_no = #{objectNo}
    </delete>
    
</mapper>