<?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.qw.mapper.QwUserbehaviorDataMapper">
    
    <resultMap type="QwUserbehaviorData" id="QwUserbehaviorDataResult">
        <result property="id"    column="id"    />
        <result property="userid"    column="userid"    />
        <result property="statTime"    column="stat_time"    />
        <result property="chatCnt"    column="chat_cnt"    />
        <result property="messageCnt"    column="message_cnt"    />
        <result property="replyPercentage"    column="reply_percentage"    />
        <result property="avgReplyTime"    column="avg_reply_time"    />
        <result property="negativeFeedbackCnt"    column="negative_feedback_cnt"    />
        <result property="newApplyCnt"    column="new_apply_cnt"    />
        <result property="newContactCnt"    column="new_contact_cnt"    />
        <result property="companyid"    column="companyId"    />
    </resultMap>

    <sql id="selectQwUserbehaviorDataVo">
        select id, userid, stat_time, chat_cnt, message_cnt, reply_percentage, avg_reply_time, negative_feedback_cnt, new_apply_cnt, new_contact_cnt, companyId from qw_userbehavior_data
    </sql>

    <select id="selectQwUserbehaviorDataList" parameterType="QwUserbehaviorData" resultMap="QwUserbehaviorDataResult">
        <include refid="selectQwUserbehaviorDataVo"/>
        <where>  
            <if test="userid != null  and userid != ''"> and userid = #{userid}</if>
            <if test="statTime != null "> and stat_time = #{statTime}</if>
            <if test="chatCnt != null "> and chat_cnt = #{chatCnt}</if>
            <if test="messageCnt != null "> and message_cnt = #{messageCnt}</if>
            <if test="replyPercentage != null "> and reply_percentage = #{replyPercentage}</if>
            <if test="avgReplyTime != null "> and avg_reply_time = #{avgReplyTime}</if>
            <if test="negativeFeedbackCnt != null "> and negative_feedback_cnt = #{negativeFeedbackCnt}</if>
            <if test="newApplyCnt != null "> and new_apply_cnt = #{newApplyCnt}</if>
            <if test="newContactCnt != null "> and new_contact_cnt = #{newContactCnt}</if>
            <if test="companyid != null "> and companyId = #{companyid}</if>
        </where>
    </select>
    
    <select id="selectQwUserbehaviorDataById" parameterType="Long" resultMap="QwUserbehaviorDataResult">
        <include refid="selectQwUserbehaviorDataVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQwUserbehaviorData" parameterType="QwUserbehaviorData">
        insert into qw_userbehavior_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userid != null">userid,</if>
            <if test="statTime != null">stat_time,</if>
            <if test="chatCnt != null">chat_cnt,</if>
            <if test="messageCnt != null">message_cnt,</if>
            <if test="replyPercentage != null">reply_percentage,</if>
            <if test="avgReplyTime != null">avg_reply_time,</if>
            <if test="negativeFeedbackCnt != null">negative_feedback_cnt,</if>
            <if test="newApplyCnt != null">new_apply_cnt,</if>
            <if test="newContactCnt != null">new_contact_cnt,</if>
            <if test="companyid != null">companyId,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userid != null">#{userid},</if>
            <if test="statTime != null">#{statTime},</if>
            <if test="chatCnt != null">#{chatCnt},</if>
            <if test="messageCnt != null">#{messageCnt},</if>
            <if test="replyPercentage != null">#{replyPercentage},</if>
            <if test="avgReplyTime != null">#{avgReplyTime},</if>
            <if test="negativeFeedbackCnt != null">#{negativeFeedbackCnt},</if>
            <if test="newApplyCnt != null">#{newApplyCnt},</if>
            <if test="newContactCnt != null">#{newContactCnt},</if>
            <if test="companyid != null">#{companyid},</if>
         </trim>
    </insert>



    <insert id="insertOrUpdateQwUserbehaviorData" parameterType="QwUserbehaviorData">
        insert into qw_userbehavior_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userid != null">userid,</if>
            <if test="statTime != null">stat_time,</if>
            <if test="chatCnt != null">chat_cnt,</if>
            <if test="messageCnt != null">message_cnt,</if>
            <if test="replyPercentage != null">reply_percentage,</if>
            <if test="avgReplyTime != null">avg_reply_time,</if>
            <if test="negativeFeedbackCnt != null">negative_feedback_cnt,</if>
            <if test="newApplyCnt != null">new_apply_cnt,</if>
            <if test="newContactCnt != null">new_contact_cnt,</if>
            <if test="companyid != null">companyId,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userid != null">#{userid},</if>
            <if test="statTime != null">#{statTime},</if>
            <if test="chatCnt != null">#{chatCnt},</if>
            <if test="messageCnt != null">#{messageCnt},</if>
            <if test="replyPercentage != null">#{replyPercentage},</if>
            <if test="avgReplyTime != null">#{avgReplyTime},</if>
            <if test="negativeFeedbackCnt != null">#{negativeFeedbackCnt},</if>
            <if test="newApplyCnt != null">#{newApplyCnt},</if>
            <if test="newContactCnt != null">#{newContactCnt},</if>
            <if test="companyid != null">#{companyid},</if>
        </trim>
        on duplicate key update
        <trim  suffixOverrides=",">
            <if test="userid != null">userid = #{userid},</if>
            <if test="statTime != null">stat_time = #{statTime},</if>
            <if test="chatCnt != null">chat_cnt = #{chatCnt},</if>
            <if test="messageCnt != null">message_cnt = #{messageCnt},</if>
            <if test="replyPercentage != null">reply_percentage = #{replyPercentage},</if>
            <if test="avgReplyTime != null">avg_reply_time = #{avgReplyTime},</if>
            <if test="negativeFeedbackCnt != null">negative_feedback_cnt = #{negativeFeedbackCnt},</if>
            <if test="newApplyCnt != null">new_apply_cnt = #{newApplyCnt},</if>
            <if test="newContactCnt != null">new_contact_cnt = #{newContactCnt},</if>
            <if test="companyid != null">companyId = #{companyid},</if>
        </trim>
    </insert>

    <update id="updateQwUserbehaviorData" parameterType="QwUserbehaviorData">
        update qw_userbehavior_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="userid != null">userid = #{userid},</if>
            <if test="statTime != null">stat_time = #{statTime},</if>
            <if test="chatCnt != null">chat_cnt = #{chatCnt},</if>
            <if test="messageCnt != null">message_cnt = #{messageCnt},</if>
            <if test="replyPercentage != null">reply_percentage = #{replyPercentage},</if>
            <if test="avgReplyTime != null">avg_reply_time = #{avgReplyTime},</if>
            <if test="negativeFeedbackCnt != null">negative_feedback_cnt = #{negativeFeedbackCnt},</if>
            <if test="newApplyCnt != null">new_apply_cnt = #{newApplyCnt},</if>
            <if test="newContactCnt != null">new_contact_cnt = #{newContactCnt},</if>
            <if test="companyid != null">companyId = #{companyid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwUserbehaviorDataById" parameterType="Long">
        delete from qw_userbehavior_data where id = #{id}
    </delete>

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

</mapper>