package com.ywt.outpatient.domain.entity.center;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * create by daiyihua
 */
public interface ArticlesRepository extends JpaRepository<Articles, Integer> {

    /**
     * 根据药商ID统计文章数
     * @param id
     * @return
     */
    @Query(value = "select count(1) from articles where provider_id = ? and deleted = 0 ", nativeQuery = true)
    int getTitleAmountByProviderId(int id);

    @Query(value = "select * from articles where provider_id = ? and deleted = 0 order by update_time desc", nativeQuery = true)
    List<Articles> getArticlesByProviderId(int providerId);

    @Query(value = "select * from articles where id = ? and deleted = 0 limit 1", nativeQuery = true)
    Articles getById(int id);

    @Query(value = "select * from articles where id = ? and deleted = 0 and audit_status > 1 limit 1", nativeQuery = true)
    Articles getAuditPassedById(int id);
}
