package com.uas.platform.b2b.dao;

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

	/**
	 * 按所属企业及编号查找MRB单
	 * 
	 * @param enUU
	 * @param code
	 * @return
	 */
	public List<PurchaseMRB> findPurchaseMRBByEnUUAndCode(Long enUU, String code);
	
	/**
	 * 卖家根据卖家UU号和下载状态获取需要下载的客户MRB单
	 * @return
	 */
	public List<PurchaseMRB> findPurchaseMRBByVendUUAndSendStatus(Long vendUU, Short sendStatus);
	
	/**
	 * 根据供应商UU号获取MRB数量
	 * @param vendUU
	 * @return
	 */
	@Query("select count(p) from PurchaseMRB p where p.vendUU = :vendUU")
	public long countByVendUU(@Param("vendUU")Long vendUU);

	/**
	 * 根据enUU和ERPid查询对应的B2Bid
	 *
	 * @param enUU 企业uu
	 * @param erpId erpId
	 * @return
	 */
    List<PurchaseMRB> findByEnUUAndErpId(Long enUU, Long erpId);
}
