package com.cirle.scientific.dao;


import com.cirle.scientific.po.QkjArticle;
import com.cirle.scientific.po.QkjBrandProduct;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface QkjArticleDao extends PagingAndSortingRepository<QkjArticle, Long>, JpaSpecificationExecutor<QkjArticle> {

    @Query(value = "SELECT a.* FROM qkj_article a WHERE a.status=1 and m_or_pc in (?3) order by a.publish_time desc limit ?1, ?2",nativeQuery = true)
    List<QkjArticle> findList(Integer start, Integer size,Integer[] mOrPc);

    @Query(value = "SELECT a.* FROM qkj_article a WHERE a.status=1 and m_or_pc in (?3) order by a.click desc limit ?1, ?2",nativeQuery = true)
    List<QkjArticle> findListByHottest(Integer start, Integer size,Integer[] mOrPc);

    @Query(value = "SELECT a.* FROM qkj_catalogs_detail d " +
                        "INNER JOIN qkj_article a on d.obj_id=a.id " +
                    "WHERE d.catalogs_id=?1 and d.obj_type=4 and a.status=1 and m_or_pc in (?4) order by a.publish_time desc limit ?2, ?3",nativeQuery = true)
    List<QkjArticle> findByCataId(Integer cataId, Integer start, Integer size,Integer[] mOrPc);

    @Query(value = "SELECT a.* FROM qkj_catalogs_detail d " +
            "INNER JOIN qkj_article a on d.obj_id=a.id " +
            "WHERE d.catalogs_id=?1 and d.obj_type=4 and a.status=1 and m_or_pc in (?4) order by a.click desc limit ?2, ?3",nativeQuery = true)
    List<QkjArticle> ByCataIdHottest(Integer cataId, Integer start, Integer size,Integer[] mOrPc);
}
