Ai-interviewer-system/src/main/java/com/yzdx/AiInterviewer/service/impl/UserServiceImpl.java

77 lines
2.3 KiB
Java
Raw Normal View History

2023-10-18 09:01:50 +00:00
package com.yzdx.AiInterviewer.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzdx.AiInterviewer.comment.R;
import com.yzdx.AiInterviewer.entity.Company;
import com.yzdx.AiInterviewer.entity.User;
import com.yzdx.AiInterviewer.mapper.CompanyMapper;
import com.yzdx.AiInterviewer.mapper.UserMapper;
import com.yzdx.AiInterviewer.service.UserService;
import com.yzdx.AiInterviewer.utiles.JWT;
import com.yzdx.AiInterviewer.utiles.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private CompanyMapper companyMapper;
@Override
public R adminLogin(String phone, String encoding, String password) {
LambdaQueryWrapper<User> queryWrapper=new LambdaQueryWrapper();
queryWrapper.eq(User::getPhone,phone);
User user = userMapper.selectOne(queryWrapper);
//若查询用户为空
if(user==null){
return R.error("账号不存在,请检查输入");
}
if (user.getRole().equals("3") || user.getRole().equals("4")) {
return R.error("输入的账号或密码错误");
}
//查询的用户存在,检查密码是否正确
String salt=user.getSalt();
String findPassword=user.getPassword();
password= MD5Util.GetMD5Password(password,salt);
if(!findPassword.equals(password)){
return R.error("输入的账号或密码错误");
}
//密码和账户都输入正确,检查公司编码是否正确
LambdaQueryWrapper<Company> queryWrapper1=new LambdaQueryWrapper();
queryWrapper1.eq(Company::getEncoding,encoding);
Company findCompany= companyMapper.selectOne(queryWrapper1);
if(findCompany==null){
return R.error("输入的公司编码有误,请检查输入");
}
//均正确返回token密钥
String token=JWT.getJWToken(user.getId());
Map<String,Object> data=new HashMap<>();
data.put("token",token);
return R.success(data);
}
}