<?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.SysMessageRecordMapper">
    
    <resultMap type="SysMessageRecord" id="SysMessageRecordResult">
        <result property="messageRecordId"    column="message_record_id"    />
        <result property="messageId"    column="message_id"    />
        <result property="userId"    column="user_id"    />
        <result property="isRead"    column="is_read"    />
        <result property="readTime"    column="read_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSysMessageRecordVo">
        select message_record_id, message_id, user_id, is_read, read_time, create_time, update_time from sys_message_record
    </sql>

    <select id="selectSysMessageRecordList" parameterType="SysMessageRecord" resultMap="SysMessageRecordResult">
        <include refid="selectSysMessageRecordVo"/>
        <where>  
            <if test="messageId != null "> and message_id = #{messageId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="isRead != null  and isRead != ''"> and is_read = #{isRead}</if>
            <if test="readTime != null "> and read_time = #{readTime}</if>
        </where>
    </select>
    
    <select id="selectSysMessageRecordByMessageRecordId" parameterType="Long" resultMap="SysMessageRecordResult">
        <include refid="selectSysMessageRecordVo"/>
        where message_record_id = #{messageRecordId}
    </select>
        
    <insert id="insertSysMessageRecord" parameterType="SysMessageRecord" useGeneratedKeys="true" keyProperty="messageRecordId">
        insert into sys_message_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="messageId != null">message_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="isRead != null">is_read,</if>
            <if test="readTime != null">read_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="messageId != null">#{messageId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="isRead != null">#{isRead},</if>
            <if test="readTime != null">#{readTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateSysMessageRecord" parameterType="SysMessageRecord">
        update sys_message_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="messageId != null">message_id = #{messageId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="isRead != null">is_read = #{isRead},</if>
            <if test="readTime != null">read_time = #{readTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where message_record_id = #{messageRecordId}
    </update>

    <delete id="deleteSysMessageRecordByMessageRecordId" parameterType="Long">
        delete from sys_message_record where message_record_id = #{messageRecordId}
    </delete>

    <delete id="deleteSysMessageRecordByMessageRecordIds" parameterType="String">
        delete from sys_message_record where message_record_id in 
        <foreach item="messageRecordId" collection="array" open="(" separator="," close=")">
            #{messageRecordId}
        </foreach>
    </delete>
</mapper>