package com.ssj.dao.sys.sort.dao;

import com.ssj.bean.sys.sort.domain.Sort;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface SortDao extends JpaRepository<Sort, String> {

	public List<Sort> findByPidOrderBySortAsc(String pid);
	/**
	 * 查询父ID下的节点 热门的
	 * @param pid
	 * @return
	 */
	public List<Sort> findByPidAndIshotOrderBySortAsc(String pid,Integer ishot);
	
	
	public List<Sort> findByCodeAndPid(String code,String pid);
	
	public Page<Sort> findAll(Specification<Sort> specification, Pageable page);
	
   @Query(nativeQuery = true, value = "update sys_sort set sort = ?2 where id =?1 ")
   @Modifying
   public void updateSequenceSort(String id,int sort);
   
   @Query(nativeQuery = true, value = "select  count(1) from sys_sort  where pid =?1 ")
   
   public Integer getSortChildrenCount(String pid);
   
   
   @Query(nativeQuery = true, value =" SELECT * FROM sys_sort  WHERE code=?1 LIMIT 1 ")
	 public Sort  getSort(String code);
}
