<?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.storeFavorite.StoreFavoriteMapper">
    <insert id="setStoreFavoriteSave" parameterType="com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteRequest" >
    /* sqlid : com.interplug.qcast.storeFavorite.setStoreFavoriteSave */
        MERGE M_USER_FAV_SALES_STORE AS A
        USING
            ( SELECT #{userId} AS USER_ID, #{saleStoreId} AS SALE_STORE_ID ) AS D
                ON (A.USER_ID = D.USER_ID AND A.SALE_STORE_ID = D.SALE_STORE_ID )
        WHEN MATCHED THEN
            UPDATE SET
                  DEL_FLG = #{delFlg}
                , DISP_ORDER = #{dispOrder}
                , LAST_EDIT_DATETIME = #{lastEditDatetime}
        WHEN NOT MATCHED THEN
            INSERT (
                  USER_ID
                , SALE_STORE_ID
                , DISP_ORDER
                , DEL_FLG
                , REGIST_DATETIME
                , LAST_EDIT_DATETIME
            ) VALUES (
                  #{userId}
                , #{saleStoreId}
                , #{dispOrder}
                , #{delFlg}
                , #{registDatetime}
                , #{lastEditDatetime}
            );
    </insert>
</mapper>
