package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.Announcement;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 公告Mapper
 */
public interface AnnouncementMapper extends BaseMapper<Announcement> {

    /**
     * 查询所有已发布的公告
     * @return 公告列表
     */
    @Select("SELECT * FROM announcement WHERE status = 1 ORDER BY is_top DESC, create_time DESC")
    List<Announcement> selectAllPublished();
    
    /**
     * 查询所有已发布的公告（分页）
     * @param title 标题关键字
     * @return 公告列表
     */
    @Select("<script>SELECT * FROM announcement WHERE status = 1 " +
            "<if test=\"title != null and title != ''\">AND title LIKE CONCAT('%', #{title}, '%')</if>" +
            " ORDER BY is_top DESC, create_time DESC</script>")
    List<Announcement> selectAllPublishedWithKeyword(@Param("title") String title);
    
    /**
     * 查询所有公告（包括草稿，仅管理员可用）
     * @param title 标题关键字
     * @return 公告列表
     */
    @Select("<script>SELECT * FROM announcement " +
            "<if test=\"title != null and title != ''\">WHERE title LIKE CONCAT('%', #{title}, '%')</if>" +
            " ORDER BY is_top DESC, create_time DESC</script>")
    List<Announcement> selectAllForAdmin(@Param("title") String title);
} 