package com.ecep.contract.ds.company.repository;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import com.ecep.contract.model.Company;

@Repository
public interface CompanyRepository extends
        // JDBC interfaces
        CrudRepository<Company, Integer>, PagingAndSortingRepository<Company, Integer>,
        // JPA interfaces
        JpaRepository<Company, Integer>, JpaSpecificationExecutor<Company> {

    List<Company> findAllByName(String name);

    Optional<Company> findFirstByName(String name);

    List<Company> findAllByShortName(String shortName);

    /**
     * @param uniscid 统一社会信用代码
     */
    List<Company> findAllByUniscid(String uniscid);

    @Query("select u from Company u")
    Stream<Company> findAllAsStream();
}
