<?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.BdReportDataMapper">
    
    <resultMap type="BdReportData" id="BdReportDataResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="date"    column="date"    />
        <result property="userName"    column="user_name"    />
        <result property="userId"    column="user_id"    />
        <result property="campaignId"    column="campaign_id"    />
        <result property="campaignName"    column="campaign_name"    />
        <result property="campaignStatus"    column="campaign_status"    />
        <result property="campaignNameStatus"    column="campaign_name_status"    />
        <result property="adGroupId"    column="ad_group_id"    />
        <result property="adGroupName"    column="ad_group_name"    />
        <result property="adGroupStatus"    column="ad_group_status"    />
        <result property="adGroupNameStatus"    column="ad_group_name_status"    />
        <result property="provinceId"    column="province_id"    />
        <result property="provinceName"    column="province_name"    />
        <result property="genderName"    column="gender_name"    />
        <result property="age"    column="age"    />
        <result property="showWord"    column="show_word"    />
        <result property="feedWord"    column="feed_word"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectBdReportDataVo">
        select id, type, date, user_name, user_id, campaign_id, campaign_name, campaign_status, campaign_name_status, ad_group_id, ad_group_name, ad_group_status, ad_group_name_status, province_id, province_name, gender_name, age, show_word, feed_word, create_time from bd_report_data
    </sql>

    <select id="selectBdReportDataList" parameterType="BdReportData" resultMap="BdReportDataResult">
        <include refid="selectBdReportDataVo"/>
        <where>  
            <if test="type != null "> and type = #{type}</if>
            <if test="date != null "> and date = #{date}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="campaignId != null "> and campaign_id = #{campaignId}</if>
            <if test="campaignName != null  and campaignName != ''"> and campaign_name like concat('%', #{campaignName}, '%')</if>
            <if test="campaignStatus != null "> and campaign_status = #{campaignStatus}</if>
            <if test="campaignNameStatus != null "> and campaign_name_status = #{campaignNameStatus}</if>
            <if test="adGroupId != null "> and ad_group_id = #{adGroupId}</if>
            <if test="adGroupName != null  and adGroupName != ''"> and ad_group_name like concat('%', #{adGroupName}, '%')</if>
            <if test="adGroupStatus != null "> and ad_group_status = #{adGroupStatus}</if>
            <if test="adGroupNameStatus != null "> and ad_group_name_status = #{adGroupNameStatus}</if>
            <if test="provinceId != null "> and province_id = #{provinceId}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="genderName != null  and genderName != ''"> and gender_name like concat('%', #{genderName}, '%')</if>
            <if test="age != null  and age != ''"> and age = #{age}</if>
            <if test="showWord != null  and showWord != ''"> and show_word = #{showWord}</if>
            <if test="feedWord != null  and feedWord != ''"> and feed_word = #{feedWord}</if>
        </where>
    </select>
    
    <select id="selectBdReportDataById" parameterType="Long" resultMap="BdReportDataResult">
        <include refid="selectBdReportDataVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBdReportData" parameterType="BdReportData" useGeneratedKeys="true" keyProperty="id">
        insert into bd_report_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="date != null">date,</if>
            <if test="userName != null">user_name,</if>
            <if test="userId != null">user_id,</if>
            <if test="campaignId != null">campaign_id,</if>
            <if test="campaignName != null">campaign_name,</if>
            <if test="campaignStatus != null">campaign_status,</if>
            <if test="campaignNameStatus != null">campaign_name_status,</if>
            <if test="adGroupId != null">ad_group_id,</if>
            <if test="adGroupName != null">ad_group_name,</if>
            <if test="adGroupStatus != null">ad_group_status,</if>
            <if test="adGroupNameStatus != null">ad_group_name_status,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="genderName != null">gender_name,</if>
            <if test="age != null">age,</if>
            <if test="showWord != null">show_word,</if>
            <if test="feedWord != null">feed_word,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="date != null">#{date},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userId != null">#{userId},</if>
            <if test="campaignId != null">#{campaignId},</if>
            <if test="campaignName != null">#{campaignName},</if>
            <if test="campaignStatus != null">#{campaignStatus},</if>
            <if test="campaignNameStatus != null">#{campaignNameStatus},</if>
            <if test="adGroupId != null">#{adGroupId},</if>
            <if test="adGroupName != null">#{adGroupName},</if>
            <if test="adGroupStatus != null">#{adGroupStatus},</if>
            <if test="adGroupNameStatus != null">#{adGroupNameStatus},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="genderName != null">#{genderName},</if>
            <if test="age != null">#{age},</if>
            <if test="showWord != null">#{showWord},</if>
            <if test="feedWord != null">#{feedWord},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateBdReportData" parameterType="BdReportData">
        update bd_report_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="date != null">date = #{date},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="campaignId != null">campaign_id = #{campaignId},</if>
            <if test="campaignName != null">campaign_name = #{campaignName},</if>
            <if test="campaignStatus != null">campaign_status = #{campaignStatus},</if>
            <if test="campaignNameStatus != null">campaign_name_status = #{campaignNameStatus},</if>
            <if test="adGroupId != null">ad_group_id = #{adGroupId},</if>
            <if test="adGroupName != null">ad_group_name = #{adGroupName},</if>
            <if test="adGroupStatus != null">ad_group_status = #{adGroupStatus},</if>
            <if test="adGroupNameStatus != null">ad_group_name_status = #{adGroupNameStatus},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="genderName != null">gender_name = #{genderName},</if>
            <if test="age != null">age = #{age},</if>
            <if test="showWord != null">show_word = #{showWord},</if>
            <if test="feedWord != null">feed_word = #{feedWord},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdReportDataById" parameterType="Long">
        delete from bd_report_data where id = #{id}
    </delete>

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