<?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.pcloud.book.advertising.dao.impl.AdvertisingCpaPaySettingDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingCpaPaySetting">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="cpa_id" property="cpaId" jdbcType="BIGINT"/>
        <result column="first_option_item_id" property="firstOptionItemId" jdbcType="BIGINT"/>
        <result column="second_option_item_id" property="secondOptionItemId" jdbcType="BIGINT"/>
        <result column="product_package_id" property="productPackageId" jdbcType="VARCHAR"/>
        <result column="pay_price" property="payPrice" jdbcType="DECIMAL"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    
    <sql id="Base_Column_List">
        id, cpa_id, first_option_item_id, second_option_item_id, product_package_id, pay_price, create_time        
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM advertising_cpa_pay_setting
        WHERE id = #{id}
    </select>
    
    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM advertising_cpa_pay_setting
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO advertising_cpa_pay_setting(
            cpa_id, 
            first_option_item_id, 
            second_option_item_id, 
            product_package_id, 
            pay_price, 
            create_time
        ) VALUES (
            #{cpaId, jdbcType=BIGINT}, 
            #{firstOptionItemId, jdbcType=BIGINT}, 
            #{secondOptionItemId, jdbcType=BIGINT}, 
            #{productPackageId, jdbcType=VARCHAR}, 
            #{payPrice, jdbcType=DECIMAL}, 
            #{createTime, jdbcType=TIMESTAMP}
        )
    </insert>
    
    <insert id="batchInsert">
        INSERT INTO advertising_cpa_pay_setting (
            cpa_id, 
            first_option_item_id, 
            second_option_item_id, 
            product_package_id, 
            pay_price, 
            create_time
        ) VALUES 
        <foreach collection="list" item="item" separator=",">
        (
            #{item.cpaId, jdbcType=BIGINT}, 
            #{item.firstOptionItemId, jdbcType=BIGINT}, 
            #{item.secondOptionItemId, jdbcType=BIGINT}, 
            #{item.productPackageId, jdbcType=VARCHAR}, 
            #{item.payPrice, jdbcType=DECIMAL}, 
            #{item.createTime, jdbcType=TIMESTAMP}
        )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE advertising_cpa_pay_setting
        <set>
            <if test="cpaId != null">
                cpa_id = #{cpaId},
            </if>
            <if test="firstOptionItemId != null">
                first_option_item_id = #{firstOptionItemId},
            </if>
            <if test="secondOptionItemId != null">
                second_option_item_id = #{secondOptionItemId},
            </if>
            <if test="productPackageId != null and productPackageId != ''">
                product_package_id = #{productPackageId},
            </if>
            <if test="payPrice != null">
                pay_price = #{payPrice},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        DELETE FROM advertising_cpa_pay_setting where id = #{id}
    </delete>

    <!--通过主键删除-->
    <delete id="deleteByCpaId">
        DELETE FROM advertising_cpa_pay_setting where cpa_id = #{cpaId}
    </delete>

    <select id="getByCpaId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM advertising_cpa_pay_setting
        WHERE cpa_id = #{cpaId}
    </select>


</mapper>
