package com.uas.search.console.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.search.console.model.ComponentSimpleInfo;

/**
 * @author sunyj
 * @since 2016年7月7日 下午5:59:24
 */
@Repository
public interface ComponentSimpleInfoDao
		extends JpaSpecificationExecutor<ComponentSimpleInfo>, JpaRepository<ComponentSimpleInfo, Long> {

	/**
	 * 根据id获取器件
	 * 
	 * @param id
	 * @return
	 */
	public ComponentSimpleInfo findById(Long id);

	/**
	 * 根据类目kindid获取器件
	 * 
	 * @param kindid
	 * @return
	 */
	public List<ComponentSimpleInfo> findByKindid(Long kindid);

	/**
	 * 根据品牌brandid获取器件
	 * 
	 * @param brandid
	 * @return
	 */
	public List<ComponentSimpleInfo> findByBrandid(Long brandid);

	/**
	 * 按id获取器件，并且按照给定的id的顺序
	 * 
	 * @param ids
	 * @return
	 */
	@Query("select c from ComponentSimpleInfo c where c.id in (:ids) order by instr(':ids', c.id)")
	public List<ComponentSimpleInfo> findByIdsInOrder(@Param("ids") Long[] ids);
}
