2026-01-15 10:53:54 +08:00
|
|
|
package com.backend.webbackend.Controller;
|
|
|
|
|
|
|
|
|
|
import com.backend.webbackend.Service.userService;
|
|
|
|
|
import com.backend.webbackend.Tools.Tools;
|
|
|
|
|
import com.backend.webbackend.Vo.ResultVo;
|
|
|
|
|
import com.backend.webbackend.domain.User;
|
|
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("user")
|
|
|
|
|
public class userController {
|
|
|
|
|
@Autowired
|
|
|
|
|
userService userService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private Tools tools;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//返回所有部门信息:用于用户注册时选择部门
|
|
|
|
|
@GetMapping("dept")
|
|
|
|
|
public ResultVo getAllDept(){
|
|
|
|
|
return ResultVo.Success("",userService.getAlldept());
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-20 14:24:29 +08:00
|
|
|
//返回全部用户信息
|
|
|
|
|
@GetMapping("allUsers")
|
|
|
|
|
public ResultVo getAllUsers(){
|
|
|
|
|
return ResultVo.Success("",userService.getAllUsers());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-01-15 10:53:54 +08:00
|
|
|
//用户注册
|
|
|
|
|
@PostMapping("register")
|
|
|
|
|
public ResultVo register(@RequestBody User user){
|
|
|
|
|
if(userService.register(user)){
|
|
|
|
|
return ResultVo.Success("","注册成功");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return ResultVo.Error("","注册失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//用户登录
|
2026-01-20 14:24:29 +08:00
|
|
|
@PostMapping(value = "login")
|
|
|
|
|
public ResultVo login(@ModelAttribute User user) {
|
2026-01-15 10:53:54 +08:00
|
|
|
if(!userService.login(user.getUsername(),user.getPassword())){
|
|
|
|
|
return ResultVo.Error("","用户名或密码错误");
|
|
|
|
|
}
|
|
|
|
|
return ResultVo.Success("","登陆成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//用户信息修改
|
|
|
|
|
@PostMapping("update")
|
|
|
|
|
public ResultVo updateUserInfo(@RequestBody User user){
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//密码加密
|
|
|
|
|
user.setPassword(tools.encryptPassword(user.getPassword()));
|
|
|
|
|
userService.updateUserInfo(user);
|
|
|
|
|
return ResultVo.Success("","用户信息修改成功");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e){
|
2026-01-20 14:24:29 +08:00
|
|
|
System.out.println(e.getMessage());
|
2026-01-15 11:18:45 +08:00
|
|
|
throw new RuntimeException("用户信息修改失败!!!!!!");
|
2026-01-15 10:53:54 +08:00
|
|
|
}
|
2026-01-20 14:24:29 +08:00
|
|
|
}
|
2026-01-15 10:53:54 +08:00
|
|
|
|
2026-01-20 14:24:29 +08:00
|
|
|
@GetMapping("deleteUser")
|
|
|
|
|
public ResultVo deleteTest(@Param("id") Long id) {
|
|
|
|
|
if(userService.deleteUserById(id) == 1){
|
|
|
|
|
return ResultVo.Success("", "用户删除成功");
|
|
|
|
|
}else {
|
|
|
|
|
return ResultVo.Error("", "用户删除失败");
|
|
|
|
|
}
|
2026-01-15 10:53:54 +08:00
|
|
|
}
|
2026-01-20 14:24:29 +08:00
|
|
|
|
2026-01-15 10:53:54 +08:00
|
|
|
}
|