医院管理系统
简介
基于 SpringBoot + Vue 的前后端分离医院管理系统,使用 SpringSecurity 结合 jwt 作为权限管理,使用 guava-cache 存储生成的 token,使用SpringDataJpa 方便数据库操作,使用 mysql 作为数据库,使用 druid 作为数据库连接池,使用 easy-captcha 作为验证码生成工具;前端使用 axios 进行后端的请求,使用 element-ui 作为组件库,使用 vuex 存储状态信息,使用 vue-router 进行路由跳转。
功能
- 系统管理
- 用户管理
- 划价收费
- 药库管理
- 药房管理
- 门诊管理
- 挂号管理
- 体检管理
代码
使用 guava-cache 存储生成的 token
package com.hospital.system.components;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
/**
* 缓存管理token
*/
public class TokenCache {
private static final String TOKEN_KEY = "token_";
private static Cache<String, String> cache = CacheBuilder.newBuilder().build();
/**
* 保存
* @param token
*/
public static void setToken(String username, String token) {
cache.put(TOKEN_KEY+username,token);
}
public static void deleteToken(){
cache.invalidateAll();
}
/**
* 取
* @return
*/
public static String getTokenFromCache(String username){
return cache.getIfPresent(TOKEN_KEY+username);
}
/**
* 保存
* @param val
*/
public static void setRem(String key, String val) {
cache.put(key,val);
}
/**
* 取
* @return
*/
public static String getRem(String key){
return cache.getIfPresent(key);
}
}
查询数据库进行鉴权
package com.hospital.system.components;
import com.hospital.system.exception.MyaccessDeniedException;
import com.hospital.system.entity.SysBackendApiTable;
import com.hospital.system.service.SysBackendApiTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Component
public class DynamicPermission {
@Autowired
SysBackendApiTableService service;
/**
* 判断有访问API的权限
* @param request
* @param authentication
* @return
* @throws MyaccessDeniedException
*/
public boolean checkPermisstion(HttpServletRequest request,
Authentication authentication) throws MyaccessDeniedException {
Object principal = authentication.getPrincipal();
System.out.println("DynamicPermission principal = " + principal);
if(principal instanceof UserDetails) {
UserDetails userDetails = (UserDetails) principal;
//得到当前的账号
String username = userDetails.getUsername();
//Collection<? extends GrantedAuthority> roles = userDetails.getAuthorities();
// System.out.println("DynamicPermission username = " + username);
//通过账号获取资源鉴权
List<SysBackendApiTable> apiUrls = service.getApiUrlByUserName(username);
AntPathMatcher antPathMatcher = new AntPathMatcher();
//当前访问路径
String requestURI = request.getRequestURI();
//提交类型
String urlMethod = request.getMethod();
// System.out.println("DynamicPermission requestURI = " + requestURI);
//判断当前路径中是否在资源鉴权中
boolean rs = apiUrls.stream().anyMatch(item->{
//判断URL是否匹配
boolean hashAntPath = antPathMatcher.match(item.getBackendApiUrl(),requestURI);
//判断请求方式是否和数据库中匹配(数据库存储:GET,POST,PUT,DELETE)
String dbMethod = item.getBackendApiMethod();
//处理null,万一数据库存值
dbMethod = (dbMethod == null )? "": dbMethod;
int hasMethod = dbMethod.indexOf(urlMethod);
System.out.println("hashAntPath = " + hashAntPath);
System.out.println("hasMethod = " + hasMethod);
System.out.println("hashAntPath && hasMethod = " + (hashAntPath && hasMethod !=-1));
//两者都成立,返回真,否则返回假
return hashAntPath && (hasMethod !=-1);
});
//返回
if (rs) {
return rs;
}else {
throw new MyaccessDeniedException("您没有访问该API的权限!");
}
}else{
throw new MyaccessDeniedException("不是UserDetails类型!");
}
}
}
示例
登录
注册
首页
菜单管理
API 管理
角色分配
菜单分配
api 分配
角色管理
用户信息管理
门诊收费
体检收费
出入库管理
药品管理
药房取药
普通门诊
挂号记录
挂号记录
进行挂号
普通体检