package com.yihu.ehr.basic.user.dao;

import com.yihu.ehr.basic.user.entity.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author Sand
 * @version 1.0
 * @created 2015.12.16 15:10
 */
public interface XUserRepository extends PagingAndSortingRepository<User, String> {

    List<User>  findByRealName(String userName);

    User findByLoginCode(String loginCode);

    List<User> findByTelephone(String telephone);

    List<User> findByIdCardNo(String idCardNo);

    @Modifying
    @Query("update User user set user.password = :password where user.id = :userId")
    void changePassWord(@Param ("userId") String userId, @Param("password") String password);


    @Query("select user from User user where user.loginCode = :loginCode or user.telephone = :loginCode or user.idCardNo = :loginCode")
    List<User> findUserForLogin(@Param("loginCode") String loginCode);

    @Query("select u.idCardNo from User u where u.id in (:userIds)")
    List<String> findIdCardNoById(@Param("userIds") List<String> userIds);

}
