package com.uas.platform.b2b.dao;

import com.uas.platform.b2b.model.PurchaseBadIn;
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 PurchaseBadInDao extends JpaSpecificationExecutor<PurchaseBadIn>, JpaRepository<PurchaseBadIn, Long> {

	/**
	 * 按所属企业及编号查找采购验收单
	 * 
	 * @param enUU
	 * @param code
	 * @return
	 */
	public List<PurchaseBadIn> findByEnUUAndCode(Long enUU, String code);
	
	/**
	 * 卖家根据卖家UU号和下载状态获取需要下载的客户采购验收入库单
	 * @return
	 */
	public List<PurchaseBadIn> findByVendUUAndSendStatus(Long vendUU, Short sendStatus);

	/**
	 * 按卖家UU、反过账状态查找
	 * @param vendUU
	 * @param sendStatus
	 * @param nonPosting
	 * @return
	 */
	public List<PurchaseBadIn> findByVendUUAndNonPosting(Long vendUU, Short nonPosting);
	
	/**
	 * 根据供应商UU号获取客户出库单数量
	 * @param vendUU
	 * @return
	 */
	@Query("select count(p) from PurchaseBadIn p where p.vendUU = :vendUU")
	public long countByVendUU(@Param("vendUU")Long vendUU);

	/**
	 * 通过企业UU和对应的erpid查询不良品入库单的id
	 *
	 * @param enUU 企业UU
	 * @param erpId erpId
	 * @return
	 */
	List<PurchaseBadIn> findByEnUUAndErpId(Long enUU, Long erpId);
}
