<?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.canvasGridSetting.CanvasGridSettingMapper">
    
    <select id="selectCanvasGridSetting" parameterType="string"
            resultType="com.interplug.qcast.biz.canvasGridSetting.dto.CanvasGridSettingInfo">
        /* sqlid : com.interplug.qcast.canvasGridSetting.selectCanvasGridSetting Canvas Grid Setting 조회 */
        SELECT object_no
             , dot_grid_display
             , line_grid_display
             , grid_type
             , grid_horizon
             , grid_vertical
             , grid_ratio
             , grid_dimen
             , regist_datetime
             , last_edit_datetime
          FROM TB_CANVAS_GRID_SETTING
         WHERE object_no = #{objectNo}
    </select>    
    
    <insert id="insertCanvasGridSetting" parameterType="com.interplug.qcast.biz.canvasGridSetting.dto.CanvasGridSettingInfo">
        /* sqlid : com.interplug.qcast.canvasGridSetting.insertCanvasGridSetting Canvas Grid Setting 등록 */
        MERGE TB_CANVAS_GRID_SETTING AS target
		USING (SELECT #{objectNo} AS object_no) AS source
		   ON (target.object_no = source.object_no)
		WHEN MATCHED THEN
	    UPDATE 
	       SET dot_grid_display = #{dotGridDisplay}
	         , line_grid_display = #{lineGridDisplay}
	         , grid_type = #{gridType}
	         , grid_horizon = #{gridHorizon}
	         , grid_vertical = #{gridVertical}
	         , grid_ratio = #{gridRatio}
	         , grid_dimen = #{gridDimen}
	         , last_edit_datetime = GETDATE()
		
		WHEN NOT MATCHED THEN
	    INSERT 
	              ( 
					object_no
			 	  , dot_grid_display
	         	  , line_grid_display
	         	  , grid_type
	         	  , grid_horizon
	         	  , grid_vertical
	         	  , grid_ratio
	         	  , grid_dimen
	              , regist_datetime
	              )
	       VALUES ( 
					#{objectNo}
				  , #{dotGridDisplay}
	         	  , #{lineGridDisplay}
	         	  , #{gridType}
	         	  , #{gridHorizon}
	         	  , #{gridVertical}
	         	  , #{gridRatio}
	         	  , #{gridDimen}
	              , GETDATE()
	              );
    </insert>
    
</mapper>