<?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.BdUnitMapper">
    
    <resultMap type="BdUnit" id="BdUnitResult">
        <result property="adgroupFeedId"    column="adgroup_feed_id"    />
        <result property="campaignFeedId"    column="campaign_feed_id"    />
        <result property="adgroupFeedName"    column="adgroup_feed_name"    />
        <result property="pause"    column="pause"    />
        <result property="status"    column="status"    />
        <result property="bid"    column="bid"    />
        <result property="ftypes"    column="ftypes"    />
        <result property="bidtype"    column="bidtype"    />
        <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="selectBdUnitVo">
        select adgroup_feed_id, campaign_feed_id, adgroup_feed_name, pause, status, bid, ftypes, bidtype, create_time, create_by, update_by, update_time, remark from bd_unit
    </sql>

    <select id="selectBdUnitList" parameterType="BdUnit" resultMap="BdUnitResult">
        <include refid="selectBdUnitVo"/>
        <where>  
            <if test="campaignFeedId != null "> and campaign_feed_id = #{campaignFeedId}</if>
            <if test="adgroupFeedName != null  and adgroupFeedName != ''"> and adgroup_feed_name like concat('%', #{adgroupFeedName}, '%')</if>
            <if test="accountId != null "> and account_id = #{accountId}</if>
            <if test="pause != null "> and pause = #{pause}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="bid != null "> and bid = #{bid}</if>
            <if test="ftypes != null "> and ftypes = #{ftypes}</if>
            <if test="bidtype != null  and bidtype != ''"> and bidtype = #{bidtype}</if>
        </where>
    </select>
    
    <select id="selectBdUnitByAdgroupFeedId" parameterType="Long" resultMap="BdUnitResult">
        <include refid="selectBdUnitVo"/>
        where adgroup_feed_id = #{adgroupFeedId}
    </select>
        
    <insert id="insertBdUnit" parameterType="BdUnit">
        insert into bd_unit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="adgroupFeedId != null">adgroup_feed_id,</if>
            <if test="campaignFeedId != null">campaign_feed_id,</if>
            <if test="adgroupFeedName != null">adgroup_feed_name,</if>
            <if test="pause != null">pause,</if>
            <if test="status != null">status,</if>
            <if test="bid != null">bid,</if>
            <if test="ftypes != null">ftypes,</if>
            <if test="bidtype != null">bidtype,</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="adgroupFeedId != null">#{adgroupFeedId},</if>
            <if test="campaignFeedId != null">#{campaignFeedId},</if>
            <if test="adgroupFeedName != null">#{adgroupFeedName},</if>
            <if test="pause != null">#{pause},</if>
            <if test="status != null">#{status},</if>
            <if test="bid != null">#{bid},</if>
            <if test="ftypes != null">#{ftypes},</if>
            <if test="bidtype != null">#{bidtype},</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="updateBdUnit" parameterType="BdUnit">
        update bd_unit
        <trim prefix="SET" suffixOverrides=",">
            <if test="campaignFeedId != null">campaign_feed_id = #{campaignFeedId},</if>
            <if test="adgroupFeedName != null">adgroup_feed_name = #{adgroupFeedName},</if>
            <if test="pause != null">pause = #{pause},</if>
            <if test="status != null">status = #{status},</if>
            <if test="bid != null">bid = #{bid},</if>
            <if test="ftypes != null">ftypes = #{ftypes},</if>
            <if test="bidtype != null">bidtype = #{bidtype},</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 adgroup_feed_id = #{adgroupFeedId}
    </update>

    <delete id="deleteBdUnitByAdgroupFeedId" parameterType="Long">
        delete from bd_unit where adgroup_feed_id = #{adgroupFeedId}
    </delete>

    <delete id="deleteBdUnitByAdgroupFeedIds" parameterType="String">
        delete from bd_unit where adgroup_feed_id in 
        <foreach item="adgroupFeedId" collection="array" open="(" separator="," close=")">
            #{adgroupFeedId}
        </foreach>
    </delete>
</mapper>