<?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.ruixuan.launch.mapper.KuaishouLaunchCampaignMapper">

    <resultMap type="com.ruixuan.launch.entity.KuaishouLaunchCampaign" id="KuaishouLaunchCampaignResult">
        <result property="id" column="id"/>
        <result property="accountId" column="account_id"/>
        <result property="campaignId" column="campaign_id"/>
        <result property="campaignName" column="campaign_name"/>
        <result property="campaignType" column="campaign_type"/>
        <result property="promotionType" column="promotion_type"/>
        <result property="putStatus" column="put_status"/>
        <result property="statDate" column="stat_date"/>
        <result property="dayBudget" column="day_budget"/>
        <result property="budgetSchedule" column="budget_schedule"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLaunchCampaignVo">
        select id,
               account_id,
               campaign_id,
               campaign_name,
               campaign_type,
               promotion_type,
               put_status,
               stat_date,
               day_budget,
               budget_schedule,
               create_time,
               update_time
        from kuaishou_launch_campaign
    </sql>

    <select id="selectKuaishouLaunchCampaignList" parameterType="com.ruixuan.launch.entity.KuaishouLaunchCampaign"
            resultMap="KuaishouLaunchCampaignResult">
        <include refid="selectKuaishouLaunchCampaignVo"/>
        <where>
            <if test="accountId != null ">and account_id = #{accountId}</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="campaignType != null ">and campaign_type = #{campaignType}</if>
            <if test="promotionType != null ">and promotion_type = #{promotionType}</if>
            <if test="putStatus != null ">and put_status = #{putStatus}</if>
            <if test="statDate != null ">and stat_date = #{statDate}</if>
            <if test="dayBudget != null ">and day_budget = #{dayBudget}</if>
            <if test="budgetSchedule != null  and budgetSchedule != ''">and budget_schedule = #{budgetSchedule}</if>
        </where>
    </select>

    <select id="selectKuaishouLaunchCampaignById" parameterType="String" resultMap="KuaishouLaunchCampaignResult">
        <include refid="selectKuaishouLaunchCampaignVo"/>
        where id = #{id}
    </select>

    <select id="getOne" resultMap="KuaishouLaunchCampaignResult">
        <include refid="selectKuaishouLaunchCampaignVo"/>
        where account_id = #{accountId}
        and campaign_name = #{campaignName}
    </select>

    <insert id="insertKuaishouLaunchCampaign" parameterType="com.ruixuan.launch.entity.KuaishouLaunchCampaign">
        insert into kuaishou_launch_campaign
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="accountId != null">account_id,</if>
            <if test="campaignId != null">campaign_id,</if>
            <if test="campaignName != null and campaignName != ''">campaign_name,</if>
            <if test="campaignType != null">campaign_type,</if>
            <if test="promotionType != null">promotion_type,</if>
            <if test="putStatus != null">put_status,</if>
            <if test="statDate != null">stat_date,</if>
            <if test="dayBudget != null">day_budget,</if>
            <if test="budgetSchedule != null">budget_schedule,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="accountId != null">#{accountId},</if>
            <if test="campaignId != null">#{campaignId},</if>
            <if test="campaignName != null and campaignName != ''">#{campaignName},</if>
            <if test="campaignType != null">#{campaignType},</if>
            <if test="promotionType != null">#{promotionType},</if>
            <if test="putStatus != null">#{putStatus},</if>
            <if test="statDate != null">#{statDate},</if>
            <if test="dayBudget != null">#{dayBudget},</if>
            <if test="budgetSchedule != null">#{budgetSchedule},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLaunchCampaign" parameterType="com.ruixuan.launch.entity.KuaishouLaunchCampaign">
        update kuaishou_launch_campaign
        <trim prefix="SET" suffixOverrides=",">
            <if test="accountId != null">account_id = #{accountId},</if>
            <if test="campaignId != null">campaign_id = #{campaignId},</if>
            <if test="campaignName != null and campaignName != ''">campaign_name = #{campaignName},</if>
            <if test="campaignType != null">campaign_type = #{campaignType},</if>
            <if test="promotionType != null">promotion_type = #{promotionType},</if>
            <if test="putStatus != null">put_status = #{putStatus},</if>
            <if test="statDate != null">stat_date = #{statDate},</if>
            <if test="dayBudget != null">day_budget = #{dayBudget},</if>
            <if test="budgetSchedule != null">budget_schedule = #{budgetSchedule},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKuaishouLaunchCampaignById" parameterType="String">
        delete
        from kuaishou_launch_campaign
        where id = #{id}
    </delete>

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