<?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.ad.mapper.BdCreativeStatisticsMapper">
    
    <resultMap type="BdCreativeStatistics" id="BdCreativeStatisticsResult">
        <result property="id"    column="id"    />
        <result property="date"    column="date"    />
        <result property="userid"    column="userId"    />
        <result property="username"    column="userName"    />
        <result property="campaignnamestatus"    column="campaignNameStatus"    />
        <result property="adgroupnamestatus"    column="adGroupNameStatus"    />
        <result property="ideainfo"    column="ideaInfo"    />
        <result property="ideanamestatus"    column="ideaNameStatus"    />
        <result property="feedsubjectenum"    column="feedSubjectEnum"    />
        <result property="impression"    column="impression"    />
        <result property="click"    column="click"    />
        <result property="cost"    column="cost"    />
        <result property="ctr"    column="ctr"    />
        <result property="cpc"    column="cpc"    />
        <result property="cpm"    column="cpm"    />
        <result property="iaacost"    column="iaaCost"    />
        <result property="iaapayroi"    column="iaaPayRoi"    />
        <result property="phonebuttonclicks"    column="phoneButtonClicks"    />
        <result property="interaction"    column="interaction"    />
    </resultMap>

    <sql id="selectBdCreativeStatisticsVo">
        select id, date, userId, userName, campaignNameStatus, adGroupNameStatus, ideaInfo, ideaNameStatus, feedSubjectEnum, impression, click, cost, ctr, cpc, cpm, iaaCost, iaaPayRoi, phoneButtonClicks, interaction from bd_creative_statistics
    </sql>

    <select id="selectBdCreativeStatisticsList" parameterType="BdCreativeStatistics" resultMap="BdCreativeStatisticsResult">
        <include refid="selectBdCreativeStatisticsVo"/>
        <where>  
            <if test="date != null "> and date = #{date}</if>
            <if test="userid != null "> and userId = #{userid}</if>
            <if test="username != null "> and userName like concat('%', #{username}, '%')</if>
            <if test="campaignnamestatus != null "> and campaignNameStatus = #{campaignnamestatus}</if>
            <if test="adgroupnamestatus != null "> and adGroupNameStatus = #{adgroupnamestatus}</if>
            <if test="ideainfo != null  and ideainfo != ''"> and ideaInfo = #{ideainfo}</if>
            <if test="ideanamestatus != null "> and ideaNameStatus = #{ideanamestatus}</if>
            <if test="feedsubjectenum != null "> and feedSubjectEnum = #{feedsubjectenum}</if>
            <if test="impression != null "> and impression = #{impression}</if>
            <if test="click != null "> and click = #{click}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="ctr != null "> and ctr = #{ctr}</if>
            <if test="cpc != null "> and cpc = #{cpc}</if>
            <if test="cpm != null "> and cpm = #{cpm}</if>
            <if test="iaacost != null "> and iaaCost = #{iaacost}</if>
            <if test="iaapayroi != null "> and iaaPayRoi = #{iaapayroi}</if>
            <if test="phonebuttonclicks != null "> and phoneButtonClicks = #{phonebuttonclicks}</if>
            <if test="interaction != null "> and interaction = #{interaction}</if>
        </where>
    </select>
    
    <select id="selectBdCreativeStatisticsById" parameterType="Long" resultMap="BdCreativeStatisticsResult">
        <include refid="selectBdCreativeStatisticsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBdCreativeStatistics" parameterType="BdCreativeStatistics" useGeneratedKeys="true" keyProperty="id">
        insert into bd_creative_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="date != null">date,</if>
            <if test="userid != null">userId,</if>
            <if test="username != null">userName,</if>
            <if test="campaignnamestatus != null">campaignNameStatus,</if>
            <if test="adgroupnamestatus != null">adGroupNameStatus,</if>
            <if test="ideainfo != null">ideaInfo,</if>
            <if test="ideanamestatus != null">ideaNameStatus,</if>
            <if test="feedsubjectenum != null">feedSubjectEnum,</if>
            <if test="impression != null">impression,</if>
            <if test="click != null">click,</if>
            <if test="cost != null">cost,</if>
            <if test="ctr != null">ctr,</if>
            <if test="cpc != null">cpc,</if>
            <if test="cpm != null">cpm,</if>
            <if test="iaacost != null">iaaCost,</if>
            <if test="iaapayroi != null">iaaPayRoi,</if>
            <if test="phonebuttonclicks != null">phoneButtonClicks,</if>
            <if test="interaction != null">interaction,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="date != null">#{date},</if>
            <if test="userid != null">#{userid},</if>
            <if test="username != null">#{username},</if>
            <if test="campaignnamestatus != null">#{campaignnamestatus},</if>
            <if test="adgroupnamestatus != null">#{adgroupnamestatus},</if>
            <if test="ideainfo != null">#{ideainfo},</if>
            <if test="ideanamestatus != null">#{ideanamestatus},</if>
            <if test="feedsubjectenum != null">#{feedsubjectenum},</if>
            <if test="impression != null">#{impression},</if>
            <if test="click != null">#{click},</if>
            <if test="cost != null">#{cost},</if>
            <if test="ctr != null">#{ctr},</if>
            <if test="cpc != null">#{cpc},</if>
            <if test="cpm != null">#{cpm},</if>
            <if test="iaacost != null">#{iaacost},</if>
            <if test="iaapayroi != null">#{iaapayroi},</if>
            <if test="phonebuttonclicks != null">#{phonebuttonclicks},</if>
            <if test="interaction != null">#{interaction},</if>
         </trim>
    </insert>

    <update id="updateBdCreativeStatistics" parameterType="BdCreativeStatistics">
        update bd_creative_statistics
        <trim prefix="SET" suffixOverrides=",">
            <if test="date != null">date = #{date},</if>
            <if test="userid != null">userId = #{userid},</if>
            <if test="username != null">userName = #{username},</if>
            <if test="campaignnamestatus != null">campaignNameStatus = #{campaignnamestatus},</if>
            <if test="adgroupnamestatus != null">adGroupNameStatus = #{adgroupnamestatus},</if>
            <if test="ideainfo != null">ideaInfo = #{ideainfo},</if>
            <if test="ideanamestatus != null">ideaNameStatus = #{ideanamestatus},</if>
            <if test="feedsubjectenum != null">feedSubjectEnum = #{feedsubjectenum},</if>
            <if test="impression != null">impression = #{impression},</if>
            <if test="click != null">click = #{click},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="ctr != null">ctr = #{ctr},</if>
            <if test="cpc != null">cpc = #{cpc},</if>
            <if test="cpm != null">cpm = #{cpm},</if>
            <if test="iaacost != null">iaaCost = #{iaacost},</if>
            <if test="iaapayroi != null">iaaPayRoi = #{iaapayroi},</if>
            <if test="phonebuttonclicks != null">phoneButtonClicks = #{phonebuttonclicks},</if>
            <if test="interaction != null">interaction = #{interaction},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdCreativeStatisticsById" parameterType="Long">
        delete from bd_creative_statistics where id = #{id}
    </delete>

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