package com.uas.platform.b2b.dao;

import com.uas.platform.b2b.model.MakeReturn;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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 MakeReturnDao extends JpaSpecificationExecutor<MakeReturn>, JpaRepository<MakeReturn, Long> {
	/**
	 * 按所属企业及编号查找委外验退单
	 * @param enUU
	 * @param code
	 * @return
	 */
	public List<MakeReturn> findByEnUUAndCode(Long enUU, String code);

	/**
	 * 卖家根据卖家UU号和下载状态获取需要下载的客户委外验收入库单
	 * @return
	 */
	public List<MakeReturn> findByVendUUAndSendStatus(Long vendUU, short sendStatus);

	/**
	 * 按卖家UU、反过账状态查找
	 * @param vendUU
	 * @param nonPosting
	 * @return
	 */
	public List<MakeReturn> findByVendUUAndNonPosting(Long vendUU,Short nonPosting);

	/**
	 * 根据供应商UU号获取客户委外验退单数量
	 * @param vendUU
	 * @return
	 */
	@Query("select count(p) from MakeReturn p where p.vendUU = :vendUU")
	public long countByVendUU(@Param("vendUU")Long vendUU);

	/**
	 * 通过enUU和erpId查询委外验退单是否存在
	 *
	 * @param enUU 企业UU号
	 * @param erpId erpId
	 * @return
	 */
    List<MakeReturn> findByEnUUAndErpId(Long enUU, Long erpId);
}
