package com.yihu.jw.base.dao.article;

import com.yihu.jw.entity.hospital.article.KnowledgeArticleDO;
import com.yihu.jw.entity.hospital.article.KnowledgeArticleDictDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * 健康文章DAO
 * @author huangwenjie
 * @date 2019/9/10 14:07
 */
public interface KnowledgeArticleDictDao extends PagingAndSortingRepository<KnowledgeArticleDictDO, String>, JpaSpecificationExecutor<KnowledgeArticleDictDO> {
	@Query("select a from KnowledgeArticleDictDO a where a.del=1 and (categoryFirst = ?1 or categorySecond=?1)")
	List<KnowledgeArticleDictDO> findByCategory(String category);
	@Query("select a from KnowledgeArticleDictDO a where a.del=1 and categoryFirst = ?1 ")
	List<KnowledgeArticleDictDO> findByCategoryFirst(String category);
	@Query("select a from KnowledgeArticleDictDO a where a.del=1 and  categorySecond=?1")
	List<KnowledgeArticleDictDO> findByCategorySecond(String category);




	@Query("select a from KnowledgeArticleDictDO a where a.del=1 and a.id=?1")
	KnowledgeArticleDictDO findByIdAndDel(String id);


	@Query("select count(*) from KnowledgeArticleDictDO a where a.del=1 and a.categoryFirst = ?1 and a.releaseStatus=1 ")
	Integer getCountByCategoryFirst(String category);
	@Query(" select count(*) from KnowledgeArticleDictDO a where a.del=1 and  a.categorySecond IN (?1) and a.releaseStatus=1")
	Integer getCountByCategorySecond(List<String> category);
	@Query("select a from KnowledgeArticleDictDO a where a.del=1 and  a.categorySecond IN ( ?1 ) and a.releaseStatus=1 order by  a.releaseTime desc ")
	List<KnowledgeArticleDictDO> findByCategorySecondAndPage(List<String> category,Pageable pageRequest);


}
