package com.cirle.scientific.dao;

import com.cirle.scientific.po.QkjTags;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface QkjTagsDao  extends PagingAndSortingRepository<QkjTags, Long>, JpaSpecificationExecutor<QkjTags> {

    @Query(value = "select qt.* from qkj_tags qt inner join qkj_tags_detail qtd on qtd.tag_id = qt.id where qtd.obj_id = ?1 and qtd.obj_type = 2 order by qtd.sqn desc limit 0,2",nativeQuery = true)
    List<QkjTags> findCourseTagsByCourseId(Long id);


    @Query(value = "select qt.* from qkj_tags qt inner join qkj_tags_detail qtd on qtd.tag_id = qt.id where qtd.obj_id = ?1 and qtd.obj_type = ?2 order by qtd.sqn desc ",nativeQuery = true)
    List<QkjTags> findTagsByObjIdAndObjType(Long objId,Integer objType);

    @Query(value = "select qt.* from qkj_tags qt inner join qkj_tags_detail qtd on qtd.tag_id = qt.id where qtd.obj_id in (?1) and qtd.obj_type = 2 order by qtd.sqn desc",nativeQuery = true)
    List<QkjTags> findAllTags(String ids);
}
