package com.uas.platform.b2b.dao;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.uas.platform.b2b.model.User;

@Repository
public interface UserDao extends JpaRepository<User, Long> {

	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
	public List<User> findUserByUserUU(Long userUU);

	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
	public List<User> findUserByUserEmail(String userEmail);

	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
	public List<User> findUserByUserTel(String userTel);

	/**
	 * 按企业ID和个人ID查找个人
	 * 
	 * @param enUU
	 * @param userUU
	 * @return
	 */
	@Query("select u from User u inner join u.enterprises as e where e.uu = :enUU and u.userUU = :userUU")
	public List<User> findByEnUUAndUserUU(@Param("enUU") long enUU, @Param("userUU") long userUU);

}
