package com.uas.platform.b2b.dao;

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

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

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

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