<?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.SysMessageMapper">
    
    <resultMap type="SysMessage" id="SysMessageResult">
        <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="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="messageType"    column="message_type"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="messageStatus"    column="message_status"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectSysMessageVo">
        select message_id, send_user_id, receive_user_id, message_content, create_time, create_by, message_type, update_time, update_by, message_status, del_flag from sys_message
    </sql>

    <select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
        <include refid="selectSysMessageVo"/>
        <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="messageType != null  and messageType != ''"> and message_type = #{messageType}</if>
            <if test="messageStatus != null  and messageStatus != ''"> and message_status = #{messageStatus}</if>
        </where>
    </select>
    
    <select id="selectSysMessageByMessageId" parameterType="Long" resultMap="SysMessageResult">
        <include refid="selectSysMessageVo"/>
        where message_id = #{messageId}
    </select>
        
    <insert id="insertSysMessage" parameterType="SysMessage" useGeneratedKeys="true" keyProperty="messageId">
        insert into sys_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="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="messageType != null">message_type,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="messageStatus != null">message_status,</if>
            <if test="delFlag != null">del_flag,</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="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="messageType != null">#{messageType},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="messageStatus != null">#{messageStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateSysMessage" parameterType="SysMessage">
        update sys_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="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="messageType != null">message_type = #{messageType},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="messageStatus != null">message_status = #{messageStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where message_id = #{messageId}
    </update>

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

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