<?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.project.system.mapper.SysMessageMapper">

    <resultMap type="SysMessage" id="SysMessageResult">
        <result property="id"    column="id"    />
        <result property="msgTitle"    column="msg_title"    />
        <result property="msgType"    column="msg_type"    />
        <result property="msgContent"    column="msg_content"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="userId"    column="user_id"    />
        <result property="isRead"    column="is_read"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectSysMessageVo">
        select d.id, d.msg_title, d.msg_type, d.msg_content, d.status, d.create_by, d.create_time, d.user_id, d.is_read, d.remark  from sys_message d
    </sql>

    <select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
        <include refid="selectSysMessageVo"/>
        <where>
            <if test="msgTitle != null  and msgTitle != ''"> and msg_title = #{msgTitle}</if>
            <if test="msgType != null  and msgType != ''"> and msg_type = #{msgType}</if>
            <if test="msgContent != null  and msgContent != ''"> and msg_content = #{msgContent}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="isRead != null "> and is_read = #{isRead}</if>
            and d.del_flag = 0
        </where>
        order by d.create_time desc
    </select>

    <select id="selectSysMessageById" parameterType="Long" resultMap="SysMessageResult">
        <include refid="selectSysMessageVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysMessage" parameterType="SysMessage">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_sys_message.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into sys_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="msgTitle != null and msgTitle != ''">msg_title,</if>
            <if test="msgType != null and msgType != ''">msg_type,</if>
            <if test="msgContent != null">msg_content,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userId != null">user_id,</if>
            <if test="isRead != null">is_read,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="msgTitle != null and msgTitle != ''">#{msgTitle},</if>
            <if test="msgType != null and msgType != ''">#{msgType},</if>
            <if test="msgContent != null">#{msgContent},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="isRead != null">#{isRead},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysMessage" parameterType="SysMessage">
        update sys_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="msgTitle != null and msgTitle != ''">msg_title = #{msgTitle},</if>
            <if test="msgType != null and msgType != ''">msg_type = #{msgType},</if>
            <if test="msgContent != null">msg_content = #{msgContent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="isRead != null">is_read = #{isRead},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteSysMessageById" parameterType="Long">
        update sys_message set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteSysMessageByIds" parameterType="String">
        update sys_message set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
