<?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="org.xyzh.system.mapper.SysNotificationMapper">

    <!-- 基础结果映射 -->
    <resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysNotification">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="user_id" property="userID" jdbcType="VARCHAR"/>
        <result column="type" property="type" jdbcType="INTEGER"/>
        <result column="title" property="title" jdbcType="VARCHAR"/>
        <result column="content" property="content" jdbcType="LONGVARCHAR"/>
        <result column="link_type" property="linkType" jdbcType="INTEGER"/>
        <result column="link_id" property="linkID" jdbcType="VARCHAR"/>
        <result column="is_read" property="isRead" jdbcType="BOOLEAN"/>
        <result column="read_time" property="readTime" jdbcType="TIMESTAMP"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!-- 基础字段 -->
    <sql id="Base_Column_List">
        id, user_id, type, title, content, link_type, link_id, is_read, 
        read_time, create_time
    </sql>

    <!-- 通用条件 -->
    <sql id="Where_Clause">
        <where>
            <if test="userID != null and userID != ''">
                AND user_id = #{userID}
            </if>
            <if test="type != null">
                AND type = #{type}
            </if>
            <if test="title != null and title != ''">
                AND title LIKE CONCAT('%', #{title}, '%')
            </if>
            <if test="isRead != null">
                AND is_read = #{isRead}
            </if>
            <if test="linkType != null">
                AND link_type = #{linkType}
            </if>
            <if test="linkID != null and linkID != ''">
                AND link_id = #{linkID}
            </if>
        </where>
    </sql>

    <!-- selectSysNotifications -->
    <select id="selectSysNotifications" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_sys_notification
        <include refid="Where_Clause"/>
        ORDER BY create_time DESC
    </select>

</mapper>
