package com.example.repository;



import com.example.entity.Attachment;

import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.data.jpa.repository.Query;

import org.springframework.data.repository.query.Param;

import org.springframework.stereotype.Repository;



import java.util.List;



/**

 * 附件数据访问层

 */

@Repository

public interface AttachmentRepository extends JpaRepository<Attachment, Long> {

    

    /**

     * 根据笔记ID查找附件列表

     * @param noteId 笔记ID

     * @return 附件列表

     */

    List<Attachment> findByNoteId(Long noteId);

    

    /**

     * 全局搜索:搜索附件的OCR内容

     * @param keyword 关键词

     * @return 匹配的附件列表

     */

    @Query("SELECT a FROM Attachment a WHERE a.ocrContent LIKE CONCAT('%', :keyword, '%')")

    List<Attachment> searchByOcrContent(@Param("keyword") String keyword);

}