<?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.data.mapper.KuaishouLiveDataKanbanMapper">

    <resultMap type="com.ruixuan.data.entity.KuaishouLiveDataKanban" id="KuaishouLiveDataKanbanResult">
        <result property="ksId" column="ks_id"/>
        <result property="ksName" column="ks_name"/>
        <result property="accountId" column="account_id"/>
        <result property="accountName" column="account_name"/>
        <result property="onlineViewers" column="online_viewers"/>
        <result property="viewers" column="viewers"/>
        <result property="viewingTimes" column="viewing_times"/>
        <result property="perViewingTime" column="per_viewing_time"/>
        <result property="fansViewingTime" column="fans_viewing_time"/>
        <result property="rewards" column="rewards"/>
        <result property="putWares" column="put_wares"/>
        <result property="newFans" column="new_fans"/>
        <result property="likes" column="likes"/>
        <result property="waresClicks" column="wares_clicks"/>
        <result property="carClicks" column="car_clicks"/>
        <result property="allAmount" column="all_amount"/>
        <result property="allTurnover" column="all_turnover"/>
        <result property="allOrders" column="all_orders"/>
        <result property="turnoverRatio" column="turnover_ratio"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLiveDataKanbanVo">
        select ks_id,
               ks_name,
               account_id,
               account_name,
               online_viewers,
               viewers,
               viewing_times,
               per_viewing_time,
               fans_viewing_time,
               rewards,
               put_wares,
               new_fans,
               likes,
               wares_clicks,
               car_clicks,
               all_amount,
               all_turnover,
               all_orders,
               turnover_ratio,
               create_time,
               update_time
        from kuaishou_live_data_kanban
    </sql>

    <select id="selectKuaishouLiveDataKanbanList" parameterType="com.ruixuan.data.entity.KuaishouLiveDataKanban"
            resultMap="KuaishouLiveDataKanbanResult">
        <include refid="selectKuaishouLiveDataKanbanVo"/>
        <where>
            <if test="ksId != null ">and ks_id = #{ksId}</if>
            <if test="ksName != null  and ksName != ''">and ks_name like concat('%', #{ksName}, '%')</if>
            <if test="accountId != null ">and account_id = #{accountId}</if>
            <if test="accountName != null  and accountName != ''">and account_name like concat('%', #{accountName},
                '%')
            </if>
            <if test="onlineViewers != null ">and online_viewers = #{onlineViewers}</if>
            <if test="viewers != null ">and viewers = #{viewers}</if>
            <if test="viewingTimes != null ">and viewing_times = #{viewingTimes}</if>
            <if test="perViewingTime != null ">and per_viewing_time = #{perViewingTime}</if>
            <if test="fansViewingTime != null ">and fans_viewing_time = #{fansViewingTime}</if>
            <if test="rewards != null ">and rewards = #{rewards}</if>
            <if test="putWares != null ">and put_wares = #{putWares}</if>
            <if test="newFans != null ">and new_fans = #{newFans}</if>
            <if test="likes != null ">and likes = #{likes}</if>
            <if test="waresClicks != null ">and wares_clicks = #{waresClicks}</if>
            <if test="carClicks != null ">and car_clicks = #{carClicks}</if>
            <if test="allAmount != null ">and all_amount = #{allAmount}</if>
            <if test="allTurnover != null ">and all_turnover = #{allTurnover}</if>
            <if test="allOrders != null ">and all_orders = #{allOrders}</if>
            <if test="turnoverRatio != null  and turnoverRatio != ''">and turnover_ratio = #{turnoverRatio}</if>
        </where>
    </select>

    <select id="selectKuaishouLiveDataKanbanByKsId" parameterType="Long" resultMap="KuaishouLiveDataKanbanResult">
        <include refid="selectKuaishouLiveDataKanbanVo"/>
        where ks_id = #{ksId}
    </select>

    <insert id="insertKuaishouLiveDataKanban" parameterType="com.ruixuan.data.entity.KuaishouLiveDataKanban">
        insert into kuaishou_live_data_kanban
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ksId != null">ks_id,</if>
            <if test="ksName != null">ks_name,</if>
            <if test="accountId != null">account_id,</if>
            <if test="accountName != null">account_name,</if>
            <if test="onlineViewers != null">online_viewers,</if>
            <if test="viewers != null">viewers,</if>
            <if test="viewingTimes != null">viewing_times,</if>
            <if test="perViewingTime != null">per_viewing_time,</if>
            <if test="fansViewingTime != null">fans_viewing_time,</if>
            <if test="rewards != null">rewards,</if>
            <if test="putWares != null">put_wares,</if>
            <if test="newFans != null">new_fans,</if>
            <if test="likes != null">likes,</if>
            <if test="waresClicks != null">wares_clicks,</if>
            <if test="carClicks != null">car_clicks,</if>
            <if test="allAmount != null">all_amount,</if>
            <if test="allTurnover != null">all_turnover,</if>
            <if test="allOrders != null">all_orders,</if>
            <if test="turnoverRatio != null">turnover_ratio,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ksId != null">#{ksId},</if>
            <if test="ksName != null">#{ksName},</if>
            <if test="accountId != null">#{accountId},</if>
            <if test="accountName != null">#{accountName},</if>
            <if test="onlineViewers != null">#{onlineViewers},</if>
            <if test="viewers != null">#{viewers},</if>
            <if test="viewingTimes != null">#{viewingTimes},</if>
            <if test="perViewingTime != null">#{perViewingTime},</if>
            <if test="fansViewingTime != null">#{fansViewingTime},</if>
            <if test="rewards != null">#{rewards},</if>
            <if test="putWares != null">#{putWares},</if>
            <if test="newFans != null">#{newFans},</if>
            <if test="likes != null">#{likes},</if>
            <if test="waresClicks != null">#{waresClicks},</if>
            <if test="carClicks != null">#{carClicks},</if>
            <if test="allAmount != null">#{allAmount},</if>
            <if test="allTurnover != null">#{allTurnover},</if>
            <if test="allOrders != null">#{allOrders},</if>
            <if test="turnoverRatio != null">#{turnoverRatio},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLiveDataKanban" parameterType="com.ruixuan.data.entity.KuaishouLiveDataKanban">
        update kuaishou_live_data_kanban
        <trim prefix="SET" suffixOverrides=",">
            <if test="ksName != null">ks_name = #{ksName},</if>
            <if test="accountId != null">account_id = #{accountId},</if>
            <if test="accountName != null">account_name = #{accountName},</if>
            <if test="onlineViewers != null">online_viewers = #{onlineViewers},</if>
            <if test="viewers != null">viewers = #{viewers},</if>
            <if test="viewingTimes != null">viewing_times = #{viewingTimes},</if>
            <if test="perViewingTime != null">per_viewing_time = #{perViewingTime},</if>
            <if test="fansViewingTime != null">fans_viewing_time = #{fansViewingTime},</if>
            <if test="rewards != null">rewards = #{rewards},</if>
            <if test="putWares != null">put_wares = #{putWares},</if>
            <if test="newFans != null">new_fans = #{newFans},</if>
            <if test="likes != null">likes = #{likes},</if>
            <if test="waresClicks != null">wares_clicks = #{waresClicks},</if>
            <if test="carClicks != null">car_clicks = #{carClicks},</if>
            <if test="allAmount != null">all_amount = #{allAmount},</if>
            <if test="allTurnover != null">all_turnover = #{allTurnover},</if>
            <if test="allOrders != null">all_orders = #{allOrders},</if>
            <if test="turnoverRatio != null">turnover_ratio = #{turnoverRatio},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where ks_id = #{ksId}
    </update>

    <delete id="deleteKuaishouLiveDataKanbanByKsId" parameterType="Long">
        delete
        from kuaishou_live_data_kanban
        where ks_id = #{ksId}
    </delete>

    <delete id="deleteKuaishouLiveDataKanbanByKsIds" parameterType="String">
        delete from kuaishou_live_data_kanban where ks_id in
        <foreach item="ksId" collection="array" open="(" separator="," close=")">
            #{ksId}
        </foreach>
    </delete>

    <insert id="inserExcelBatchInfo">
        replace into kuaishou_live_data_kanban(
        ks_id,
        ks_name,
        account_id,
        account_name,
        online_viewers,
        viewers,
        viewing_times,
        per_viewing_time,
        fans_viewing_time,
        rewards,
        put_wares,
        new_fans,
        likes,
        wares_clicks,
        car_clicks,
        all_amount,
        all_turnover,
        all_orders,
        turnover_ratio
        )
        values
        <foreach collection="kanbanList" item="cell" separator=",">
            (
            #{cell.ksId},
            #{cell.ksName},
            #{cell.accountId},
            #{cell.accountName},
            #{cell.onlineViewers},
            #{cell.viewers},
            #{cell.viewingTimes},
            #{cell.perViewingTime},
            #{cell.fansViewingTime},
            #{cell.rewards},
            #{cell.putWares},
            #{cell.newFans},
            #{cell.likes},
            #{cell.waresClicks},
            #{cell.carClicks},
            #{cell.allAmount},
            #{cell.allTurnover},
            #{cell.allOrders},
            #{cell.turnoverRatio}
            )
        </foreach>
    </insert>

</mapper>