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

@Repository
public interface SaleARCheckItemDao extends JpaSpecificationExecutor<SaleARCheckItem>,
		JpaRepository<SaleARCheckItem, Long> {

	/**
	 * 查找对账单主表对账已同意的数量
	 * 
	 * @param checkId
	 * @return
	 */
	@Query("select count(i) from SaleARCheckItem i where i.arCheck.id = :checkId and i.agreed = 1")
	public int findAgreedCountBycheckId(@Param("checkId") Long checkId);
	
	/**
	 * 查找对账单主表对账不同意的数量
	 * 
	 * @param checkId
	 * @return
	 */
	@Query("select count(i) from SaleARCheckItem i where i.arCheck.id = :checkId and i.agreed = 0")
	public int findDisAgreedCountBycheckId(@Param("checkId") Long checkId);
	
	/**
	 * 根据供应商UU号和明细来源ID获取明细
	 * @param vendUU
	 * @param sourceId
	 * @return
	 */
	@Query("select i from SaleARCheckItem i where i.arCheck.vendUU = :vendUU and i.sourceId = :sourceId")
	public List<SaleARCheckItem> findByArCheckVendUUAndSourceId(@Param("vendUU") Long vendUU, @Param("sourceId") Long sourceId);
}
