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

    <resultMap type="com.ruixuan.data.entity.KuaishouLiveDataAnalysis" id="KuaishouLiveDataAnalysisResult">
        <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="waresName" column="wares_name"/>
        <result property="waresPutDate" column="wares_put_date"/>
        <result property="waresPrice" column="wares_price"/>
        <result property="waresSalesAmount" column="wares_sales_amount"/>
        <result property="waresSalesVolume" column="wares_sales_volume"/>
        <result property="topayOrders" column="topay_orders"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLiveDataAnalysisVo">
        select ks_id,
               ks_name,
               account_id,
               account_name,
               wares_name,
               wares_put_date,
               wares_price,
               wares_sales_amount,
               wares_sales_volume,
               topay_orders,
               create_time,
               update_time
        from kuaishou_live_data_analysis
    </sql>

    <select id="selectKuaishouLiveDataAnalysisList" parameterType="com.ruixuan.data.entity.KuaishouLiveDataAnalysis"
            resultMap="KuaishouLiveDataAnalysisResult">
        <include refid="selectKuaishouLiveDataAnalysisVo"/>
        <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="waresName != null  and waresName != ''">and wares_name like concat('%', #{waresName}, '%')</if>
            <if test="waresPutDate != null  and waresPutDate != ''">and wares_put_date = #{waresPutDate}</if>
            <if test="waresPrice != null ">and wares_price = #{waresPrice}</if>
            <if test="waresSalesAmount != null ">and wares_sales_amount = #{waresSalesAmount}</if>
            <if test="waresSalesVolume != null ">and wares_sales_volume = #{waresSalesVolume}</if>
            <if test="topayOrders != null ">and topay_orders = #{topayOrders}</if>
        </where>
    </select>

    <select id="selectKuaishouLiveDataAnalysisByKsId" parameterType="Long" resultMap="KuaishouLiveDataAnalysisResult">
        <include refid="selectKuaishouLiveDataAnalysisVo"/>
        where ks_id = #{ksId}
    </select>

    <insert id="insertKuaishouLiveDataAnalysis" parameterType="com.ruixuan.data.entity.KuaishouLiveDataAnalysis">
        insert into kuaishou_live_data_analysis
        <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="waresName != null">wares_name,</if>
            <if test="waresPutDate != null">wares_put_date,</if>
            <if test="waresPrice != null">wares_price,</if>
            <if test="waresSalesAmount != null">wares_sales_amount,</if>
            <if test="waresSalesVolume != null">wares_sales_volume,</if>
            <if test="topayOrders != null">topay_orders,</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="waresName != null">#{waresName},</if>
            <if test="waresPutDate != null">#{waresPutDate},</if>
            <if test="waresPrice != null">#{waresPrice},</if>
            <if test="waresSalesAmount != null">#{waresSalesAmount},</if>
            <if test="waresSalesVolume != null">#{waresSalesVolume},</if>
            <if test="topayOrders != null">#{topayOrders},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLiveDataAnalysis" parameterType="com.ruixuan.data.entity.KuaishouLiveDataAnalysis">
        update kuaishou_live_data_analysis
        <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="waresName != null">wares_name = #{waresName},</if>
            <if test="waresPutDate != null">wares_put_date = #{waresPutDate},</if>
            <if test="waresPrice != null">wares_price = #{waresPrice},</if>
            <if test="waresSalesAmount != null">wares_sales_amount = #{waresSalesAmount},</if>
            <if test="waresSalesVolume != null">wares_sales_volume = #{waresSalesVolume},</if>
            <if test="topayOrders != null">topay_orders = #{topayOrders},</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="deleteKuaishouLiveDataAnalysisByKsId" parameterType="Long">
        delete
        from kuaishou_live_data_analysis
        where ks_id = #{ksId}
    </delete>

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


    <insert id="inserExcelBatchInfo">
        replace into kuaishou_live_data_analysis(
        ks_id,
        ks_name,
        account_id,
        account_name,
        wares_name,
        wares_put_date,
        wares_price,
        wares_sales_amount,
        wares_sales_volume,
        topay_orders
        )
        values
        <foreach collection="analysisList" item="cell" separator=",">
            (
            #{cell.ksId},
            #{cell.ksName},
            #{cell.accountId},
            #{cell.accountName},
            #{cell.waresName},
            #{cell.waresPutDate},
            #{cell.waresPrice},
            #{cell.waresSalesAmount},
            #{cell.waresSalesVolume},
            #{cell.topayOrders}
            )
        </foreach>
    </insert>
</mapper>