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 DrugProviderRepository extends JpaRepository<DrugProvider, Integer> {

    /**
     * 通过经销商ID得到下级经销商数量
     * @param parentId
     * @return
     */
    @Query(value = "select count(1) from drug_provider where parent_id = ? and status = 0 and deleted = 0;",nativeQuery = true)
    int getLastDrugProviderByParentId(int parentId);

    @Query(value = "select * from drug_provider where parent_id = ? and status = 0 and deleted = 0;",nativeQuery = true)
    List<DrugProvider> getSubordinateList(int parentId);
}
