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

@Repository
public interface MakeOrderChangeItemDao extends JpaSpecificationExecutor<MakeOrderChangeItem>,
		JpaRepository<MakeOrderChangeItem, Long> {
	
	public List<MakeOrderChangeItem> findByOrderChangeEnUUAndStatusAndReplySendStatus(Long enUU, 
			Short status, Short replySendStatus);
	
	public List<MakeOrderChangeItem> findByVendUUAndSendStatus(Long vendUU, Short sendStatus);

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

	@Query("select count(p), p.status from MakeOrderChangeItem p where p.id in (select u.sourceId from UserOrders u where u.table='make$changeitems' and u.category=:category and u.enUU=:enUU and u.userUU=:userUU and u.readStatus=0) group by p.status")
	public List<Object[]> getUnreadCountEveryStatus(@Param("enUU") Long enUU, @Param("userUU") Long userUU, @Param("category") String category);

}
