package com.ywt.mg.domain.entities;

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

import java.util.List;

/**
 * Created by huangguoping.
 */
public interface UserRepository extends JpaRepository<User, Integer> {

    /**
     * 判断手机号是否存在
     * @param mobile
     * @return 数量
     */
    @Query(value = "Select count(1) From user Where mobile = ? and is_deleted = 0 limit 1;", nativeQuery = true)
    public int checkUserByMobile(String mobile);

    /**
     * 判断手机号是否存在
     * @param mobile
     *@return {@link  List< User >}
     */
    @Query(value = "Select * From user Where mobile = ? and is_deleted = 0 limit 1;", nativeQuery = true)
    public List<User> getUserByMobile(String mobile);

    /**
     * 根据手机号得到用户信息
     * @param mobile
     *@return {@link User}
     */
    @Query(value = "Select * from user Where mobile = ? and is_deleted = 0 limit 1;", nativeQuery = true)
    public User findUserByMobile(String mobile);


    /**
     * 根据用户ID得到用户信息
     * @param userId
     * @return {@link User}
     */
    @Query(value = "Select * from user Where id = ? and is_deleted = 0 limit 1;", nativeQuery = true)
    public User findUserById(int userId);


    @Query(value = "Select * From user Where real_name = ? and is_deleted = 0;", nativeQuery = true)
    List<User> getUserListByName(String trim);


    @Query(value = "Select * From user Where mobile = ? and is_deleted = 0;", nativeQuery = true)
    public List<User> getAllUserByMobile(String mobile);


    @Query(value = "Select * From user Where real_name = ? and mobile = ? and is_deleted = 0;", nativeQuery = true)
    public List<User> getAllUserByNameAndMobile(String realName, String mobile);
}
