UserDAO.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package nju.seec.helper.dao;
  2. import nju.seec.helper.entity.User;
  3. import nju.seec.helper.enums.ExceptionType;
  4. import nju.seec.helper.exception.HelperException;
  5. import org.springframework.data.domain.Page;
  6. import org.springframework.data.domain.Pageable;
  7. import org.springframework.data.jpa.repository.JpaRepository;
  8. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  9. import org.springframework.stereotype.Repository;
  10. import java.util.Optional;
  11. import java.util.Set;
  12. /**
  13. * @author cst
  14. */
  15. @Repository
  16. public interface UserDAO extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
  17. /**
  18. * 封装findById
  19. *
  20. * @param id
  21. * @return
  22. */
  23. default User findUserById(Long id) {
  24. return this.findById(id)
  25. .orElseThrow(() -> HelperException.of(ExceptionType.NOT_FOUND, "找不到用户信息"));
  26. }
  27. // /**
  28. //// * 检查邮箱是否已存在
  29. //// *
  30. //// * @param email
  31. //// * @return
  32. //// */
  33. //// boolean existsByEmail(String email);
  34. ////
  35. ////
  36. //// /**
  37. //// * 检查手机号是否已存在
  38. //// *
  39. //// * @param phone
  40. //// * @return
  41. //// */
  42. //// boolean existsByPhone(String phone);
  43. ////
  44. //// /**
  45. //// * 邮箱密码匹配
  46. //// *
  47. //// * @param email
  48. //// * @param password
  49. //// * @return
  50. //// */
  51. //// Optional<User> findByEmailAndPassword(String email, String password);
  52. ////
  53. //// /**
  54. //// * 根据邮箱查询
  55. //// *
  56. //// * @param email
  57. //// * @return
  58. //// */
  59. //// Optional<User> findByEmail(String email);
  60. /**
  61. * 根据手机号查询
  62. *
  63. * @param phone
  64. * @return
  65. */
  66. Optional<User> findByPhone(String phone);
  67. /**
  68. * 根据PID查询
  69. *
  70. * @param pid
  71. * @return
  72. */
  73. Optional<User> findByPid(Long pid);
  74. /**
  75. * ID列表查询
  76. *
  77. * @param ids
  78. * @param pageable
  79. * @return
  80. */
  81. Page<User> findByIdIn(Set<Long> ids, Pageable pageable);
  82. }