package com.uas.finance.dao;

import com.uas.finance.model.Attach;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 附件数据访问层
 * created by shicr on 2017/12/25
 **/
@Repository
public interface AttachDao extends JpaRepository<Attach, Long> {

    /**
     * 查找某金融单下的附件
     *
     * @param applyId
     * @return
     */
    List<Attach> findAttachesByApplyId(Long applyId);


    /**
     * 找到某家保理公司需要下载的文件
     *
     * @param fauu
     * @return
     */
    Attach findAttachesByFauu(Long fauu);

    /**
     * 删除附件
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Modifying
    @Query(value = "delete from attach where id = ?1", nativeQuery = true)
    void deleteOne(Long id);
}

