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.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

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

@Repository
@Transactional
public interface PurchaseInquiryDao extends JpaSpecificationExecutor<PurchaseInquiry>, JpaRepository<PurchaseInquiry, Long> {

	/**
	 * @param enUU
	 *            询价方企业ID
	 * @param code
	 *            流水号
	 * @return
	 */
	public List<PurchaseInquiry> findByEnUUAndCode(long enUU, String code);

	/**
	 * @param enUU
	 *            询价方企业ID
	 * @param sourceId
	 *            来源系统的单据ID
	 * @return
	 */
	public List<PurchaseInquiry> findByEnUUAndSourceId(long enUU, long sourceId);

	/**
	 * 按询价单来源ID更新是否提交状态
	 * 
	 */
	@Modifying(clearAutomatically = true)
	@Query("update PurchaseInquiry p set p.check = :check where p.enUU = :enUU and p.sourceId IN (:sourceIds)")
	public void updateByCheck(@Param("check") short check, @Param("enUU") long enUU, @Param("sourceIds") Long[] sourceIds);


}
