<?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.youlai.boot.system.mapper.NoticeStatusMapper">

    <select id="listUnreadNotices" resultType="com.youlai.boot.system.model.vo.NoticeStatusVO">
        SELECT
            sn.id,
            sn.title,
            sns.read_status
        FROM
            sys_notice_status sns
        LEFT JOIN
                sys_notice sn
        ON
            sn.id = sns.notice_id
        WHERE
            user_id = #{userId}
            AND sns.read_status = 0
        ORDER BY
            sn.release_time DESC
    </select>

    <select id="getMyNoticePage" resultType="com.youlai.boot.system.model.vo.NoticeStatusVO">
        SELECT
            sn.id,
            sn.title,
            sn.notice_type,
            sn.release_by,
            sn.priority,
            sn.release_time,
            sns.read_status
        FROM
            sys_notice sn
        LEFT JOIN
            sys_notice_status sns
        ON
            sn.id = sns.notice_id
        <where>
            <if test="queryParams.userId != null">
                sns.user_id = #{queryParams.userId}
            </if>
            <if test="queryParams.title != null and queryParams.title != ''">
                AND sn.title LIKE CONCAT('%',#{queryParams.title},'%')
            </if>
        </where>
        ORDER BY
            sn.release_time DESC
    </select>
</mapper>
