<?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.chat.mapper.ChatMsgLogsMapper">

    <resultMap type="ChatMsgLogs" id="ChatMsgLogsResult">
        <result property="logsId"    column="logs_id"    />
        <result property="msgId"    column="msg_id"    />
        <result property="logsType"    column="logs_type"    />
        <result property="content"    column="content"    />
        <result property="sContent"    column="s_content"    />
        <result property="userContent"    column="user_content"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectChatMsgLogsVo">
        select logs_id, msg_id, logs_type, company_id,content,s_content,user_content, company_user_id, create_time,create_by from chat_msg_logs
    </sql>

    <select id="selectChatMsgLogsList" parameterType="ChatMsgLogs" resultMap="ChatMsgLogsResult">
        <include refid="selectChatMsgLogsVo"/>
        <where>
            <if test="msgId != null "> and msg_id = #{msgId}</if>
            <if test="logsType != null "> and logs_type = #{logsType}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>

    <select id="selectChatMsgLogsByLogsId" parameterType="Long" resultMap="ChatMsgLogsResult">
        <include refid="selectChatMsgLogsVo"/>
        where logs_id = #{logsId}
    </select>

    <insert id="insertChatMsgLogs" parameterType="ChatMsgLogs" useGeneratedKeys="true" keyProperty="logsId">
        insert into chat_msg_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="msgId != null">msg_id,</if>
            <if test="logsType != null">logs_type,</if>
            <if test="content != null">content,</if>
            <if test="sContent != null">s_content,</if>
            <if test="userContent != null">user_content,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="msgId != null">#{msgId},</if>
            <if test="logsType != null">#{logsType},</if>
            <if test="content != null">#{content},</if>
            <if test="sContent != null">#{sContent},</if>
            <if test="userContent != null">#{userContent},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateChatMsgLogs" parameterType="ChatMsgLogs">
        update chat_msg_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="msgId != null">msg_id = #{msgId},</if>
            <if test="logsType != null">logs_type = #{logsType},</if>
            <if test="content != null">content = #{content},</if>
            <if test="sContent != null">s_content = #{sContent},</if>
            <if test="userContent != null">user_content = #{userContent},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where logs_id = #{logsId}
    </update>

    <delete id="deleteChatMsgLogsByLogsId" parameterType="Long">
        delete from chat_msg_logs where logs_id = #{logsId}
    </delete>

    <delete id="deleteChatMsgLogsByLogsIds" parameterType="String">
        delete from chat_msg_logs where logs_id in
        <foreach item="logsId" collection="array" open="(" separator="," close=")">
            #{logsId}
        </foreach>
    </delete>
</mapper>
