<?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.fs.live.mapper.LiveTrafficLogMapper">

    <resultMap type="LiveTrafficLog" id="LiveTrafficLogResult">
        <result property="logId"    column="log_id"    />
        <result property="userId"    column="user_id"    />
        <result property="liveId"    column="live_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="qwExternalContactId"    column="qw_external_contact_id"    />
        <result property="internetTraffic"    column="internet_traffic"    />
        <result property="qwUserId"    column="qw_user_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="uuId"    column="uu_id"    />
    </resultMap>

    <sql id="selectLiveTrafficLogVo">
        select log_id, user_id, live_id, create_time, qw_external_contact_id, internet_traffic, qw_user_id, company_user_id, company_id, video_id, uu_id from live_traffic_log
    </sql>

    <select id="selectLiveTrafficLogList" parameterType="LiveTrafficLog" resultMap="LiveTrafficLogResult">
        <include refid="selectLiveTrafficLogVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="liveId != null "> and live_id = #{liveId}</if>
            <if test="qwExternalContactId != null "> and qw_external_contact_id = #{qwExternalContactId}</if>
            <if test="internetTraffic != null "> and internet_traffic = #{internetTraffic}</if>
            <if test="qwUserId != null  and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="uuId != null  and uuId != ''"> and uu_id = #{uuId}</if>
        </where>
    </select>

    <select id="selectLiveTrafficLogById" parameterType="Long" resultMap="LiveTrafficLogResult">
        <include refid="selectLiveTrafficLogVo"/>
        where log_id = #{logId}
    </select>

    <insert id="insertLiveTrafficLog" parameterType="LiveTrafficLog" useGeneratedKeys="true" keyProperty="logId">
        insert into live_traffic_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="liveId != null">live_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="qwExternalContactId != null">qw_external_contact_id,</if>
            <if test="internetTraffic != null">internet_traffic,</if>
            <if test="qwUserId != null">qw_user_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="uuId != null">uu_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="liveId != null">#{liveId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
            <if test="internetTraffic != null">#{internetTraffic},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="uuId != null">#{uuId},</if>
         </trim>
    </insert>

    <update id="updateLiveTrafficLog" parameterType="LiveTrafficLog">
        update live_traffic_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="liveId != null">live_id = #{liveId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
            <if test="internetTraffic != null">internet_traffic = #{internetTraffic},</if>
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="uuId != null">uu_id = #{uuId},</if>
        </trim>
        where log_id = #{logId}
    </update>

    <delete id="deleteLiveTrafficLogById" parameterType="Long">
        delete from live_traffic_log where log_id = #{logId}
    </delete>

    <delete id="deleteLiveTrafficLogByIds" parameterType="String">
        delete from live_traffic_log where log_id in
        <foreach item="logId" collection="array" open="(" separator="," close=")">
            #{logId}
        </foreach>
    </delete>
    <insert id="insertOrUpdateLiveTrafficLog" parameterType="com.fs.live.domain.LiveTrafficLog">
        INSERT INTO live_traffic_log (
                                   user_id,
            live_id,
            create_time,
            qw_external_contact_id,
            internet_traffic,
            qw_user_id,
            company_user_id,
            company_id,
            video_id,
            uu_id
        ) VALUES (
                  #{userId},
                     #{liveId},
                     #{createTime},
                     #{qwExternalContactId},
                     #{internetTraffic},
                     #{qwUserId},
                     #{companyUserId},
                     #{companyId},
                     #{videoId},
                     #{uuId}
                 ) ON DUPLICATE KEY UPDATE
                     user_id = VALUES(user_id),
            live_id = VALUES(live_id),
            create_time = VALUES(create_time),
            qw_external_contact_id = VALUES(qw_external_contact_id),
            internet_traffic = VALUES(internet_traffic),
            qw_user_id = VALUES(qw_user_id),
            company_user_id = VALUES(company_user_id),
            company_id = VALUES(company_id),
            video_id = VALUES(video_id)
    </insert>

</mapper>
