package com.guo.learningprogresstracker.service.impl; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.guo.learningprogresstracker.entity.UserEntity; import com.guo.learningprogresstracker.exception.AppException; import com.guo.learningprogresstracker.service.UserService; import com.guo.learningprogresstracker.mapper.UserMapper; import lombok.RequiredArgsConstructor; import org.mindrot.jbcrypt.BCrypt; import org.springframework.stereotype.Service; /** * @author guo * @description 针对表【user(用户信息表)】的数据库操作Service实现 * @createDate 2024-06-09 15:28:48 */ @Service @RequiredArgsConstructor public class UserServiceImpl extends ServiceImpl implements UserService{ @Override public String authenticate(String username, String password) throws AppException { UserEntity userEntity = this.getOneOpt(Wrappers.lambdaQuery() .eq(UserEntity::getUserName, username)) .orElseThrow(() -> new AppException("账号或密码错误!")); if (!BCrypt.checkpw(password, userEntity.getUserPassword())) { throw new AppException("账号或密码错误!"); } return userEntity.getId(); } }