<?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.KuaishouLaunchCampaignAutoStrategyMapper">

    <resultMap type="com.ruixuan.launch.entity.KuaishouLaunchCampaignAutoStrategy"
               id="KuaishouLaunchCampaignAutoStrategyResult">
        <result property="id" column="id"/>
        <result property="state" column="state"/>
        <result property="accountId" column="account_id"/>
        <result property="campaignName" column="campaign_name"/>
        <result property="campaignType" column="campaign_type"/>
        <result property="promotionType" column="promotion_type"/>
        <result property="budgetSchedule" column="budget_schedule"/>
        <result property="unitName" column="unit_name"/>
        <result property="bidType" column="bid_type"/>
        <result property="ocpxActionArr" column="ocpx_action_arr"/>
        <result property="roiRatio" column="roi_ratio"/>
        <result property="sceneId" column="scene_id"/>
        <result property="unitType" column="unit_type"/>
        <result property="beginTimeStr" column="begin_time_str"/>
        <result property="endTimeStr" column="end_time_str"/>
        <result property="scheduleTime" column="schedule_time"/>
        <result property="dayBudget" column="day_budget"/>
        <result property="groupDayBudget" column="group_day_budget"/>
        <result property="supportType" column="support_type"/>
        <result property="showMode" column="show_mode"/>
        <result property="speed" column="speed"/>
        <result property="itemId" column="item_id"/>
        <result property="merchantItemPutType" column="merchant_item_put_type"/>
        <result property="shoppingCarProductId" column="shopping_car_product_id"/>
        <result property="liveUserId" column="live_user_id"/>
        <result property="targetTemplate" column="target_template"/>
        <result property="creativeName" column="creative_name"/>
        <result property="coverUrl" column="cover_url"/>
        <result property="coverWidth" column="cover_width"/>
        <result property="coverHeight" column="cover_height"/>
        <result property="photoId" column="photo_id"/>
        <result property="creativeMaterialType" column="creative_material_type"/>
        <result property="actionBar" column="action_bar"/>
        <result property="recommendation" column="recommendation"/>
        <result property="description" column="description"/>
        <result property="newExposeText" column="new_expose_text"/>
        <result property="newExposeUrl" column="new_expose_url"/>
        <result property="liveCreativeType" column="live_creative_type"/>
        <result property="createTime" column="create_time"/>
        <result property="createrId" column="creater_id"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLaunchCampaignAutoStrategyVo">
        select id,
               state,
               account_id,
               campaign_name,
               campaign_type,
               promotion_type,
               budget_schedule,
               unit_name,
               bid_type,
               ocpx_action_arr,
               roi_ratio,
               scene_id,
               unit_type,
               begin_time_str,
               end_time_str,
               schedule_time,
               day_budget,
               support_type,
               show_mode,
               speed,
               group_day_budget,
               item_id,
               merchant_item_put_type,
               shopping_car_product_id,
               live_user_id,
               target_template,
               creative_name,
               cover_url,
               cover_width,
               cover_height,
               photo_id,
               creative_material_type,
               action_bar,
               recommendation,
               description,
               new_expose_text,
               new_expose_url,
               live_creative_type
        from kuaishou_launch_campaign_auto_strategy
    </sql>

    <select id="selectKuaishouLaunchCampaignAutoStrategyList" resultType="com.alibaba.fastjson.JSONObject">
        SELECT t1.id,
        t1.account_id as 'accountId',
        t2.account_name as 'accountName',
        t1.campaign_name as 'campaignName',
        IFNULL(t3.nick_name, '-') as 'nickName',
        DATE_FORMAT(t1.create_time, '%Y-%m-%d %H:%i:%s') as 'createTime'
        FROM kuaishou_launch_campaign_auto_strategy t1
        LEFT JOIN kuaishou_live_user_account t2 ON t1.account_id = t2.account_id
        LEFT JOIN sys_user t3 ON t1.creater_id = t3.user_id
        where state = 1
        <if test="campaignName != null and campaignName != ''">and t1.campaign_name like concat('%', #{campaignName},
            '%')
        </if>
        <if test="accountName != null and accountName != ''">and t2.account_name like concat('%',#{accountName},
            '%')
        </if>
        order by t1.create_time desc

    </select>

    <select id="selectKuaishouLaunchCampaignAutoStrategyById" parameterType="Long"
            resultMap="KuaishouLaunchCampaignAutoStrategyResult">
        <include refid="selectKuaishouLaunchCampaignAutoStrategyVo"/>
        where id = #{id}
    </select>

    <insert id="insertKuaishouLaunchCampaignAutoStrategy"
            parameterType="com.ruixuan.launch.entity.KuaishouLaunchCampaignAutoStrategy" useGeneratedKeys="true"
            keyProperty="id">
        insert into kuaishou_launch_campaign_auto_strategy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="state != null">state,</if>
            <if test="accountId != null">account_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="budgetSchedule != null">budget_schedule,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="bidType != null">bid_type,</if>
            <if test="ocpxActionArr != null">ocpx_action_arr,</if>
            <if test="roiRatio != null">roi_ratio,</if>
            <if test="sceneId != null">scene_id,</if>
            <if test="unitType != null">unit_type,</if>
            <if test="beginTimeStr != null">begin_time_str,</if>
            <if test="endTimeStr != null">end_time_str,</if>
            <if test="scheduleTime != null">schedule_time,</if>
            <if test="dayBudget != null">day_budget,</if>
            <if test="groupDayBudget != null">group_day_budget,</if>
            <if test="supportType != null">support_type,</if>
            <if test="showMode != null">show_mode,</if>
            <if test="speed != null">speed,</if>
            <if test="itemId != null">item_id,</if>
            <if test="merchantItemPutType != null">merchant_item_put_type,</if>
            <if test="shoppingCarProductId != null">shopping_car_product_id,</if>
            <if test="liveUserId != null">live_user_id,</if>
            <if test="targetTemplate != null">target_template,</if>
            <if test="creativeName != null">creative_name,</if>
            <if test="coverUrl != null">cover_url,</if>
            <if test="coverWidth != null">cover_width,</if>
            <if test="coverHeight != null">cover_height,</if>
            <if test="photoId != null">photo_id,</if>
            <if test="creativeMaterialType != null">creative_material_type,</if>
            <if test="actionBar != null">action_bar,</if>
            <if test="recommendation != null">recommendation,</if>
            <if test="description != null">description,</if>
            <if test="newExposeText != null">new_expose_text,</if>
            <if test="newExposeUrl != null">new_expose_url,</if>
            <if test="liveCreativeType != null">live_creative_type,</if>
            <if test="createrId != null">creater_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="state != null">#{state},</if>
            <if test="accountId != null">#{accountId},</if>
            <if test="campaignName != null and campaignName != ''">#{campaignName},</if>
            <if test="campaignType != null">#{campaignType},</if>
            <if test="promotionType != null">#{promotionType},</if>
            <if test="budgetSchedule != null">#{budgetSchedule},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="bidType != null">#{bidType},</if>
            <if test="ocpxActionArr != null">#{ocpxActionArr},</if>
            <if test="roiRatio != null">#{roiRatio},</if>
            <if test="sceneId != null">#{sceneId},</if>
            <if test="unitType != null">#{unitType},</if>
            <if test="beginTimeStr != null">#{beginTimeStr},</if>
            <if test="endTimeStr != null">#{endTimeStr},</if>
            <if test="scheduleTime != null">#{scheduleTime},</if>
            <if test="dayBudget != null">#{dayBudget},</if>
            <if test="groupDayBudget != null">#{groupDayBudget},</if>
            <if test="supportType != null">#{supportType},</if>
            <if test="showMode != null">#{showMode},</if>
            <if test="speed != null">#{speed},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="merchantItemPutType != null">#{merchantItemPutType},</if>
            <if test="shoppingCarProductId != null">#{shoppingCarProductId},</if>
            <if test="liveUserId != null">#{liveUserId},</if>
            <if test="targetTemplate != null">#{targetTemplate},</if>
            <if test="creativeName != null">#{creativeName},</if>
            <if test="coverUrl != null">#{coverUrl},</if>
            <if test="coverWidth != null">#{coverWidth},</if>
            <if test="coverHeight != null">#{coverHeight},</if>
            <if test="photoId != null">#{photoId},</if>
            <if test="creativeMaterialType != null">#{creativeMaterialType},</if>
            <if test="actionBar != null">#{actionBar},</if>
            <if test="recommendation != null">#{recommendation},</if>
            <if test="description != null">#{description},</if>
            <if test="newExposeText != null">#{newExposeText},</if>
            <if test="newExposeUrl != null">#{newExposeUrl},</if>
            <if test="liveCreativeType != null">#{liveCreativeType},</if>
            <if test="createrId != null">#{createrId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLaunchCampaignAutoStrategy"
            parameterType="com.ruixuan.launch.entity.KuaishouLaunchCampaignAutoStrategy">
        update kuaishou_launch_campaign_auto_strategy
        <trim prefix="SET" suffixOverrides=",">
            <if test="state != null">state = #{state},</if>
            <if test="accountId != null">account_id = #{accountId},</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="budgetSchedule != null">budget_schedule = #{budgetSchedule},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="bidType != null">bid_type = #{bidType},</if>
            <if test="ocpxActionArr != null">ocpx_action_arr = #{ocpxActionArr},</if>
            <if test="roiRatio != null">roi_ratio = #{roiRatio},</if>
            <if test="sceneId != null">scene_id = #{sceneId},</if>
            <if test="unitType != null">unit_type = #{unitType},</if>
            <if test="beginTimeStr != null">begin_time_str = #{beginTimeStr},</if>
            <if test="endTimeStr != null">end_time_str = #{endTimeStr},</if>
            <if test="scheduleTime != null">schedule_time = #{scheduleTime},</if>
            <if test="dayBudget != null">day_budget = #{dayBudget},</if>
            <if test="groupDayBudget != null">group_day_budget = #{groupDayBudget},</if>
            <if test="supportType != null">support_type = #{supportType},</if>
            <if test="showMode != null">show_mode = #{showMode},</if>
            <if test="speed != null">speed = #{speed},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="merchantItemPutType != null">merchant_item_put_type = #{merchantItemPutType},</if>
            <if test="shoppingCarProductId != null">shopping_car_product_id = #{shoppingCarProductId},</if>
            <if test="liveUserId != null">live_user_id = #{liveUserId},</if>
            <if test="targetTemplate != null">target_template = #{targetTemplate},</if>
            <if test="creativeName != null">creative_name = #{creativeName},</if>
            <if test="coverUrl != null">cover_url = #{coverUrl},</if>
            <if test="coverWidth != null">cover_width = #{coverWidth},</if>
            <if test="coverHeight != null">cover_height = #{coverHeight},</if>
            <if test="photoId != null">photo_id = #{photoId},</if>
            <if test="creativeMaterialType != null">creative_material_type = #{creativeMaterialType},</if>
            <if test="actionBar != null">action_bar = #{actionBar},</if>
            <if test="recommendation != null">recommendation = #{recommendation},</if>
            <if test="description != null">description = #{description},</if>
            <if test="newExposeText != null">new_expose_text = #{newExposeText},</if>
            <if test="newExposeUrl != null">new_expose_url = #{newExposeUrl},</if>
            <if test="liveCreativeType != null">live_creative_type = #{liveCreativeType},</if>
            <if test="createrId != null">creater_id = #{createrId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

</mapper>