<?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.bytedance.mapper.BytedanceMapper">

    <insert id="replaceBatchActivitys">
        replace into bytedance_colonel_activity(
        institution_id,
        activity_id,
        colonel_buyin_id,
        activity_name,
        activity_start_time,
        activity_end_time,
        status,
        application_start_time,
        application_end_time,
        categories_limit
        )
        values
        <foreach collection="activityList" item="cell" separator=",">
            (
            #{cell.institutionId},
            #{cell.activityId},
            #{cell.colonelBuyinId},
            #{cell.activityName},
            #{cell.activityStartTime},
            #{cell.activityEndTime},
            #{cell.status},
            #{cell.applicationStartTime},
            #{cell.applicationEndTime},
            #{cell.categoriesLimit}
            )
        </foreach>
    </insert>


    <insert id="insertDetail"
            parameterType="com.ruixuan.bytedance.entity.BytedanceColonelActivityDetail" useGeneratedKeys="true"
            keyProperty="id">
        insert into bytedance_colonel_activity_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="institutionId != null">institution_id,</if>
            <if test="activityId != null">activity_id,</if>
            <if test="activityName != null">activity_name,</if>
            <if test="isNewShop != null">is_new_shop,</if>
            <if test="shopType != null">shop_type,</if>
            <if test="activityDesc != null">activity_desc,</if>
            <if test="applyStartTime != null">apply_start_time,</if>
            <if test="applyEndTime != null">apply_end_time,</if>
            <if test="commissionRate != null">commission_rate,</if>
            <if test="wechatId != null">wechat_id,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="estimatedSingleSale != null">estimated_single_sale,</if>
            <if test="activityType != null">activity_type,</if>
            <if test="specifiedShopIds != null">specified_shop_ids,</if>
            <if test="categories != null">categories,</if>
            <if test="shopScore != null">shop_score,</if>
            <if test="minPromotionDays != null">min_promotion_days,</if>
            <if test="thresholdCrossBorder != null">threshold_cross_border,</if>
            <if test="hasThreshold != null">has_threshold,</if>
            <if test="colonelBuyinId != null">colonel_buyin_id,</if>
            <if test="monthsOfProtection != null">months_of_protection,</if>
            <if test="colonelName != null">colonel_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="institutionId != null">#{institutionId},</if>
            <if test="activityId != null">#{activityId},</if>
            <if test="activityName != null">#{activityName},</if>
            <if test="isNewShop != null">#{isNewShop},</if>
            <if test="shopType != null">#{shopType},</if>
            <if test="activityDesc != null">#{activityDesc},</if>
            <if test="applyStartTime != null">#{applyStartTime},</if>
            <if test="applyEndTime != null">#{applyEndTime},</if>
            <if test="commissionRate != null">#{commissionRate},</if>
            <if test="wechatId != null">#{wechatId},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="estimatedSingleSale != null">#{estimatedSingleSale},</if>
            <if test="activityType != null">#{activityType},</if>
            <if test="specifiedShopIds != null">#{specifiedShopIds},</if>
            <if test="categories != null">#{categories},</if>
            <if test="shopScore != null">#{shopScore},</if>
            <if test="minPromotionDays != null">#{minPromotionDays},</if>
            <if test="thresholdCrossBorder != null">#{thresholdCrossBorder},</if>
            <if test="hasThreshold != null">#{hasThreshold},</if>
            <if test="colonelBuyinId != null">#{colonelBuyinId},</if>
            <if test="monthsOfProtection != null">#{monthsOfProtection},</if>
            <if test="colonelName != null">#{colonelName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>


    <select id="getDetailByActivityId" resultType="com.ruixuan.bytedance.entity.BytedanceColonelActivityDetail">
        select id,
               institution_id,
               activity_id,
               activity_name,
               is_new_shop,
               shop_type,
               activity_desc,
               apply_start_time,
               apply_end_time,
               commission_rate,
               wechat_id,
               phone_num,
               estimated_single_sale,
               activity_type,
               specified_shop_ids,
               categories,
               shop_score,
               min_promotion_days,
               threshold_cross_border,
               has_threshold,
               colonel_buyin_id,
               months_of_protection,
               colonel_name
        from bytedance_colonel_activity_detail
        where activity_id = #{activityId}
    </select>


    <insert id="replaceBatchOrders">
        replace into bytedance_order_list(
        order_id,
        buyer_app_id,
        distributor_buyin_id,
        distributor_name,
        ads_promotion_rate,
        product_id,
        product_name,
        product_img,
        author_account,
        author_openid,
        shop_id,
        shop_name,
        total_pay_amount,
        flow_point,
        app,
        update_time,
        pay_success_time,
        settle_time,
        pay_goods_amount,
        settled_goods_amount,
        item_num,
        refund_time,
        author_short_id,
        colonel_type,
        author_buyin_id,
        media_type,
        commission_rate,
        media_id,
        is_trusteeship,
        good_share_type,
        colonel_commission_rate,
        colonel_activity_id,
        colonel_estimated_commission,
        colonel_real_commission,
        colonel_tech_service_fee_rate,
        colonel_tech_service_fee,
        colonel_settled_tech_service_fee,
        colonel_institution_id,
        colonel_institution_name,
        colonel_buyin_id,
        second_commission_rate,
        second_activity_id,
        second_estimated_commission,
        second_real_commission,
        second_institution_id,
        second_institution_name,
        second_colonel_buyin_id
        )
        values
        <foreach collection="list" item="cell" separator=",">
            (
            #{cell.orderId},
            #{cell.buyerAppId},
            #{cell.distributorBuyinId},
            #{cell.distributorName},
            #{cell.adsPromotionRate},
            #{cell.productId},
            #{cell.productName},
            #{cell.productImg},
            #{cell.authorAccount},
            #{cell.authorOpenid},
            #{cell.shopId},
            #{cell.shopName},
            #{cell.totalPayAmount},
            #{cell.flowPoint},
            #{cell.app},
            #{cell.updateTime},
            #{cell.paySuccessTime},
            #{cell.settleTime},
            #{cell.payGoodsAmount},
            #{cell.settledGoodsAmount},
            #{cell.itemNum},
            #{cell.refundTime},
            #{cell.authorShortId},
            #{cell.colonelType},
            #{cell.authorBuyinId},
            #{cell.mediaType},
            #{cell.commissionRate},
            #{cell.mediaId},
            #{cell.isTrusteeship},
            #{cell.goodShareType},
            #{cell.colonelCommissionRate},
            #{cell.colonelActivityId},
            #{cell.colonelEstimatedCommission},
            #{cell.colonelRealCommission},
            #{cell.colonelTechServiceFeeRate},
            #{cell.colonelTechServiceFee},
            #{cell.colonelSettledTechServiceFee},
            #{cell.colonelInstitutionId},
            #{cell.colonelInstitutionName},
            #{cell.colonelBuyinId},
            #{cell.secondCommissionRate},
            #{cell.secondActivityId},
            #{cell.secondEstimatedCommission},
            #{cell.secondRealCommission},
            #{cell.secondInstitutionId},
            #{cell.secondInstitutionName},
            #{cell.secondColonelBuyinId}
            )
        </foreach>
    </insert>

</mapper>