基于 SpringBoot + Vue 的学生公寓管理系统
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                基于 SpringBoot + Vue 的学生公寓管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                學生公寓管理系統
簡介
基于 SpringBoot + Vue 的學生公寓管理系統,自定義了權限攔截器進行權限認證與授權,使用 aop+log4j 進行日志記錄,使用 reids 作為緩存,使用 mysql 作為數據庫,使用 druid 作為數據庫連接池,使用 jwt 作為前后端狀態交互信息,使用 websocket 進行通知的實時推送。
功能
-  登錄注銷,修改密碼個人信息 
-  宿舍管理 
-  學生管理 
-  班級管理 
-  宿舍樓管理 
-  維修記錄 
-  用戶管理 
-  菜單管理 
-  角色管理 
-  日志 
-  通知管理 
-  退宿審核 
代碼
自定義權限攔截
@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;});}public SecurityInterceptor(RedisUtil redisUtil, SystemFunctionService systemFunctionService, SystemRoleService systemRoleService) {this.redisUtil = redisUtil;this.systemFunctionService = systemFunctionService;this.systemRoleService = systemRoleService;}@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {//獲取請求的方法HandlerMethod handlerMethod;if (handler instanceof HandlerMethod) {handlerMethod = (HandlerMethod) handler;} else {//404return 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;}//權限驗證失敗throw new HttpException(HttpCode.HAS_NO_PERMISSIONS, "沒有權限,請聯系管理員");}private interface Validate {/*** 驗證權限* @param userPermission 用戶擁有的權限* @param methodPermission 方法需要的權限* @return 是否通過*/Boolean validate(Set<String> userPermission, String[] methodPermission);} }實現通知消息的推送
@Component @ServerEndpoint("/ws/{name}") public class WebSocket {private Session session;private String name;public final static Map<String,WebSocket> WEB_SOCKET_SET = new ConcurrentHashMap<>();@OnOpenpublic void onOpen(Session session,@PathParam(value = "name") String name){this.session = session;this.name = name;WEB_SOCKET_SET.put(name,this);}@OnClosepublic void onClose(){WEB_SOCKET_SET.remove(name);}@OnMessagepublic void onMessage(String message) throws JsonProcessingException {Message m = new ObjectMapper().readValue(message, Message.class);System.out.println(m);}/*** 發送消息* @param userId 目標用戶id* @param message 消息內容* @param systemUserService 。*/public static boolean sendMessage(Long userId, Message message, SystemUserService systemUserService) {SystemUser systemUser = systemUserService.get(userId).orElseThrow(() -> new HttpException(HttpCode.FAILED, "用戶不存在"));if (WEB_SOCKET_SET.containsKey(systemUser.getLoginName())) {ObjectMapper objectMapper = new ObjectMapper();try {WEB_SOCKET_SET.get(systemUser.getLoginName()).session.getBasicRemote().sendText(objectMapper.writeValueAsString(message));return true;} catch (IOException e) {e.printStackTrace();}}return false;} }示例
登錄
管理員主頁
宿舍管理
學生管理
班級管理
宿舍樓管理
維修記錄
用戶管理
角色管理
菜單管理
 
日志記錄
消息
審核
總結
以上是生活随笔為你收集整理的基于 SpringBoot + Vue 的学生公寓管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 题目0134-竖直四子棋
- 下一篇: linux 做路由器系统下载文件,用Li
