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

    <resultMap type="QwMessage" id="QwMessageResult">
        <result property="id"    column="id"    />
        <result property="messageType"    column="message_type"    />
        <result property="senderId"    column="sender_id"    />
        <result property="receiverId"    column="receiver_id"    />
        <result property="roomId"    column="room_id"    />
        <result property="localId"    column="local_id"    />
        <result property="serverId"    column="server_id"    />
        <result property="sendTime"    column="send_time"    />
        <result property="param"    column="param"    />
        <result property="content"    column="content"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="url"    column="url"    />
        <result property="duration"    column="duration"    />
        <result property="width"    column="width"    />
        <result property="height"    column="height"    />
        <result property="fileSize"    column="file_size"    />
        <result property="fileShowType"    column="file_show_type"    />
        <result property="fileName"    column="file_name"    />
        <result property="conversationId"    column="conversation_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isRevoked"    column="is_revoked"    />
    </resultMap>

    <sql id="selectQwMessageVo">
        select id, message_type, sender_id, receiver_id, room_id, local_id, server_id, send_time, param,content,url,image_url ,duration,width,height, file_size,file_show_type,file_name ,conversation_id, create_time, update_time ,is_revoked  from qw_message
    </sql>

    <select id="selectQwMessageList" parameterType="QwMessage" resultMap="QwMessageResult">
        <include refid="selectQwMessageVo"/>
        <where>
            <if test="messageType != null "> and message_type = #{messageType}</if>
            <if test="senderId != null "> and sender_id = #{senderId}</if>
            <if test="receiverId != null "> and receiver_id = #{receiverId}</if>
            <if test="roomId != null "> and room_id = #{roomId}</if>
            <if test="localId != null "> and local_id = #{localId}</if>
            <if test="serverId != null "> and server_id = #{serverId}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
            <if test="param != null  and param != ''"> and param = #{param}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="duration != null "> and duration = #{duration}</if>
            <if test="width != null "> and width = #{width}</if>
            <if test="height != null "> and height = #{height}</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="fileName != null "> and file_name = #{fileName}</if>
            <if test="conversationId != null  and conversationId != ''"> and conversation_id = #{conversationId}</if>
            <if test="isRevoked != null "> and is_revoked = #{isRevoked}</if>
        </where>
    </select>

    <select id="selectQwMessageById" parameterType="Long" resultMap="QwMessageResult">
        <include refid="selectQwMessageVo"/>
        where id = #{id}
    </select>

    <select id="selectQwMessageByServerId" parameterType="Long" resultMap="QwMessageResult">
        <include refid="selectQwMessageVo"/>
        where server_id = #{serverId}
    </select>

    <insert id="insertQwMessage"  parameterType="QwMessage" useGeneratedKeys="true" keyProperty="id">
        insert into qw_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="messageType != null">message_type,</if>
            <if test="senderId != null">sender_id,</if>
            <if test="receiverId != null">receiver_id,</if>
            <if test="roomId != null">room_id,</if>
            <if test="localId != null">local_id,</if>
            <if test="serverId != null">server_id,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="param != null">param,</if>
            <if test="content != null">content,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="url != null">url,</if>
            <if test="duration != null">duration,</if>
            <if test="width != null">width,</if>
            <if test="height != null">height,</if>
            <if test="fileSize != null ">file_size,</if>
            <if test="fileShowType != null ">file_show_type,</if>
            <if test="fileName != null ">file_name,</if>
            <if test="conversationId != null">conversation_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isRevoked != null">is_revoked,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="messageType != null">#{messageType},</if>
            <if test="senderId != null">#{senderId},</if>
            <if test="receiverId != null">#{receiverId},</if>
            <if test="roomId != null">#{roomId},</if>
            <if test="localId != null">#{localId},</if>
            <if test="serverId != null">#{serverId},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="param != null">#{param},</if>
            <if test="content != null">#{content},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="url != null">#{url},</if>
            <if test="duration != null">#{duration},</if>
            <if test="width != null">#{width},</if>
            <if test="height != null">#{height},</if>
            <if test="fileSize != null ">#{fileSize},</if>
            <if test="fileShowType != null ">#{fileShowType},</if>
            <if test="fileName != null ">#{fileName},</if>
            <if test="conversationId != null">#{conversationId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isRevoked != null">#{isRevoked},</if>
        </trim>
    </insert>

    <update id="updateQwMessage" parameterType="QwMessage">
        update qw_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="messageType != null">message_type = #{messageType},</if>
            <if test="senderId != null">sender_id = #{senderId},</if>
            <if test="receiverId != null">receiver_id = #{receiverId},</if>
            <if test="roomId != null">room_id = #{roomId},</if>
            <if test="localId != null">local_id = #{localId},</if>
            <if test="serverId != null">server_id = #{serverId},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="param != null">param = #{param},</if>
            <if test="content != null">content = #{content},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="url != null">url = #{url},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="width != null">width = #{width},</if>
            <if test="height != null">height = #{height},</if>
            <if test="fileSize != null ">file_size = #{fileSize},</if>
            <if test="fileShowType != null ">file_show_type = #{fileShowType},</if>
            <if test="fileName != null ">file_name = #{fileName},</if>
            <if test="conversationId != null">conversation_id = #{conversationId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isRevoked != null">is_revoked = #{isRevoked},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwMessageById" parameterType="Long">
        delete from qw_message where id = #{id}
    </delete>

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

</mapper>
