<?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.BdCreativeMapper">
    
    <resultMap type="BdCreative" id="BdCreativeResult">
        <result property="creativeFeedId"    column="creative_feed_id"    />
        <result property="adgroupFeedId"    column="adgroup_feed_id"    />
        <result property="materialstyle"    column="materialstyle"    />
        <result property="creativeFeedName"    column="creative_feed_name"    />
        <result property="pause"    column="pause"    />
        <result property="status"    column="status"    />
        <result property="material"    column="material"    />
        <result property="refusereason"    column="refusereason"    />
        <result property="commentnum"    column="commentnum"    />
        <result property="readnum"    column="readnum"    />
        <result property="playnum"    column="playnum"    />
        <result property="ideaType"    column="idea_type"    />
        <result property="showMt"    column="show_mt"    />
        <result property="addtime"    column="addtime"    />
        <result property="progFlag"    column="prog_flag"    />
        <result property="videoId"    column="video_id"    />
        <result property="videoUrl"    column="video_url"    />
        <result property="templateJson"    column="template_json"    />
        <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="selectBdCreativeVo">
        select creative_feed_id, adgroup_feed_id, materialstyle, creative_feed_name, pause, status, material, refusereason, commentnum, readnum, playnum, idea_type, show_mt, addtime, prog_flag, video_id, video_url, template_json, create_time, create_by, update_by, update_time, remark from bd_creative
    </sql>

    <select id="selectBdCreativeList" parameterType="BdCreative" resultMap="BdCreativeResult">
        <include refid="selectBdCreativeVo"/>
        <where>  
            <if test="adgroupFeedId != null "> and adgroup_feed_id = #{adgroupFeedId}</if>
            <if test="accountId != null "> and account_id = #{accountId}</if>
            <if test="materialstyle != null "> and materialstyle = #{materialstyle}</if>
            <if test="creativeFeedName != null  and creativeFeedName != ''"> and creative_feed_name like concat('%', #{creativeFeedName}, '%')</if>
            <if test="pause != null "> and pause = #{pause}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="material != null  and material != ''"> and material = #{material}</if>
            <if test="refusereason != null  and refusereason != ''"> and refusereason = #{refusereason}</if>
            <if test="commentnum != null "> and commentnum = #{commentnum}</if>
            <if test="readnum != null "> and readnum = #{readnum}</if>
            <if test="playnum != null "> and playnum = #{playnum}</if>
            <if test="ideaType != null "> and idea_type = #{ideaType}</if>
            <if test="showMt != null "> and show_mt = #{showMt}</if>
            <if test="addtime != null  and addtime != ''"> and addtime = #{addtime}</if>
            <if test="progFlag != null  and progFlag != ''"> and prog_flag = #{progFlag}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="videoUrl != null  and videoUrl != ''"> and video_url = #{videoUrl}</if>
            <if test="templateJson != null  and templateJson != ''"> and template_json = #{templateJson}</if>
        </where>
    </select>
    
    <select id="selectBdCreativeByCreativeFeedId" parameterType="Long" resultMap="BdCreativeResult">
        <include refid="selectBdCreativeVo"/>
        where creative_feed_id = #{creativeFeedId}
    </select>
        
    <insert id="insertBdCreative" parameterType="BdCreative">
        insert into bd_creative
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="creativeFeedId != null">creative_feed_id,</if>
            <if test="adgroupFeedId != null">adgroup_feed_id,</if>
            <if test="materialstyle != null">materialstyle,</if>
            <if test="creativeFeedName != null">creative_feed_name,</if>
            <if test="pause != null">pause,</if>
            <if test="status != null">status,</if>
            <if test="material != null">material,</if>
            <if test="refusereason != null">refusereason,</if>
            <if test="commentnum != null">commentnum,</if>
            <if test="readnum != null">readnum,</if>
            <if test="playnum != null">playnum,</if>
            <if test="ideaType != null">idea_type,</if>
            <if test="showMt != null">show_mt,</if>
            <if test="addtime != null">addtime,</if>
            <if test="progFlag != null">prog_flag,</if>
            <if test="videoId != null">video_id,</if>
            <if test="videoUrl != null">video_url,</if>
            <if test="templateJson != null">template_json,</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="creativeFeedId != null">#{creativeFeedId},</if>
            <if test="adgroupFeedId != null">#{adgroupFeedId},</if>
            <if test="materialstyle != null">#{materialstyle},</if>
            <if test="creativeFeedName != null">#{creativeFeedName},</if>
            <if test="pause != null">#{pause},</if>
            <if test="status != null">#{status},</if>
            <if test="material != null">#{material},</if>
            <if test="refusereason != null">#{refusereason},</if>
            <if test="commentnum != null">#{commentnum},</if>
            <if test="readnum != null">#{readnum},</if>
            <if test="playnum != null">#{playnum},</if>
            <if test="ideaType != null">#{ideaType},</if>
            <if test="showMt != null">#{showMt},</if>
            <if test="addtime != null">#{addtime},</if>
            <if test="progFlag != null">#{progFlag},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
            <if test="templateJson != null">#{templateJson},</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="updateBdCreative" parameterType="BdCreative">
        update bd_creative
        <trim prefix="SET" suffixOverrides=",">
            <if test="adgroupFeedId != null">adgroup_feed_id = #{adgroupFeedId},</if>
            <if test="materialstyle != null">materialstyle = #{materialstyle},</if>
            <if test="creativeFeedName != null">creative_feed_name = #{creativeFeedName},</if>
            <if test="pause != null">pause = #{pause},</if>
            <if test="status != null">status = #{status},</if>
            <if test="material != null">material = #{material},</if>
            <if test="refusereason != null">refusereason = #{refusereason},</if>
            <if test="commentnum != null">commentnum = #{commentnum},</if>
            <if test="readnum != null">readnum = #{readnum},</if>
            <if test="playnum != null">playnum = #{playnum},</if>
            <if test="ideaType != null">idea_type = #{ideaType},</if>
            <if test="showMt != null">show_mt = #{showMt},</if>
            <if test="addtime != null">addtime = #{addtime},</if>
            <if test="progFlag != null">prog_flag = #{progFlag},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if>
            <if test="templateJson != null">template_json = #{templateJson},</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 creative_feed_id = #{creativeFeedId}
    </update>

    <delete id="deleteBdCreativeByCreativeFeedId" parameterType="Long">
        delete from bd_creative where creative_feed_id = #{creativeFeedId}
    </delete>

    <delete id="deleteBdCreativeByCreativeFeedIds" parameterType="String">
        delete from bd_creative where creative_feed_id in 
        <foreach item="creativeFeedId" collection="array" open="(" separator="," close=")">
            #{creativeFeedId}
        </foreach>
    </delete>
</mapper>