package com.uas.finance.dao;

import com.uas.finance.model.FinancingApply;
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/21
 **/
@Repository
public interface FinancingApplyDao extends JpaRepository<FinancingApply, Long> {

    /**
     * 通过保理企业UU和下载状态获取未下载的保理申请数据
     *
     * @param faenuu
     * @param status
     * @return
     */
    List<FinancingApply> findByFauuAndErpstatus(Long faenuu, Integer status);

    /**
     * 查找某企业申请的保理单
     *
     * @return
     */
    List<FinancingApply> findByEnuuOrderBySubmitTimeDesc(Long enuu);


    /**
     * 找出所有已是审核的申请单
     *
     * @param enuu
     * @return
     */
    @Query("from FinancingApply where enuu = :enuu and status = 204")
    List<FinancingApply> hasApproved(@Param("enuu") Long enuu);

    /**
     * 根据客户资料找到保理单
     * @param cusId
     * @return
     */
    FinancingApply findByCusId(Long cusId);



    /**
     * 确认客户资料
     * @param enuu
     * @return
     */
    @Modifying
    @Transactional
    @Query(value = "update financingapply set fa_check = 1 where fa_id = ?1 ",nativeQuery = true)
    void checkInfo(@Param("enuu") Long enuu);

    /**
     * 找到英唐保理下所有保理单据
     * @param fauu
     * @return
     */
    List<FinancingApply> findByFauu(Long fauu);
}
