基于javaweb+mysql的springboot校园宿舍管理系统(java+springboot+vue+maven+redis+mysql)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot校园宿舍管理系统(java+springboot+vue+maven+redis+mysql)
项目介绍
这个项目是一个基于SpringBoot+Vue的校园宿舍管理系统,前后端分离。 主要有超级管理员和宿舍管理员两种角色;
超级管理员权限包括: 首页; 学生宿舍管理:宿舍管理、学生管理、班级管理、宿舍楼管理; 记录:维修记录、晚归记录、请假记录; 系统管理:用户管理、角色管理、菜单管理、日志管理等。
宿舍管理员权限包括: 首页; 学生宿舍管理:宿舍管理、学生管理、班级管理; 记录:维修记录、晚归记录、请假记录;
环境需要
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项目:是;
技术栈
1.后端:SpringBoot+Mysql+redis 2.前端:Vue
使用说明
后端项目运行: 1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application-dev.yaml配置文件中的数据库配置改为自己的配置; 4. 运行项目,控制台提示运行成功后再去运行前端项目;
前端项目运行:
- 安装好node环境 2. 在dms目录下运行 npm install 安装所需要的包 3. 在dms目录下运行 npm run dev 4. 运行成功后,在浏览器中访问http://localhost:8087,登录账号即可
}
@GetMapping("/delete")
@RequirePermission(permissions = {"system:function:delete"})
@Log("删除功能")
public Result<?> delete(@RequestParam("id") Long id) {
systemFunctionService.delete(id);
return Result.ok("删除成功");
}
@PostMapping("/saveOrUpdate")
@RequirePermission(permissions = {"system:function:save", "system:function:update"})
@Log("添加修改功能")
public Result<?> saveOrUpdate(@RequestBody @Validated SystemFunction function) {
if (function.getId() == null) {
systemFunctionService.save(function);
} else {
if (function.getId().equals(function.getParentId())) {
throw new HttpException(HttpCode.FAILED, "父节点不能为自己");
}
systemFunctionService.update(function);
}
return Result.ok("操作成功");
}
@GetMapping("/query")
@RequirePermission(permissions = {"system:function:query"})
public Result<SystemFunction> query(@RequestParam("id") Long id) {
SystemFunction function = systemFunctionService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "菜单不存在"));
return Result.<SystemFunction>ok().add(function);
}
}
@RestController
@RequestMapping("/permission")
public class PermissionController {
private final RedisUtil redisUtil;
private final SystemUserService systemUserService;
private final SystemFunctionService systemFunctionService;
private final SystemRoleService systemRoleService;
private final NoticeService noticeService;
private final DepartApplicationService departApplicationService;
private final ImageService imageService;
public PermissionController(RedisUtil redisUtil,
SystemUserService systemUserService,
SystemFunctionService systemFunctionService,
SystemRoleService systemRoleService,
NoticeService noticeService,
DepartApplicationService departApplicationService,
ImageService imageService) {
this.redisUtil = redisUtil;
this.systemUserService = systemUserService;
this.systemFunctionService = systemFunctionService;
this.systemRoleService = systemRoleService;
this.noticeService = noticeService;
this.departApplicationService = departApplicationService;
this.imageService = imageService;
}
/**
* 获取登录用户权限,头像,名称,菜单信息
*
* @param token token
* @return
*/
@GetMapping("/info")
public Result<SystemUser> info(@RequestHeader(HEADER_TOKEN) String token) {
SystemUser user = redisUtil.exchange(token).orElseThrow(() -> new HttpException(HttpCode.FAILED, "没有该用户"));
List<SystemRole> systemRoles = systemRoleService.listByUserId(user.getId());
Set<String> permissions;
if (systemRoles.size() == 0) {
permissions = new HashSet<>();
} else {
permissions = systemFunctionService.getPermission(systemRoles);
}
user.setPermissions(permissions);
List<SystemFunction> functionList = systemFunctionService.listFunctionByParentIdAndIds(null, user.getUserRoleId());
user.setFunctions(functionList);
return Result.<SystemUser>ok().add(user);
}
throw new HttpException(HttpCode.FAILED, "父节点不能为自己");
}
facultyService.update(faculty);
}
return Result.ok("操作成功");
}
@GetMapping("/delete")
@RequirePermission(permissions = {"faculty:delete"})
@Log("删除学院")
public Result<?> delete(@RequestParam("id") Long id) {
facultyService.delete(id);
return Result.ok("删除成功");
}
@GetMapping("/query")
@RequirePermission(permissions = {"faculty:query"})
public Result<Faculty> query(@RequestParam("id") Long id) {
Faculty faculty = facultyService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "没有该数据"));
return Result.<Faculty>ok().add(faculty);
}
}
/**
*/
@RestController
@RequestMapping("/repair")
public class RepairController {
@Autowired
private RepairService repairService;
@Autowired
private RedisUtil redisUtil;
@PostMapping("/saveOrUpdate")
@RequirePermission(permissions = {"repair:update", "repair:save"})
@Log
*/
@RestController
@RequestMapping("/notice")
public class NoticeController {
@Autowired
private NoticeService noticeService;
@Autowired
private BuildingService buildingService;
@Autowired
private SystemUserService systemUserService;
@Autowired
private RedisUtil redisUtil;
@RequirePermission(permissions = {"home:send:msg"})
@PostMapping("/sendToUser/{uid}")
@Log("发送消息给单个用户")
public Result<?> sendToUser(@RequestBody Notice notice,
@PathVariable("uid") Long uid,
@RequestHeader(Constant.HEADER_TOKEN) String token) {
notice.setUserId(redisUtil.get(token));
noticeService.save(notice);
noticeService.saveRelevance(uid, notice.getId());
return Result.ok("发送成功");
}
@RequirePermission(permissions = {"home:send:msg"})
@PostMapping("/sendToBuilding/{bid}")
@Log("发送消息给多个用户")
public Result<?> sendToBuilding(@RequestBody Notice notice,
@PathVariable("bid") Long bid,
@RequestHeader(Constant.HEADER_TOKEN) String token) {
notice.setUserId(redisUtil.get(token));
noticeService.save(notice);
List<Long> bids = buildingService.getIdsByParentId(bid);
List<Long> uids = systemUserService.listByBuildingIds(bids);
noticeService.saveRelevance(uids, notice.getId());
return Result.ok("发送成功");
}
@PostMapping("/list")
public Result<PageInfo<Notice>> list(@RequestHeader(Constant.HEADER_TOKEN) String token, @RequestBody ListQuery<?> listQuery) {
PageHelper.startPage(listQuery.getPage(), listQuery.getRows());
List<Notice> list = noticeService.listByUserId(redisUtil.get(token));
PageInfo<Notice> pageInfo = new PageInfo<>(list);
@PostMapping("/list")
@RequirePermission(permissions = {"back:list"})
public Result<PageInfo<BackLate>> list(@RequestBody ListQuery<BackLate> listQuery,
@RequestHeader(Constant.HEADER_TOKEN) String token) {
SystemUser systemUser = redisUtil.exchange(token).get();
PageInfo<BackLate> pageInfo = backLateService.list(listQuery, systemUser.getBuildingId());
return Result.<PageInfo<BackLate>>ok().add(pageInfo);
}
@GetMapping("/query/{id}")
@RequirePermission(permissions = {"back:query"})
public Result<BackLate> query(@PathVariable Long id) {
BackLate backLate = backLateService.query(id);
return Result.<BackLate>ok().add(backLate);
}
}
/**
*/
@RestController
@RequestMapping("/system/log")
public class SystemLogController {
@Autowired
private SystemLogService systemLogService;
@PostMapping("/list")
this.systemFunctionService = systemFunctionService;
this.systemRoleService = systemRoleService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//获取请求的方法
HandlerMethod handlerMethod;
if (handler instanceof HandlerMethod) {
handlerMethod = (HandlerMethod) handler;
} else {
//404
return true;
}
Method method = handlerMethod.getMethod();
//获取请求方法所需的权限
String[] requiredPermissions;
Match match;
if (method.isAnnotationPresent(RequirePermission.class)) {
RequirePermission hasPermission = method.getAnnotation(RequirePermission.class);
requiredPermissions = hasPermission.permissions();
match = hasPermission.matchType();
} else {
//方法不需要权限(无 RequirePermission 注解)
return true;
}
String token = request.getHeader(Constant.HEADER_TOKEN);
Long id = redisUtil.get(token);
//获取该用户的权限
List<SystemRole> roleList = systemRoleService.listByUserId(id);
Set<String> permissions;
if (roleList.size() == 0) {
permissions = new HashSet<>();
} else {
permissions = systemFunctionService.getPermission(roleList);
}
//验证权限
if (VALIDATE_MAP.get(match).validate(permissions, requiredPermissions)) {
return true;
}
//权限验证失败
@RestController
@RequestMapping("/system/role")
public class SystemRoleController {
@Autowired
private SystemRoleService systemRoleService;
@Autowired
private SystemFunctionService systemFunctionService;
@GetMapping("/listInSelect")
@RequirePermission(permissions = {"system:role:list"})
public Result<List<SystemRole>> listInSelect() {
return Result.<List<SystemRole>>ok().add(systemRoleService.listAll(new SystemRole()));
}
@PostMapping("/saveOrUpdate")
@RequirePermission(permissions = {"system:role:save", "system:role:update"})
@Log("添加修改角色")
public Result<?> saveOrUpdate(@RequestBody @Validated SystemRole role) {
systemRoleService.saveOrUpdate(role);
return Result.ok("操作成功");
}
@PostMapping("/list")
@RequirePermission(permissions = {"system:role:list"})
public Result<PageInfo<SystemRole>> list(@RequestBody ListQuery<SystemRole> query) {
PageHelper.startPage(query.getPage(), query.getRows());
List<SystemRole> list = systemRoleService.listAll(query.getEntity());
PageInfo<SystemRole> pageInfo = new PageInfo<>(list);
return Result.<PageInfo<SystemRole>>ok().add(pageInfo);
}
@GetMapping("/delete")
@RequirePermission(permissions = {"system:role:delete"})
@Log("删除角色")
public Result<?> delete(@RequestParam("id") Long id) {
systemRoleService.delete(id);
return Result.ok("操作成功");
}
@GetMapping("/query")
@RequirePermission(permissions = {"system:role:query"})
public Result<SystemRole> query(@RequestParam("id") Long id) {
SystemRole role = systemRoleService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "角色不存在"));
role.setFunctionIds(systemFunctionService.selectMenuListByRoleId(id));
return Result.<SystemRole>ok().add(role);
}
public Result<?> delete(@PathVariable("id") Long id) {
int count = studentService.countByRoomId(id);
if (count > 0) {
throw new HttpException(HttpCode.FAILED, "该宿舍还有学生, 无法删除");
}
roomService.delete(id);
return Result.ok("删除成功");
}
}
/**
*/
@RestController
@RequestMapping("/building")
public class BuildingController {
@Autowired
private BuildingService buildingService;
@Autowired
private RoomService roomService;
@GetMapping("/listAll")
@RequirePermission(permissions = {"manage:building:list"})
public Result<List<Building>> listAll() {
List<Building> list = buildingService.listAll();
return Result.<List<Building>>ok().add(list);
}
@GetMapping("/list")
@RequirePermission(permissions = {"manage:building:list"})
public Result<List<Building>> list() {
List<Building> list = buildingService.list();
@RequirePermission(permissions = {"student:save", "student:update"})
@Log
public Result<?> saveOrUpdate(@RequestBody Student student) {
studentService.saveOrUpdate(student);
return Result.ok("操作成功");
}
@PostMapping("/delete")
@RequirePermission(permissions = {"student:delete"})
@Log
public Result<?> delete(@RequestBody DepartApplication departApplication, @RequestHeader(Constant.HEADER_TOKEN) String token) {
SystemUser user = redisUtil.exchange(token).get();
departApplication.setApplyUserId(user.getId());
departApplicationService.saveApplication(departApplication);
if (user.getLeaderId() == null) {
studentService.delete(departApplication.getStudentId());
return Result.ok("退宿成功");
} else {
departApplicationService.saveApplication(user.getLeaderId(), departApplication.getId());
WebSocket.sendMessage(user.getLeaderId(),
new Message().setTitle("新的退宿申请").setType(2).setMessageBody(departApplication.getReason()),
systemUserService);
return Result.ok("退宿申请已提交,等待上一级审核");
}
}
}
/**
/**
*/
@RestController
@RequestMapping("/system/function")
public class SystemFunctionController {
@Autowired
private SystemFunctionService systemFunctionService;
@GetMapping("/list")
@RequirePermission(permissions = {"system:function:list"})
public Result<List<SystemFunction>> list() {
List<SystemFunction> list = systemFunctionService.listTree();
return Result.<List<SystemFunction>>ok().add(list);
}
@GetMapping("/delete")
@RequirePermission(permissions = {"system:function:delete"})
@Log("删除功能")
public Result<?> delete(@RequestParam("id") Long id) {
systemFunctionService.delete(id);
return Result.ok("删除成功");
}
@PostMapping("/saveOrUpdate")
@RequirePermission(permissions = {"system:function:save", "system:function:update"})
@Log("添加修改功能")
public Result<?> saveOrUpdate(@RequestBody @Validated SystemFunction function) {
if (function.getId() == null) {
systemFunctionService.save(function);
} else {
if (function.getId().equals(function.getParentId())) {
throw new HttpException(HttpCode.FAILED, "父节点不能为自己");
}
systemFunctionService.update(function);
}
return Result.ok("操作成功");
}
@GetMapping("/query")
* @param systemUser 修改的用户
* @return 修改成功后将修改后的用户返回
*/
@PostMapping("/update")
public Result<SystemUser> update(@RequestBody SystemUser systemUser, @RequestHeader(HEADER_TOKEN) String token) {
systemUser.setId(redisUtil.get(token));
systemUserService.saveOrUpdate(systemUser);
return Result.<SystemUser>ok("修改成功").add(systemUser);
}
@GetMapping("/changeIcon/{icon}")
public Result<?> changeIcon(@PathVariable String icon , @RequestHeader(HEADER_TOKEN) String token) {
systemUserService.changeIcon(icon, redisUtil.get(token));
return Result.ok("修改成功");
}
}
/**
*/
@RestController
@RequestMapping("/depart")
public class DepartApplicationController {
@Autowired
private DepartApplicationService departApplicationService;
@Autowired
private StudentService studentService;
return true;
}
}
}
return false;
});
VALIDATE_MAP.put(Match.HAS_ALL, (userPermission, methodPermission) -> {
int vote = 0;
for (String up : userPermission) {
for (String mp : methodPermission) {
if (up.equalsIgnoreCase(mp)) {
vote++;
}
}
}
return vote == methodPermission.length;
});
}
public SecurityInterceptor(RedisUtil redisUtil, SystemFunctionService systemFunctionService, SystemRoleService systemRoleService) {
this.redisUtil = redisUtil;
this.systemFunctionService = systemFunctionService;
this.systemRoleService = systemRoleService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//获取请求的方法
HandlerMethod handlerMethod;
if (handler instanceof HandlerMethod) {
handlerMethod = (HandlerMethod) handler;
} else {
//404
return true;
}
Method method = handlerMethod.getMethod();
//获取请求方法所需的权限
String[] requiredPermissions;
Match match;
if (method.isAnnotationPresent(RequirePermission.class)) {
RequirePermission hasPermission = method.getAnnotation(RequirePermission.class);
requiredPermissions = hasPermission.permissions();
match = hasPermission.matchType();
} else {
//方法不需要权限(无 RequirePermission 注解)
return true;
}
String token = request.getHeader(Constant.HEADER_TOKEN);
Long id = redisUtil.get(token);
//获取该用户的权限
List<SystemRole> roleList = systemRoleService.listByUserId(id);
@RequirePermission(permissions = {"room:list"})
@PostMapping("/list")
public Result<PageInfo<Room>> list(@RequestBody ListQuery<Room> listQuery, @RequestHeader(Constant.HEADER_TOKEN) String token) {
SystemUser systemUser = redisUtil.exchange(token).orElseThrow(() -> new HttpException(HttpCode.FAILED, "登录用户不存在"));
PageInfo<Room> pageInfo = roomService.list(listQuery, systemUser.getBuildingId());
return Result.<PageInfo<Room>>ok().add(pageInfo);
}
@RequirePermission(permissions = {"room:list"})
@GetMapping("/listAll")
public Result<List<Room>> list(@RequestHeader(Constant.HEADER_TOKEN) String token) {
SystemUser systemUser = redisUtil.exchange(token).orElseThrow(() -> new HttpException(HttpCode.FAILED, "登录用户不存在"));
List<Room> list = roomService.list(systemUser.getBuildingId());
return Result.<List<Room>>ok().add(list);
}
@GetMapping("/query/{id}")
@RequirePermission(permissions = {"room:query"})
public Result<Room> query(@PathVariable("id") Long id) {
Room room = roomService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "没有该宿舍信息"));
return Result.<Room>ok().add(room);
}
@PostMapping("/saveOrUpdate")
@RequirePermission(permissions = {"room:save", "room:update"})
@Log
public Result<?> saveOrUpdate(@RequestBody @Validated Room room) {
roomService.saveOrUpdate(room);
return Result.ok();
}
@GetMapping("/delete/{id}")
@RequirePermission(permissions = {"room:delete"})
@Log
public Result<?> delete(@PathVariable("id") Long id) {
int count = studentService.countByRoomId(id);
if (count > 0) {
throw new HttpException(HttpCode.FAILED, "该宿舍还有学生, 无法删除");
}
roomService.delete(id);
return Result.ok("删除成功");
}
}
if (systemUser.getPassword().equals(MD5Util.md5(user.getPassword()))) {
String token = UUID.randomUUID().toString();
redisUtil.put(token, systemUser.getId());
return Result.<String>ok().add(redirectUrl + "#/token=" + token);
} else {
throw new HttpException(HttpCode.LOGIN_FAILED, "登陆失败,密码错误");
}
}
}
@GetMapping("/logout")
public Result<?> logout(@RequestHeader(HEADER_TOKEN) String token) {
if (redisUtil.hasToken(token)) {
redisUtil.deleteToken(token);
}
return Result.ok();
}
}
/**
*/
@RestController
@RequestMapping("/backlate")
public class BackLateController {
@Autowired
private BackLateService backLateService;
@Autowired
private RedisUtil redisUtil;
@PostMapping("/saveOrUpdate")
@RequirePermission(permissions = {"back:save","back:update"})
/**
* 权限拦截器
*/
@Component
public class SecurityInterceptor implements HandlerInterceptor {
private final RedisUtil redisUtil;
private final SystemFunctionService systemFunctionService;
private final SystemRoleService systemRoleService;
private static final Map<Match, Validate> VALIDATE_MAP = new HashMap<>();
static {
VALIDATE_MAP.put(Match.HAS_ANY, (userPermission, methodPermission) -> {
for (String up : userPermission) {
for (String mp : methodPermission) {
if (up.equalsIgnoreCase(mp)) {
return true;
}
}
}
return false;
});
VALIDATE_MAP.put(Match.HAS_ALL, (userPermission, methodPermission) -> {
int vote = 0;
for (String up : userPermission) {
for (String mp : methodPermission) {
if (up.equalsIgnoreCase(mp)) {
vote++;
}
}
}
return vote == methodPermission.length;
}
@PostMapping("/list")
@RequirePermission(permissions = {"system:role:list"})
public Result<PageInfo<SystemRole>> list(@RequestBody ListQuery<SystemRole> query) {
PageHelper.startPage(query.getPage(), query.getRows());
List<SystemRole> list = systemRoleService.listAll(query.getEntity());
PageInfo<SystemRole> pageInfo = new PageInfo<>(list);
return Result.<PageInfo<SystemRole>>ok().add(pageInfo);
}
@GetMapping("/delete")
@RequirePermission(permissions = {"system:role:delete"})
@Log("删除角色")
public Result<?> delete(@RequestParam("id") Long id) {
systemRoleService.delete(id);
return Result.ok("操作成功");
}
@GetMapping("/query")
@RequirePermission(permissions = {"system:role:query"})
public Result<SystemRole> query(@RequestParam("id") Long id) {
SystemRole role = systemRoleService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "角色不存在"));
role.setFunctionIds(systemFunctionService.selectMenuListByRoleId(id));
return Result.<SystemRole>ok().add(role);
}
}
/**
/**
*/
@RestController
@RequestMapping("/system/role")
public class SystemRoleController {
@Autowired
private SystemRoleService systemRoleService;
@Autowired
private SystemFunctionService systemFunctionService;
@GetMapping("/listInSelect")
@RequirePermission(permissions = {"system:role:list"})
public Result<List<SystemRole>> listInSelect() {
return Result.<List<SystemRole>>ok().add(systemRoleService.listAll(new SystemRole()));
}
@PostMapping("/saveOrUpdate")
@RequirePermission(permissions = {"system:role:save", "system:role:update"})
@Log("添加修改角色")
public Result<?> saveOrUpdate(@RequestBody @Validated SystemRole role) {
systemRoleService.saveOrUpdate(role);
return Result.ok("操作成功");
}
@PostMapping("/list")
@RequirePermission(permissions = {"system:role:list"})