源码获取:俺的博客首页 "资源" 里下载!
项目介绍
springboot师生健康信息管理系统
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7/8.0版本均可;
5.是否Maven项目:是;
技术栈
后端:SpringBoot+Mybaits
前端:Vue + elementui
使用说明
项目运行:
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入地址:
前台地址:http://localhost:8080/springbootrpj39/front/index.html
后台地址
http://localhost:8080/springbootrpj39/admin/dist/index.html
管理员 abo 密码 abo
用户:用户1 密码: 123456
注意项目文件路径中不能含有中文、空格、特殊字符等,否则图片会上传不成功。
医生管理控制层:
/**
*
* @author:yy
*/
package vip.penint.dandp.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vip.penint.dandp.entity.User;
import vip.penint.dandp.service.IUserService;
import vip.penint.dandp.utils.MD5Util;
import vip.penint.dandp.utils.QueryRequest;
import vip.penint.dandp.utils.ResultVo;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
@RestController
@RequestMapping("/adminApi/doctor")
public class DoctorController {
@Autowired
private IUserService userService;
@GetMapping("/list")
public ResultVo list(QueryRequest queryRequest, User user) {
return ResultVo.oK(userService.queryDoctorFuzz(queryRequest, user));
}
/**
* 修改账户状态,禁用或者取消
*
* @param user
* @param request
* @return
*/
@PutMapping("/changeStatus")
public ResultVo changeStatus(@RequestBody User user, HttpServletRequest request) {
userService.updateById(user);
return ResultVo.oK();
}
/**
* 根据ID查询用户详情
*
* @param userId
* @return
*/
@GetMapping("/{userId}")
public ResultVo getUserInfo(@PathVariable Integer userId) {
User info = userService.getById(userId);
return ResultVo.oK(info);
}
/**
* 新增用户
*/
@PostMapping
public ResultVo add(@RequestBody User user) {
// 查询用户名是否存在数据库中
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(User::getUsername, user.getUsername());
User entity = userService.getOne(lambdaQueryWrapper);
if (entity == null) {
user.setCreateTime(new Date());
// 设置默认密码1234qwer
user.setPassword(MD5Util.md5("1234qwer"));
user.setRoleId(1);
userService.save(user);
return ResultVo.oK("用户:" + user.getUsername() + "新增成功,默认密码为:" + "1234qwer");
} else {
return ResultVo.failed(201, "用户新增失败,用户名:" + user.getUsername() + "已存在");
}
}
/**
* 删除用户
*/
@DeleteMapping("/{userIds}")
public ResultVo remove(@PathVariable Integer[] userIds) {
for (Integer userId : userIds) {
userService.removeById(userId);
return ResultVo.oK();
}
return null;
}
/**
* 修改用户
*
* @return
*/
@PutMapping
public ResultVo edit(@RequestBody User user) {
user.setModifyTime(new Date());
userService.updateById(user);
return ResultVo.oK();
}
/**
* 重置密码
*/
@PutMapping("/resetPwd")
public ResultVo reSetPwd(@RequestBody User user) {
user.setPassword(MD5Util.md5(user.getPassword()));
userService.updateById(user);
return ResultVo.oK();
}
}
登录用户控制层:
/**
*
* @author: yy
*/
@RestController
@RequestMapping("/adminApi/common")
public class CommonController {
@Autowired
private IUserService userService;
@Autowired
private IDepartmentService departmentService;
@PostMapping("/login")
public Object adminLogin(String username, String password) {
User user = userService.selectByUsername(username);
if (user == null) {
return ResultVo.failed(201, "账号不存在,请检查账号是否正确或联系管理员");
} else {
if (!MD5Util.md5(password).equals(user.getPassword())) {
return ResultVo.failed(201, "密码错误");
} else {
JSONObject obj = new JSONObject();
obj.put("userInfo", user);
obj.put("token", TokenUtil.getAdminToken(user));
return ResultVo.oK(obj);
}
}
}
@ApiOperation("根据Token获取用户信息")
@GetMapping("/getUserInfo")
@AdminLoginToken
public Object getUserInfo(HttpServletRequest request) {
User user = userService.getById(TokenUtil.getAdminUserId(request.getHeader("Authorization")));
if (user == null) {
return ResultVo.failed(201, "账号不存在,请检查账号是否正确或联系管理员");
} else {
JSONObject obj = new JSONObject();
obj.put("userInfo", user);
obj.put("token", TokenUtil.getAdminToken(user));
return ResultVo.oK(obj);
}
}
@ApiOperation("退出登录")
@GetMapping("/outLogin")
public Object outLogin() {
return ResultVo.oK();
}
@ApiOperation("文件上传")
@PostMapping("/file")
public ResultVo uploadFile(@RequestParam("file") MultipartFile file) {
String uploadUrl = FileUpload.uploadAccessory(file);
if (uploadUrl != null && uploadUrl != "") {
return ResultVo.oK(uploadUrl);
}
return ResultVo.failed(500, "失败");
}
@PostMapping("/getMeInfo")
@AdminLoginToken
public ResultVo getMeInfo(HttpServletRequest request) {
User user = userService.getById(TokenUtil.getAdminUserId(request.getHeader("Authorization")));
return ResultVo.oK(user);
}
/**
* 判断库中用户名 有没有被使用
*
* @param username
* @return
*/
@GetMapping("/checkUsername/{username}")
public ResultVo checkUsername(@PathVariable String username) {
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(User::getUsername, username);
if (userService.getOne(lambdaQueryWrapper) != null) {
return ResultVo.oK(true);
} else {
return ResultVo.oK(false);
}
}
/**
* 判断请求方法的该用户原密码是否正确
*
* @param password
* @return
*/
@GetMapping("/checkPassword/{password}")
public ResultVo checkPassword(@PathVariable String password, HttpServletRequest request) {
Integer userId = TokenUtil.getAdminUserId(request.getHeader("Authorization"));
String encrypt = MD5Util.md5(password);// 用户输入的密码加密字符串
if (userService.getById(userId).getPassword().equalsIgnoreCase(encrypt)) {
return ResultVo.oK(true);
} else {
return ResultVo.oK(false);
}
}
/**
* 获取科室下拉框
*/
@GetMapping("/getDepartment")
public ResultVo getDepartment() {
LambdaQueryWrapper<Department> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(Department::getId, Department::getDepName);
return ResultVo.oK(departmentService.list(lambdaQueryWrapper));
}
/**
* 通过科室id查询医生
*/
@GetMapping("/getDoctor/{id}")
public ResultVo getDoctor(@PathVariable Integer id) {
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.select(User::getNickName, User::getUserId);
lambdaQueryWrapper.eq(User::getDepId, id);
return ResultVo.oK(userService.list(lambdaQueryWrapper));
}
@PostMapping("/registerDoctor")
public ResultVo registerStudent(User user) {
user.setPassword(MD5Util.md5(user.getPassword()));
user.setCreateTime(new Date());
user.setRoleId(1);
userService.save(user);
return ResultVo.oK();
}
@PostMapping("/registerPatients")
public ResultVo registerTeacher(User user) {
user.setPassword(MD5Util.md5(user.getPassword()));
user.setCreateTime(new Date());
user.setRoleId(2);
userService.save(user);
return ResultVo.oK();
}
/**
* 忘记密码
*/
@PutMapping("/forgotPassword")
public ResultVo forgotPassword(User sysUser) {
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(!StringUtils.isEmpty(sysUser.getUsername()), User::getUsername, sysUser.getUsername());
// 先判断用户名在不在库中
User user = userService.getOne(lambdaQueryWrapper);
if (user != null) {
sysUser.setPassword(MD5Util.md5(sysUser.getPassword()));
sysUser.setUserId(user.getUserId());
userService.updateById(sysUser);
return ResultVo.oK();
} else {
return ResultVo.failed(201, "请输入正确的用户名");
}
}
/**
* 通过用户名查询医生详情,科室
*/
@GetMapping("/getDoctorInfoByUsername/{username}")
public ResultVo getDoctorInfoByUsername(@PathVariable String username){
return ResultVo.oK(userService.getDoctorInfoByUsername(username));
}
}
用户管理控制层:
/**
* <p>
* 系统用户 前端控制器
* </p>
*
* @author yy
*/
@RestController
@RequestMapping("/adminApi/user")
public class UserController {
@Autowired
private IUserService userService;
@GetMapping("/list")
public ResultVo list(QueryRequest queryRequest, User user) {
return ResultVo.oK(userService.queryFuzz(queryRequest, user));
}
/**
* 修改账户状态,禁用或者取消
*
* @param user
* @return
*/
@PutMapping("/changeStatus")
public ResultVo changeStatus(@RequestBody User user) {
userService.updateById(user);
return ResultVo.oK();
}
/**
* 根据ID查询用户详情
*
* @param userId
* @return
*/
@GetMapping("/{userId}")
public ResultVo getUserInfo(@PathVariable Integer userId) {
User info = userService.getById(userId);
return ResultVo.oK(info);
}
/**
* 新增用户
*/
@PostMapping
public ResultVo add(@RequestBody User entity) {
// 查询用户名是否存在数据库中
LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(User::getUsername, entity.getUsername());
User user = userService.getOne(lambdaQueryWrapper);
if (user == null) {
entity.setCreateTime(new Date());
// 设置默认密码1234qwer
entity.setPassword(MD5Util.md5("1234qwer"));
entity.setRoleId(0);
userService.save(entity);
// 插入返回ID
return ResultVo.oK("用户:" + entity.getUsername() + "新增成功,默认密码为:1234qwer");
} else {
return ResultVo.failed(201, "用户新增失败,用户名:" + entity.getUsername() + "已存在");
}
}
/**
* 删除用户
*/
@DeleteMapping("/{userIds}")
public ResultVo remove(@PathVariable Integer[] userIds) {
boolean flag = false;
for (Integer userId : userIds) {
User entity = userService.getById(userId);
if (!entity.getUsername().equals("admin")) {
userService.removeById(userId);
} else {
flag = true;
}
}
if (flag) {
return ResultVo.failed(201, "admin用户不能删除");
} else {
return ResultVo.oK();
}
}
/**
* 修改用户
*/
@PutMapping
public ResultVo edit(@RequestBody User user) {
userService.updateById(user);
return ResultVo.oK();
}
/**
* 重置密码
*/
@PutMapping("/resetPwd")
public ResultVo reSetPwd(@RequestBody User user) {
user.setPassword(MD5Util.md5(user.getPassword()));
userService.updateById(user);
return ResultVo.oK();
}
/**
* 个人中心配置
*/
@GetMapping("/profile")
public ResultVo profile(HttpServletRequest request) {
Integer userId = TokenUtil.getAdminUserId(request.getHeader("Authorization"));
return ResultVo.oK(userService.getById(userId));
}
/**
* 个人中心配置
*/
@PutMapping("/profile")
public ResultVo updateProfile(@RequestBody User user) {
userService.updateById(user);
return ResultVo.oK();
}
@PutMapping("/profile/updatePwd")
public ResultVo profileUpdatePwd(QueryRequest queryRequest, HttpServletRequest request) {
Integer userId = TokenUtil.getAdminUserId(request.getHeader("Authorization"));
User user = userService.getById(userId);
if (user.getPassword().equalsIgnoreCase(MD5Util.md5(queryRequest.getOldPassword()))) {
User u = new User();
u.setUserId(userId);
u.setPassword(MD5Util.md5(queryRequest.getNewPassword()));
userService.updateById(u);
return ResultVo.oK();
} else {
return ResultVo.failed(201, "原密码不正确");
}
}
@PostMapping("/profile/avatar")
public ResultVo avatarUpload(@RequestParam("avatarfile") MultipartFile file, HttpServletRequest request) {
Integer userId = TokenUtil.getAdminUserId(request.getHeader("Authorization"));
JSONObject result = UploadFileUtils.upload(file);
if (result.getInteger("status") == 200) {
if (result.getBoolean("isImage")) {
User user = new User();
user.setAvatar(result.getString("requestUrl"));
user.setUserId(userId);
userService.updateById(user);
// 缓存
return ResultVo.oK(result.getString("requestUrl"));
} else {
return ResultVo.failed(201, "不是图片文件");
}
} else {
return ResultVo.failed(201, "文件上传失败,请联系管理员");
}
}
}
标签:Vue,return,elementui,ResultVo,user,userService,java,public,User From: https://blog.csdn.net/m0_66863468/article/details/144922584源码获取:俺的博客首页 "资源" 里下载!