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

    <resultMap type="com.ruixuan.data.entity.KuaishouLiveDataOverview" id="KuaishouLiveDataOverviewResult">
        <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="amounts" column="amounts"/>
        <result property="statDate" column="stat_date"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLiveDataOverviewVo">
        select ks_id,
               ks_name,
               account_id,
               account_name,
               amounts,
               stat_date,
               create_time,
               update_time
        from kuaishou_live_data_overview
    </sql>

    <select id="selectKuaishouLiveDataOverviewList" parameterType="com.ruixuan.data.entity.KuaishouLiveDataOverview"
            resultMap="KuaishouLiveDataOverviewResult">
        <include refid="selectKuaishouLiveDataOverviewVo"/>
        <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="amounts != null ">and amounts = #{amounts}</if>
            <if test="statDate != null  and statDate != ''">and stat_date = #{statDate}</if>
        </where>
    </select>

    <select id="selectKuaishouLiveDataOverviewByKsId" parameterType="Long" resultMap="KuaishouLiveDataOverviewResult">
        <include refid="selectKuaishouLiveDataOverviewVo"/>
        where ks_id = #{ksId}
    </select>

    <insert id="insertKuaishouLiveDataOverview" parameterType="com.ruixuan.data.entity.KuaishouLiveDataOverview">
        insert into kuaishou_live_data_overview
        <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="amounts != null">amounts,</if>
            <if test="statDate != null">stat_date,</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="amounts != null">#{amounts},</if>
            <if test="statDate != null">#{statDate},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLiveDataOverview" parameterType="com.ruixuan.data.entity.KuaishouLiveDataOverview">
        update kuaishou_live_data_overview
        <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="amounts != null">amounts = #{amounts},</if>
            <if test="statDate != null">stat_date = #{statDate},</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="deleteKuaishouLiveDataOverviewByKsId" parameterType="Long">
        delete
        from kuaishou_live_data_overview
        where ks_id = #{ksId}
    </delete>

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


    <insert id="inserExcelBatchInfo">
        replace into kuaishou_live_data_overview(
        ks_id,
        ks_name,
        account_id,
        account_name,
        amounts,
        stat_date
        )
        values
        <foreach collection="overviewList" item="cell" separator=",">
            (
            #{cell.ksId},
            #{cell.ksName},
            #{cell.accountId},
            #{cell.accountName},
            #{cell.amounts},
            #{cell.statDate}
            )
        </foreach>
    </insert>

</mapper>