package com.uas.platform.b2b.dao;

import java.util.List;

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 com.uas.platform.b2b.model.PurchaseOrderItem;

@Repository
public interface PurchaseOrderItemDao extends JpaSpecificationExecutor<PurchaseOrderItem>, JpaRepository<PurchaseOrderItem, Long> {

	/**
	 * 按订单明细状态查找订单明细
	 * 
	 * @param statusCode
	 * @return
	 */
	@Query("from PurchaseOrderItem d where d.order.id = :orderId and d.status = :status")
	public List<PurchaseOrderItem> findByOrderIdAndStatus(@Param("orderId") long orderId, @Param("status") short status);

	/**
	 * 按订单单号和序号查找订单明细
	 * 
	 * @param enUU
	 * @param orderCode
	 * @param number
	 * @return
	 */
	@Query("from PurchaseOrderItem d where d.order.enUU = :enUU and d.order.code = :orderCode and d.number = :number")
	public List<PurchaseOrderItem> findByEnUUAndOrderCodeAndNumber(@Param("enUU") long enUU, @Param("orderCode") String orderCode,
			@Param("number") Short number);

	/**
	 * 按供应商ID和结案、反结案传输状态查找订单明细
	 * 
	 * @param vendUU
	 * @param endStatus
	 * @return
	 */
	@Query("from PurchaseOrderItem d where d.order.vendUU = :vendUU and d.endStatus = :endStatus")
	public List<PurchaseOrderItem> findByVendUUAndEndStatus(@Param("vendUU") long vendUU, @Param("endStatus") short endStatus);
}
