package top.tqx.demo_1.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.tqx.demo_1.entity.CollectionFile;

import java.util.List;

@Mapper
public interface CollectionFileMapper extends BaseMapper<CollectionFile> {

    @Select("SELECT cf.*, f.file_name, f.file_path as storage_path, f.file_size, f.dept_id " +
            "FROM collection_file cf " +
            "LEFT JOIN file f ON cf.file_id = f.id " +
            "WHERE cf.doc_name = #{docName} AND cf.status = 1")
    List<CollectionFile> findByDocNameWithFileInfo(@Param("docName") String docName);

    @Select("SELECT cf.*, f.file_name, f.file_path as storage_path, f.file_size, f.dept_id " +
            "FROM collection_file cf " +
            "LEFT JOIN file f ON cf.file_id = f.id " +
            "WHERE cf.collection_name = #{collectionName} AND cf.status = 1")
    List<CollectionFile> findByCollectionName(@Param("collectionName") String collectionName);

    @Select("SELECT * FROM collection_file WHERE collection_name = #{collectionName} AND doc_name = #{docName}")
    CollectionFile findByCollectionAndDocName(@Param("collectionName") String collectionName, @Param("docName") String docName);

    @Select("SELECT * FROM collection_file WHERE file_id = #{fileId}")
    CollectionFile findByFileId(@Param("fileId") Long fileId);
}
