package com.uas.platform.b2b.dao;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.uas.platform.b2b.model.PurchaseOrderAll;

import javax.transaction.Transactional;

@Repository
public interface PurchaseOrderAllDao extends JpaSpecificationExecutor<PurchaseOrderAll>, JpaRepository<PurchaseOrderAll, Long> {

	/**
	 * @param vendUU
	 *            卖方企业ID
	 * @param code
	 *            订单号
	 * @return
	 */
	public List<PurchaseOrderAll> findByVendUUAndCode(long vendUU, String code);

	/**
	 * @param id
	 *            订单ID
	 * @return
	 */
	public List<PurchaseOrderAll> findById(Long id);

	/**
	 * 卖家按上传状态查找订单
	 * 
	 * @param vendUU
	 *            卖方企业ID
	 * @param status
	 *            状态
	 * @return
	 */
	@Query("from PurchaseOrderAll where vendUU = :vendUU and sendStatus = :sendStatus and status <> 311")
	public List<PurchaseOrderAll> findByVendUUAndSendStatus(@Param("vendUU") long vendUU, @Param("sendStatus") short sendStatus);

	/**
	 * 根据供应商UU号获取客户采购订单数量
	 * @param vendUU
	 * @return
	 */
	@Query("select count(p) from PurchaseOrderAll p where p.vendUU = :vendUU")
	public long countByVendUU(@Param("vendUU")Long vendUU);

	/**
	 * 查询订单之前先设置状态，将未读的订单放在最上面
	 * 
	 * @param useruu
	 * @param enuu
	 * @param orderkind
	 */
	@Procedure(procedureName = "orders_set_status_beforeread")
	public void setDisplayStatus(Long useruu, Long enuu, String orderkind);

}
