<?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.AdvertisingCpaProductPackageDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingCpaProductPackage">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="product_package_id" property="productPackageId" jdbcType="VARCHAR"/>
        <result column="product_name" property="productName" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="api_domain" property="apiDomain" jdbcType="VARCHAR"/>
        <result column="api_method_create" property="apiMethodCreate" jdbcType="VARCHAR"/>
        <result column="api_method_refund" property="apiMethodRefund" jdbcType="VARCHAR"/>
        <result column="app_id" property="appId" jdbcType="VARCHAR"/>
        <result column="app_secret" property="appSecret" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    
    <sql id="Base_Column_List">
        id, product_package_id, product_name, description, api_domain, api_method_create, api_method_refund, app_id, app_secret, create_time        
    </sql>

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

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO advertising_cpa_product_package(
            product_package_id, 
            product_name, 
            description, 
            api_domain, 
            api_method_create, 
            api_method_refund, 
            app_id, 
            app_secret, 
            create_time
        ) VALUES (
            #{productPackageId, jdbcType=VARCHAR}, 
            #{productName, jdbcType=VARCHAR}, 
            #{description, jdbcType=VARCHAR}, 
            #{apiDomain, jdbcType=VARCHAR}, 
            #{apiMethodCreate, jdbcType=VARCHAR}, 
            #{apiMethodRefund, jdbcType=VARCHAR}, 
            #{appId, jdbcType=VARCHAR}, 
            #{appSecret, jdbcType=VARCHAR}, 
            #{createTime, jdbcType=TIMESTAMP}
        )
    </insert>
    
    <insert id="batchInsert">
        INSERT INTO advertising_cpa_product_package (
            product_package_id, 
            product_name, 
            description, 
            api_domain, 
            api_method_create, 
            api_method_refund, 
            app_id, 
            app_secret, 
            create_time
        ) VALUES 
        <foreach collection="list" item="item" separator=",">
        (
            #{item.productPackageId, jdbcType=VARCHAR}, 
            #{item.productName, jdbcType=VARCHAR}, 
            #{item.description, jdbcType=VARCHAR}, 
            #{item.apiDomain, jdbcType=VARCHAR}, 
            #{item.apiMethodCreate, jdbcType=VARCHAR}, 
            #{item.apiMethodRefund, jdbcType=VARCHAR}, 
            #{item.appId, jdbcType=VARCHAR}, 
            #{item.appSecret, jdbcType=VARCHAR}, 
            #{item.createTime, jdbcType=TIMESTAMP}
        )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE advertising_cpa_product_package
        <set>
            <if test="productPackageId != null and productPackageId != ''">
                product_package_id = #{productPackageId},
            </if>
            <if test="productName != null and productName != ''">
                product_name = #{productName},
            </if>
            <if test="description != null and description != ''">
                description = #{description},
            </if>
            <if test="apiDomain != null and apiDomain != ''">
                api_domain = #{apiDomain},
            </if>
            <if test="apiMethodCreate != null and apiMethodCreate != ''">
                api_method_create = #{apiMethodCreate},
            </if>
            <if test="apiMethodRefund != null and apiMethodRefund != ''">
                api_method_refund = #{apiMethodRefund},
            </if>
            <if test="appId != null and appId != ''">
                app_id = #{appId},
            </if>
            <if test="appSecret != null and appSecret != ''">
                app_secret = #{appSecret},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

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

    <select id="getByProductPackageId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM advertising_cpa_product_package
        WHERE product_package_id = #{productPackageId}
    </select>
  
</mapper>
