<?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.fs.baidu.mapper.BdPlanMapper">
    
    <resultMap type="BdPlan" id="BdPlanResult">
        <result property="campaignFeedId"    column="campaign_feed_id"    />
        <result property="campaignFeedName"    column="campaign_feed_name"    />
        <result property="subject"    column="subject"    />
        <result property="appinfo"    column="appinfo"    />
        <result property="schedule"    column="schedule"    />
        <result property="eshopType"    column="eshop_type"    />
        <result property="campaignOcpxStatus"    column="campaign_ocpx_status"    />
        <result property="useLiftBudget"    column="use_lift_budget"    />
        <result property="liftBudget"    column="lift_budget"    />
        <result property="liftStatus"    column="lift_status"    />
        <result property="deliveryType"    column="delivery_type"    />
        <result property="appSubType"    column="app_sub_type"    />
        <result property="miniProgramType"    column="mini_program_type"    />
        <result property="bidMode"    column="bid_mode"    />
        <result property="productIds"    column="product_ids"    />
        <result property="saleType"    column="sale_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBdPlanVo">
        select campaign_feed_id, campaign_feed_name, subject, appinfo, schedule, eshop_type, campaign_ocpx_status, use_lift_budget, lift_budget, lift_status, delivery_type, app_sub_type, mini_program_type, bid_mode, product_ids, sale_type, create_time, create_by, update_by, update_time, remark from bd_plan
    </sql>

    <select id="selectBdPlanList" parameterType="BdPlan" resultMap="BdPlanResult">
        <include refid="selectBdPlanVo"/>
        <where>  
            <if test="campaignFeedName != null  and campaignFeedName != ''"> and campaign_feed_name like concat('%', #{campaignFeedName}, '%')</if>
            <if test="subject != null "> and subject = #{subject}</if>
            <if test="accountId != null "> and account_id = #{accountId}</if>
            <if test="appinfo != null  and appinfo != ''"> and appinfo = #{appinfo}</if>
            <if test="schedule != null  and schedule != ''"> and schedule = #{schedule}</if>
            <if test="eshopType != null  and eshopType != ''"> and eshop_type = #{eshopType}</if>
            <if test="campaignOcpxStatus != null "> and campaign_ocpx_status = #{campaignOcpxStatus}</if>
            <if test="useLiftBudget != null "> and use_lift_budget = #{useLiftBudget}</if>
            <if test="liftBudget != null "> and lift_budget = #{liftBudget}</if>
            <if test="liftStatus != null "> and lift_status = #{liftStatus}</if>
            <if test="deliveryType != null  and deliveryType != ''"> and delivery_type = #{deliveryType}</if>
            <if test="appSubType != null "> and app_sub_type = #{appSubType}</if>
            <if test="miniProgramType != null "> and mini_program_type = #{miniProgramType}</if>
            <if test="bidMode != null "> and bid_mode = #{bidMode}</if>
            <if test="productIds != null "> and product_ids = #{productIds}</if>
            <if test="saleType != null "> and sale_type = #{saleType}</if>
        </where>
    </select>
    
    <select id="selectBdPlanByCampaignFeedId" parameterType="Long" resultMap="BdPlanResult">
        <include refid="selectBdPlanVo"/>
        where campaign_feed_id = #{campaignFeedId}
    </select>
        
    <insert id="insertBdPlan" parameterType="BdPlan">
        insert into bd_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="campaignFeedId != null">campaign_feed_id,</if>
            <if test="campaignFeedName != null">campaign_feed_name,</if>
            <if test="subject != null">subject,</if>
            <if test="appinfo != null">appinfo,</if>
            <if test="schedule != null">schedule,</if>
            <if test="eshopType != null">eshop_type,</if>
            <if test="campaignOcpxStatus != null">campaign_ocpx_status,</if>
            <if test="useLiftBudget != null">use_lift_budget,</if>
            <if test="liftBudget != null">lift_budget,</if>
            <if test="liftStatus != null">lift_status,</if>
            <if test="deliveryType != null">delivery_type,</if>
            <if test="appSubType != null">app_sub_type,</if>
            <if test="miniProgramType != null">mini_program_type,</if>
            <if test="bidMode != null">bid_mode,</if>
            <if test="productIds != null">product_ids,</if>
            <if test="saleType != null">sale_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="campaignFeedId != null">#{campaignFeedId},</if>
            <if test="campaignFeedName != null">#{campaignFeedName},</if>
            <if test="subject != null">#{subject},</if>
            <if test="appinfo != null">#{appinfo},</if>
            <if test="schedule != null">#{schedule},</if>
            <if test="eshopType != null">#{eshopType},</if>
            <if test="campaignOcpxStatus != null">#{campaignOcpxStatus},</if>
            <if test="useLiftBudget != null">#{useLiftBudget},</if>
            <if test="liftBudget != null">#{liftBudget},</if>
            <if test="liftStatus != null">#{liftStatus},</if>
            <if test="deliveryType != null">#{deliveryType},</if>
            <if test="appSubType != null">#{appSubType},</if>
            <if test="miniProgramType != null">#{miniProgramType},</if>
            <if test="bidMode != null">#{bidMode},</if>
            <if test="productIds != null">#{productIds},</if>
            <if test="saleType != null">#{saleType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBdPlan" parameterType="BdPlan">
        update bd_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="campaignFeedName != null">campaign_feed_name = #{campaignFeedName},</if>
            <if test="subject != null">subject = #{subject},</if>
            <if test="appinfo != null">appinfo = #{appinfo},</if>
            <if test="schedule != null">schedule = #{schedule},</if>
            <if test="eshopType != null">eshop_type = #{eshopType},</if>
            <if test="campaignOcpxStatus != null">campaign_ocpx_status = #{campaignOcpxStatus},</if>
            <if test="useLiftBudget != null">use_lift_budget = #{useLiftBudget},</if>
            <if test="liftBudget != null">lift_budget = #{liftBudget},</if>
            <if test="liftStatus != null">lift_status = #{liftStatus},</if>
            <if test="deliveryType != null">delivery_type = #{deliveryType},</if>
            <if test="appSubType != null">app_sub_type = #{appSubType},</if>
            <if test="miniProgramType != null">mini_program_type = #{miniProgramType},</if>
            <if test="bidMode != null">bid_mode = #{bidMode},</if>
            <if test="productIds != null">product_ids = #{productIds},</if>
            <if test="saleType != null">sale_type = #{saleType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where campaign_feed_id = #{campaignFeedId}
    </update>

    <delete id="deleteBdPlanByCampaignFeedId" parameterType="Long">
        delete from bd_plan where campaign_feed_id = #{campaignFeedId}
    </delete>

    <delete id="deleteBdPlanByCampaignFeedIds" parameterType="String">
        delete from bd_plan where campaign_feed_id in 
        <foreach item="campaignFeedId" collection="array" open="(" separator="," close=")">
            #{campaignFeedId}
        </foreach>
    </delete>
</mapper>