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.PurchaseOrderReply;

@Repository
public interface PurchaseOrderReplyDao extends JpaSpecificationExecutor<PurchaseOrderReply>, JpaRepository<PurchaseOrderReply, Long> {

	/**
	 * 按订单明细ID查找订单明细回复
	 * 
	 * @param orderItemId
	 * @return
	 */
	@Query("from PurchaseOrderReply r where r.orderItem.id = :orderItemId order by r.date desc")
	public List<PurchaseOrderReply> findByOrderItemId(@Param("orderItemId") long orderItemId);

	/**
	 * (买家)按回复记录的状态查找回复记录
	 * 
	 * @param enUU
	 * @param status
	 * @return
	 */
	@Query("from PurchaseOrderReply r where r.orderItem.order.enUU = :enUU and r.status = :status")
	public List<PurchaseOrderReply> findByEnUUAndStatus(@Param("enUU") long enUU, @Param("status") short status);

	/**
	 * (卖家)按回复记录的状态查找回复记录
	 * 
	 * @param vendUU
	 * @param status
	 * @return
	 */
	@Query("from PurchaseOrderReply r where r.orderItem.order.vendUU = :vendUU and r.sendStatus = :status")
	public List<PurchaseOrderReply> findByVendUUAndSendStatus(@Param("vendUU") long vendUU, @Param("status") short status);
}
