<?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.ruoyi.system.mapper.MessageMapper">
    
    <resultMap type="Message" id="MessageResult">
        <result property="messageId"    column="message_id"    />
        <result property="sendUserId"    column="send_user_id"    />
        <result property="receiveUserId"    column="receive_user_id"    />
        <result property="messageContent"    column="message_content"    />
        <result property="sendTime"    column="send_time"    />
        <result property="messageClass"    column="message_class"    />
        <result property="messageStatus"    column="message_status"    />
    </resultMap>

    <sql id="selectMessageVo">
        select message_id, send_user_id, receive_user_id, message_content, send_time, message_class, message_status from message
    </sql>



    <select id="selectMessageList" parameterType="Message" resultMap="MessageResult">
        <include refid="selectMessageVo"/>
        <where>  
            <if test="sendUserId != null "> and send_user_id = #{sendUserId}</if>
            <if test="receiveUserId != null "> and receive_user_id = #{receiveUserId}</if>
            <if test="messageContent != null  and messageContent != ''"> and message_content = #{messageContent}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
            <if test="messageClass != null  and messageClass != ''"> and message_class = #{messageClass}</if>
            <if test="messageStatus != null  and messageStatus != ''"> and message_status = #{messageStatus}</if>
        </where>
    </select>
    
    <select id="selectMessageByMessageId" parameterType="Long" resultMap="MessageResult">
        <include refid="selectMessageVo"/>
        where message_id = #{messageId}
    </select>

    <select id="selectMessageByReceiveUserId" parameterType="Long" resultMap="MessageResult">
        <include refid="selectMessageVo"/>
        where receive_user_id = #{receiveUserId}
    </select>
        
    <insert id="insertMessage" parameterType="Message" useGeneratedKeys="true" keyProperty="messageId">
        insert into message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sendUserId != null">send_user_id,</if>
            <if test="receiveUserId != null">receive_user_id,</if>
            <if test="messageContent != null and messageContent != ''">message_content,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="messageClass != null and messageClass != ''">message_class,</if>
            <if test="messageStatus != null and messageStatus != ''">message_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sendUserId != null">#{sendUserId},</if>
            <if test="receiveUserId != null">#{receiveUserId},</if>
            <if test="messageContent != null and messageContent != ''">#{messageContent},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="messageClass != null and messageClass != ''">#{messageClass},</if>
            <if test="messageStatus != null and messageStatus != ''">#{messageStatus},</if>
         </trim>
    </insert>

    <update id="updateMessage" parameterType="Message">
        update message
        <trim prefix="SET" suffixOverrides=",">
            <if test="sendUserId != null">send_user_id = #{sendUserId},</if>
            <if test="receiveUserId != null">receive_user_id = #{receiveUserId},</if>
            <if test="messageContent != null and messageContent != ''">message_content = #{messageContent},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="messageClass != null and messageClass != ''">message_class = #{messageClass},</if>
            <if test="messageStatus != null and messageStatus != ''">message_status = #{messageStatus},</if>
        </trim>
        where message_id = #{messageId}
    </update>

    <delete id="deleteMessageByMessageId" parameterType="Long">
        delete from message where message_id = #{messageId}
    </delete>

    <delete id="deleteMessageByMessageIds" parameterType="String">
        delete from message where message_id in 
        <foreach item="messageId" collection="array" open="(" separator="," close=")">
            #{messageId}
        </foreach>
    </delete>
</mapper>