Ai-interviewer-system/src/main/java/com/yzdx/AiInterviewer/controller/UserController.java

248 lines
8.2 KiB
Java
Raw Normal View History

2023-10-18 09:01:50 +00:00
package com.yzdx.AiInterviewer.controller;
import com.yzdx.AiInterviewer.comment.R;
2023-10-19 13:40:26 +00:00
import com.yzdx.AiInterviewer.entity.User;
2023-10-18 09:01:50 +00:00
import com.yzdx.AiInterviewer.service.UserService;
2023-10-19 13:40:26 +00:00
import com.yzdx.AiInterviewer.utiles.JWT;
2023-11-23 14:28:01 +00:00
import io.swagger.annotations.*;
2023-10-18 09:01:50 +00:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
2023-11-04 16:30:50 +00:00
import java.util.List;
2023-10-18 09:01:50 +00:00
import java.util.Map;
@RestController
@RequestMapping("/admin")
public class UserController {
@Autowired
private UserService userService;
2023-11-18 07:47:31 +00:00
/**
* 用户登录
* @param loginForm 用户输入的账号密码公司编码
* @return R
* */
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "管理员登录",notes = "")
2023-10-22 01:10:10 +00:00
@PostMapping("/login")
2023-11-23 14:28:01 +00:00
public R adminLogin(@RequestBody @ApiParam("传入的值:loginForm:{" +
"(String)phone," +
"(String)encoding," +
"(String)password}") Map<String,Object> loginForm){
2023-10-18 09:01:50 +00:00
if(loginForm.size()==0){
return R.error("传来的数据有误,请检查输入");
}
String phone=(String)loginForm.get("phone");
String encoding=(String)loginForm.get("encoding");
String password=(String)loginForm.get("password");
return userService.adminLogin(phone, encoding, password);
}
2023-11-18 07:47:31 +00:00
/**
* 用户信息
* @param token 用户登录时返回的token
* @return R
*/
@GetMapping("/get_userInfo")
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "获取用户信息",notes = "")
2023-11-18 07:47:31 +00:00
public R getUserInfo( @ApiParam("传入的值:(String)token值") String token) {
2023-10-19 13:40:26 +00:00
if(token==null){
return R.error(401,"非法访问,请重新登陆!");
}
Integer userId = JWT.getTokenId(token);
2023-10-19 13:40:26 +00:00
User findUser = userService.getUserById(userId);
if (findUser == null) {
return R.error(401, "非法访问,请重新登陆");
}
User user=new User();
user.setId(findUser.getId());
user.setUsername(findUser.getUsername());
user.setRole(findUser.getRole());
user.setPhone(findUser.getPhone());
user.setSex(findUser.getSex());
user.setAge(findUser.getAge());
user.setAvatar(findUser.getAvatar());
user.setEmail(findUser.getEmail());
user.setCreateTime(findUser.getCreateTime());
user.setUpdateTime(findUser.getUpdateTime());
return R.success(user);
2023-10-19 13:40:26 +00:00
}
2023-11-18 07:47:31 +00:00
/**
* 用户注销
* @param token 用户登录时返回的token
* @return R
*/
2023-10-23 12:55:51 +00:00
@GetMapping("/logout")
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "管理员登出",notes = "")
2023-11-18 07:47:31 +00:00
public R adminLogout(@ApiParam("传入的值:(String)token值") String token){
2023-10-23 12:55:51 +00:00
Integer row = userService.adminLogout(token);
if(row==0){
return R.error("登出失败,请联系管理员!");
}
return R.success("退出成功!");
}
2023-10-18 09:01:50 +00:00
2023-11-18 07:47:31 +00:00
/**
* 获取管理员列表
* @param encoding 公司编码
* @return R
*/
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "根据公司编码获取管理员列表",notes = "")
2023-11-04 16:30:50 +00:00
@GetMapping("/get_adminList")
2023-11-18 07:47:31 +00:00
public R getAdminList(@ApiParam("传入的值:(String)encoding") String encoding){
2023-11-04 16:30:50 +00:00
List<User> adminList = userService.getAdminList(encoding);
return R.success(adminList);
}
2023-11-18 07:47:31 +00:00
/**
* 搜索管理员
* @param name 管理员的姓名
* @param encoding 公司编码
* @return R
*/
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "根据名字搜索管理员",notes = "")
2023-11-12 06:00:40 +00:00
@GetMapping("/search_admin")
2023-11-18 07:47:31 +00:00
public R searchAdmin(@ApiParam("传入的值:(String)name,(String)encoding") String name,String encoding){
2023-11-12 06:00:40 +00:00
if(name==null&&encoding==null){
return R.error("查询失败");
}
List<User> users = userService.searchAdmin(name, encoding);
return R.success(users);
}
2023-11-18 07:47:31 +00:00
/**
* 添加管理员
* @param addAdminInfo 添加人的公司编码操作人的id,添加入的姓名添加入的手机号/账号添加人的权限
* @return R
*/
2023-11-04 16:30:50 +00:00
@PostMapping("/add_admin")
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "添加管理员",notes = "")
2023-11-18 07:47:31 +00:00
public R addAdmin(@RequestBody @ApiParam("传入的值 addAdminInfo:{(String)encoding,(Integer)userId,(String)username,(String)phone,(String)role}") Map<String ,Object> addAdminInfo){
2023-11-04 16:30:50 +00:00
String encoding=(String) addAdminInfo.get("encoding");
Integer userId=(Integer) addAdminInfo.get("userId");
String username=(String)addAdminInfo.get("username");
String phone=(String)addAdminInfo.get("phone");
String role=(String)addAdminInfo.get("role");
Integer rows = userService.addAdmin(encoding, userId, username, phone, role);
if(rows==-2){
return R.error("添加人的账号存在,请检查输入!");
}
if(rows==0){
return R.error("添加失败,请联系管理员!");
}
return R.success("添加管理员成功!");
}
2023-11-18 07:47:31 +00:00
/**
* 更新管理员信息
2023-11-20 02:38:07 +00:00
* @param userId 操作人的id
* @param deleteId 删除人的id
2023-11-18 07:47:31 +00:00
* @return R
*/
2023-11-20 02:38:07 +00:00
@DeleteMapping("/del_admin")
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "删除管理员",notes = "")
2023-11-20 02:38:07 +00:00
public R deleteAdmin(@ApiParam("传入的值 (Integer)userId,(Integer)deleteId")Integer deleteId,Integer userId){
2023-11-04 16:30:50 +00:00
Integer rows = userService.deleteAdmin(deleteId, userId);
if(rows==-3){
return R.error("禁止删除本次登陆账号!");
}
if(rows==-2){
return R.error("权限不足!");
}
if(rows==0){
return R.error("删除失败!");
}
return R.success("删除成功!");
}
2023-11-18 07:47:31 +00:00
/**
* 更换头像
* @param updateInfo 更改人的id更改人头像的地址
* @return R
*/
2023-11-04 16:30:50 +00:00
@PostMapping("/change_avatar")
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "根据ID修改头像",notes = "")
2023-11-18 07:47:31 +00:00
public R changeAvatar(@RequestBody @ApiParam("传入的值为updateInfo:(Integer)userId,(String)avatar") Map<String,Object> updateInfo){
2023-11-04 16:30:50 +00:00
Integer userId=(Integer) updateInfo.get("userId") ;
String avatar=(String)updateInfo.get("avatar") ;
User user = userService.changeAvatar(userId, avatar);
if(user==null){
return R.error("更新失败!");
}
return R.success(user);
}
2023-11-18 07:47:31 +00:00
/**
* 更新密码
* @param updateInfo 更新人的Id,新密码旧密码
* @return R
*/
2023-11-04 16:30:50 +00:00
@PostMapping("/reset_password")
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "根据id更改密码",notes = "")
2023-11-18 07:47:31 +00:00
public R resetPassword(@RequestBody @ApiParam("传入的值为updateInfo:(Integer)userId,(String)oldPassword,(String)password") Map<String,Object> updateInfo){
2023-11-04 16:30:50 +00:00
Integer userId=(Integer)updateInfo.get("userId") ;
String oldPassword=(String)updateInfo.get("oldPassword");
String password=(String)updateInfo.get("Password") ;
String resetPassword=(String)updateInfo.get("resetPassword");
if(!password.equals(resetPassword)){
return R.error("两次输入的密码不一致!");
}
return userService.resetPassword(userId,oldPassword,password);
}
2023-11-16 13:22:51 +00:00
2023-11-18 07:47:31 +00:00
/**
* 更新用户信息
* @param updateInfo 操作人的id更新人的id修改的名称修改的年龄修改的电子邮箱修改的性别
* @return R
*/
2023-11-16 13:22:51 +00:00
@PostMapping("/upload_userInfo")
2023-11-23 14:28:01 +00:00
@ApiOperation(value = "根据ID更新用户信息",notes = "")
2023-11-18 07:47:31 +00:00
public R updateUserInfo(@RequestBody @ApiParam("传入的值为updateInfo:(Integer)userId,(Integer)updateId,(String)username,(String)age,(String)email,(String)sex") Map<String,Object> updateInfo){
2023-11-16 13:22:51 +00:00
Integer userId=(Integer) updateInfo.get("userId");
Integer updateId=(Integer) updateInfo.get("updateId");
String username=(String) updateInfo.get("username");
String age=(String) updateInfo.get("age");
String email=(String) updateInfo.get("email");
String sex=(String) updateInfo.get("sex");
if(updateId==userId||userId==null||userId.equals("")){
userId=null;
User user = userService.updateUserInfo(userId, updateId, username, age, email, sex);
return R.success(user);
}else{
User user = userService.updateUserInfo(userId, updateId, username, age, email, sex);
return R.success(user);
}
}
2023-10-18 09:01:50 +00:00
}