package com.uas.platform.b2b.dao;

import com.uas.platform.b2b.model.Enterprise;
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.jpa.repository.QueryHints;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.QueryHint;
import java.util.List;

@Repository
public interface EnterpriseDao extends JpaSpecificationExecutor<Enterprise>,JpaRepository<Enterprise, Long> {

	public Enterprise findEnterpriseByEnBussinessCode(String enBussinessCode);

	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
	public Enterprise findEnterpriseByUu(Long uu);

	/**
	 * 按名称查找企业
	 * 
	 * @param name
	 * @return
	 */
	@Query("from Enterprise e where e.enName LIKE :name%")
	public List<Enterprise> findByEnName(@Param("name") String name);
	
	/**
	 * 企业资料初始化
	 * 
	 * @param enUU
	 */
	@Procedure(procedureName = "init_en")
	public void callInitProcedure(Long enUU);
	
	/**
	 * 按企业名称精确查询企业信息
	 *
	 * @param name 企业名称
	 * @return
	 */
	@Query("from Enterprise e where e.enName = :name")
	List<Enterprise> findByName(@Param("name") String name);
}
