diff --git a/.gitignore b/.gitignore index 9154f4c7..a879ee72 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,39 @@ -# ---> Java -# Compiled class file -*.class +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Log file -*.log +### IntelliJ IDEA ### +.idea/ +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr -# BlueJ files -*.ctxt +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* +### VS Code ### +.vscode/ +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..99788073 --- /dev/null +++ b/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.3.5.RELEASE + + + com.supervision + virtual-patient + 1.0-SNAPSHOT + pom + + virtual-patient + + + + virtual-patient-common + virtual-patient-model + virtual-patient-web + + + + UTF-8 + 1.8 + 1.8 + + 2.3.5.RELEASE + 1.2.76 + 3.3.1 + 1.1.10 + 5.8.16 + 3.0.3 + + + + + + org.projectlombok + lombok + 1.18.20 + provided + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + + cn.hutool + hutool-all + ${hutool.version} + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-puls-spring-boot.version} + + + + + + + + diff --git a/virtual-patient-common/pom.xml b/virtual-patient-common/pom.xml new file mode 100644 index 00000000..b9b4926b --- /dev/null +++ b/virtual-patient-common/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + com.supervision + virtual-patient + 1.0-SNAPSHOT + + + virtual-patient-common + + + 8 + 8 + UTF-8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + mysql + mysql-connector-java + 8.0.26 + + + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.9 + + + + + + \ No newline at end of file diff --git a/virtual-patient-common/src/main/java/com/supervision/config/JwtInterceptor.java b/virtual-patient-common/src/main/java/com/supervision/config/JwtInterceptor.java new file mode 100644 index 00000000..25ea6558 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/config/JwtInterceptor.java @@ -0,0 +1,66 @@ +package com.supervision.config; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.hutool.jwt.JWT; +import cn.hutool.jwt.JWTUtil; +import com.supervision.domain.UserInfo; +import com.supervision.exception.BusinessException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Slf4j +public class JwtInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + //请求消息头获取用户ID + String token = request.getHeader("token"); + if (StrUtil.isBlank(token)) { + throw new BusinessException("当前用户未登录"); + } + JWT jwt = JWTUtil.parseToken(token); + // 校验token是否过期,如果过期了,需要提示过期重新登录 + checkTokenExpire(jwt); + cacheAuth(jwt); + return true; + } + + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { + // 请求结束,将用户信息从thread中移除 + clearAuth(); + HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); + } + + private void checkTokenExpire(JWT jwt) { + Object expireTime = jwt.getPayload("expireTime"); + long l = Long.parseLong(String.valueOf(expireTime)); + // 校验是否比当前时间大 + System.out.println(l); + long currentTimeMillis = System.currentTimeMillis(); + if (currentTimeMillis > l) { + throw new BusinessException("用户登录已过期,请重新登录"); + } + } + + private void cacheAuth(JWT jwt) { + try { + JSONObject claimsJson = jwt.getPayload().getClaimsJson(); + UserInfo userInfo = JSONUtil.toBean(claimsJson, UserInfo.class); + ThreadCache.USER.set(userInfo); + } catch (Exception e) { + log.error("用户信息异常", e); + } + } + + private void clearAuth() { + ThreadCache.USER.remove(); + } +} diff --git a/virtual-patient-common/src/main/java/com/supervision/config/Knife4jConfig.java b/virtual-patient-common/src/main/java/com/supervision/config/Knife4jConfig.java new file mode 100644 index 00000000..f4274756 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/config/Knife4jConfig.java @@ -0,0 +1,53 @@ +/* + * 文 件 名: Knife4jConfig + * 版 权: + * 描 述: <描述> + * 修 改 人: RedName + * 修改时间: 2022/8/5 + * 跟踪单号: <跟踪单号> + * 修改单号: <修改单号> + * 修改内容: <修改内容> + */ +package com.supervision.config; + +import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; +import io.swagger.annotations.Api; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +/** + * <功能详细描述> + * + * @author ljt + * @version [版本号, 2022/8/5] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Configuration +@EnableSwagger2WebMvc +public class Knife4jConfig { + @Bean(value = "defaultApi2") + public Docket defaultApi2() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(this.apiInfo()) + .useDefaultResponseMessages(false) + .select() + .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) + .paths(PathSelectors.any()).build(); + + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder().title("API文档").description("API文档").contact(new Contact("", "", "")) + .version("1.0.0").build(); + } +} diff --git a/virtual-patient-common/src/main/java/com/supervision/config/MyBatisMetaObjectHandler.java b/virtual-patient-common/src/main/java/com/supervision/config/MyBatisMetaObjectHandler.java new file mode 100644 index 00000000..e85b88df --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/config/MyBatisMetaObjectHandler.java @@ -0,0 +1,28 @@ +package com.supervision.config; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.stereotype.Component; + +import java.util.Date; + +/** + * @author ljt on 2022/08/13. + * 创建时间和更新时间自动填充 + */ +@Component +public class MyBatisMetaObjectHandler implements MetaObjectHandler { + // 使用MP进行添加操作,该方法执行 + @Override + public void insertFill(MetaObject metaObject) { + //属性名称,不是字段名称 + this.setFieldValByName("createTime", new Date(), metaObject); + this.setFieldValByName("updateTime", new Date(), metaObject); + } + + @Override + public void updateFill(MetaObject metaObject) { + // 使用MP进行修改操作,该方法执行 + this.setFieldValByName("updateTime", new Date(), metaObject); + } +} diff --git a/virtual-patient-common/src/main/java/com/supervision/config/MybatisPlusConfig.java b/virtual-patient-common/src/main/java/com/supervision/config/MybatisPlusConfig.java new file mode 100644 index 00000000..ec5c1754 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/config/MybatisPlusConfig.java @@ -0,0 +1,32 @@ +/* + * 文 件 名: MybatisPlusConfig + * 版 权: + * 描 述: <描述> + * 修 改 人: RedName + * 修改时间: 2022/8/9 + * 跟踪单号: <跟踪单号> + * 修改单号: <修改单号> + * 修改内容: <修改内容> + */ +package com.supervision.config; + +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * <功能详细描述> + * + * @author RedName + * @version [版本号, 2022/8/9] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Configuration +public class MybatisPlusConfig { + + @Bean + public PaginationInterceptor paginationInterceptor() { + return new PaginationInterceptor(); + } +} diff --git a/virtual-patient-common/src/main/java/com/supervision/config/ResponseConfig.java b/virtual-patient-common/src/main/java/com/supervision/config/ResponseConfig.java new file mode 100644 index 00000000..c3207935 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/config/ResponseConfig.java @@ -0,0 +1,102 @@ +package com.supervision.config; + +import cn.hutool.json.JSONUtil; +import com.supervision.domain.GlobalResult; +import com.supervision.exception.BusinessException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.MethodParameter; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.server.ServerHttpRequest; +import org.springframework.http.server.ServerHttpResponse; +import org.springframework.lang.Nullable; +import org.springframework.validation.BindException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; + +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * 统一返回 + * + * @author wb + * @date 2022/3/10 13:24 + */ +@Slf4j +@RestControllerAdvice(annotations = RestController.class, basePackages = {"com.**.controller"}) +public class ResponseConfig implements ResponseBodyAdvice { + + + @Override + public boolean supports(@Nullable MethodParameter methodParameter, + @Nullable Class> aClass) { + assert methodParameter != null; + return !methodParameter.getDeclaringClass().getName().contains("swagger"); + } + + @Override + public Object beforeBodyWrite(Object o, @Nullable MethodParameter methodParameter, @Nullable MediaType mediaType, + @Nullable Class> aClass, @Nullable ServerHttpRequest serverHttpRequest, + @Nullable ServerHttpResponse serverHttpResponse) { + + + if (Objects.isNull(o)) { + return GlobalResult.ok(null, "success"); + } + if (o instanceof GlobalResult) { + return o; + } + // 对于String类型的返回值需要进行特殊处理 + if (o instanceof String) { + return JSONUtil.toJsonStr(GlobalResult.ok(o, "success")); + } + return GlobalResult.ok(o, "success"); + } + + /** + * 业务异常处理 + * + * @param exception 业务异常 + * @return 通用返回值 + */ + @ExceptionHandler(BusinessException.class) + public GlobalResult businessExceptionResponse(BusinessException exception) { + log.error(exception.getMessage(), exception); + return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), exception.getMessage(), "业务异常"); + } + + + /** + * 参数验证异常处理 + * + * @param exception 参数验证异常 + * @return 通用返回值 + */ + @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class}) + public GlobalResult validationExceptionResponse(MethodArgumentNotValidException exception) { + log.error(exception.getMessage(), exception); + // 格式化错误信息 + String errorMsg = exception.getBindingResult().getFieldErrors().stream() + .map(e -> e.getField() + ":" + e.getDefaultMessage()).collect(Collectors.joining("、")); + return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "参数验证异常", errorMsg); + } + + + /** + * 未知异常处理 + * + * @param exception 未知异常 + * @return 通用返回值 + */ + @ExceptionHandler(Exception.class) + public GlobalResult validationExceptionResponse(Exception exception) { + log.error(exception.getMessage(), exception); + return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "未知错误", exception.getMessage()); + } + +} diff --git a/virtual-patient-common/src/main/java/com/supervision/config/ThreadCache.java b/virtual-patient-common/src/main/java/com/supervision/config/ThreadCache.java new file mode 100644 index 00000000..cc257865 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/config/ThreadCache.java @@ -0,0 +1,32 @@ +/* + * 文 件 名: ThreadCache + * 版 权: + * 描 述: <描述> + * 修 改 人: RedName + * 修改时间: 2023/9/4 + * 跟踪单号: <跟踪单号> + * 修改单号: <修改单号> + * 修改内容: <修改内容> + */ +package com.supervision.config; + + +import com.supervision.domain.UserInfo; + +/** + * <功能详细描述> + * + * @author ljt + * @version [版本号, 2023/9/4] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class ThreadCache { + + /** + * 用户ID + */ + public static final ThreadLocal USER = new ThreadLocal<>(); + + +} diff --git a/virtual-patient-common/src/main/java/com/supervision/config/WebConfig.java b/virtual-patient-common/src/main/java/com/supervision/config/WebConfig.java new file mode 100644 index 00000000..33e9d678 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/config/WebConfig.java @@ -0,0 +1,33 @@ +package com.supervision.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import java.util.ArrayList; +import java.util.List; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addInterceptors(InterceptorRegistry registry) { + // 添加权限拦截器 + registry.addInterceptor(new JwtInterceptor()) + .addPathPatterns("/**") + .excludePathPatterns(ignorePathPatterns()); + } + + public List ignorePathPatterns() { + List paths = new ArrayList<>(); + paths.add("/swagger-resources/**"); + paths.add("/webjars/**"); + paths.add("/v2/**"); + paths.add("/swagger-ui.html/**"); + paths.add("/doc.html/**"); + paths.add("/error"); + paths.add("/favicon.ico"); + paths.add("/user/login"); + return paths; + } +} diff --git a/virtual-patient-common/src/main/java/com/supervision/domain/GlobalResult.java b/virtual-patient-common/src/main/java/com/supervision/domain/GlobalResult.java new file mode 100644 index 00000000..86311704 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/domain/GlobalResult.java @@ -0,0 +1,45 @@ +package com.supervision.domain; + +import lombok.Data; +import org.springframework.http.HttpStatus; + +@Data +public class GlobalResult { + + private int code = 200; + + private String msg = "success"; + + private T data; + + + public static GlobalResult ok() { + return ok(null); + } + + public static GlobalResult ok(T data) { + GlobalResult globalResult = new GlobalResult<>(); + globalResult.setData(data); + return globalResult; + } + + public static GlobalResult ok(T data, String message) { + GlobalResult globalResult = new GlobalResult<>(); + globalResult.setMsg(message); + globalResult.setData(data); + return globalResult; + } + + public static GlobalResult error(String msg) { + return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), null, msg); + } + + + public static GlobalResult error(int code, T data, String msg) { + GlobalResult globalResult = new GlobalResult<>(); + globalResult.setCode(code); + globalResult.setData(data); + globalResult.setMsg(msg); + return globalResult; + } +} diff --git a/virtual-patient-common/src/main/java/com/supervision/domain/UserInfo.java b/virtual-patient-common/src/main/java/com/supervision/domain/UserInfo.java new file mode 100644 index 00000000..82a1c425 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/domain/UserInfo.java @@ -0,0 +1,11 @@ +package com.supervision.domain; + +import lombok.Data; + +@Data +public class UserInfo { + + private String id; + + private String name; +} diff --git a/virtual-patient-common/src/main/java/com/supervision/exception/BusinessException.java b/virtual-patient-common/src/main/java/com/supervision/exception/BusinessException.java new file mode 100644 index 00000000..53d07fb6 --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/exception/BusinessException.java @@ -0,0 +1,76 @@ +/* + * 文 件 名: CustomException + * 版 权: + * 描 述: <描述> + * 修 改 人: RedName + * 修改时间: 2022/8/5 + * 跟踪单号: <跟踪单号> + * 修改单号: <修改单号> + * 修改内容: <修改内容> + */ +package com.supervision.exception; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; + +/** + * <功能详细描述> + * 自定义异常 + * + * @author ljt + * @version [版本号, 2022/8/5] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Slf4j +public class BusinessException extends RuntimeException { + /** + * 异常编码 + */ + private final Integer code; + + /** + * 异常信息 + */ + private final String message; + + public BusinessException(Throwable cause) { + super(cause); + this.code = HttpStatus.INTERNAL_SERVER_ERROR.value(); + this.message = null; + + } + + public BusinessException(Throwable cause, String message) { + super(cause); + this.code = HttpStatus.INTERNAL_SERVER_ERROR.value(); + this.message = message; + + } + + public BusinessException(String message) { + this.code = HttpStatus.INTERNAL_SERVER_ERROR.value(); + this.message = message; + } + + public BusinessException(String message, Integer code) { + this.message = message; + this.code = code; + } + + public BusinessException(String message, Throwable e) { + super(message, e); + log.error(message, e); + this.code = HttpStatus.INTERNAL_SERVER_ERROR.value(); + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public Integer getCode() { + return code; + } +} diff --git a/virtual-patient-common/src/main/java/com/supervision/util/TokenUtil.java b/virtual-patient-common/src/main/java/com/supervision/util/TokenUtil.java new file mode 100644 index 00000000..9ff37ddb --- /dev/null +++ b/virtual-patient-common/src/main/java/com/supervision/util/TokenUtil.java @@ -0,0 +1,19 @@ +package com.supervision.util; + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.hutool.jwt.JWTUtil; +import cn.hutool.jwt.signers.JWTSigner; +import cn.hutool.jwt.signers.JWTSignerUtil; +import com.supervision.domain.UserInfo; + +public class TokenUtil { + + public static String creatToken(UserInfo userInfo){ + final JWTSigner signer = JWTSignerUtil.hs256("123456".getBytes()); + JSONObject info = JSONUtil.parseObj(userInfo); + // 过期时间一天 + info.putOnce("expireTime",System.currentTimeMillis() + 1000 * 60 * 60 * 24); + return JWTUtil.createToken(info, signer); + } +} diff --git a/virtual-patient-model/pom.xml b/virtual-patient-model/pom.xml new file mode 100644 index 00000000..186ae7b6 --- /dev/null +++ b/virtual-patient-model/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + com.supervision + virtual-patient + 1.0-SNAPSHOT + + + virtual-patient-model + jar + + virtual-patient-model + + + UTF-8 + + + + + + diff --git a/virtual-patient-web/pom.xml b/virtual-patient-web/pom.xml new file mode 100644 index 00000000..af9811fc --- /dev/null +++ b/virtual-patient-web/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + + com.supervision + virtual-patient + 1.0-SNAPSHOT + + + virtual-patient-web + jar + + virtual-patient-web + + + UTF-8 + + + + + + com.supervision + virtual-patient-model + 1.0-SNAPSHOT + + + + com.supervision + virtual-patient-common + 1.0-SNAPSHOT + + + + + diff --git a/virtual-patient-web/src/main/java/com/supervision/VirtualPatientApplication.java b/virtual-patient-web/src/main/java/com/supervision/VirtualPatientApplication.java new file mode 100644 index 00000000..074f5712 --- /dev/null +++ b/virtual-patient-web/src/main/java/com/supervision/VirtualPatientApplication.java @@ -0,0 +1,14 @@ +package com.supervision; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class VirtualPatientApplication { + + public static void main(String[] args) { + SpringApplication.run(VirtualPatientApplication.class, args); + } + + +} diff --git a/virtual-patient-web/src/main/java/com/supervision/controller/TestController.java b/virtual-patient-web/src/main/java/com/supervision/controller/TestController.java new file mode 100644 index 00000000..94dbab9b --- /dev/null +++ b/virtual-patient-web/src/main/java/com/supervision/controller/TestController.java @@ -0,0 +1,15 @@ +package com.supervision.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("test") +public class TestController { + + @GetMapping("testExpireTime") + public String testExpireTime() { + return "OK"; + } +} diff --git a/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java b/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java new file mode 100644 index 00000000..e76a9138 --- /dev/null +++ b/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java @@ -0,0 +1,28 @@ +package com.supervision.controller; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.hutool.jwt.JWTUtil; +import cn.hutool.jwt.signers.JWTSigner; +import cn.hutool.jwt.signers.JWTSignerUtil; +import com.supervision.domain.UserInfo; +import com.supervision.exception.BusinessException; +import com.supervision.util.TokenUtil; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("user") +public class UserController { + + @GetMapping("login") + public String login(String userName, String password) { + if (StrUtil.isBlank(userName)) { + throw new BusinessException("用户名不能为空"); + } + UserInfo userInfo = new UserInfo(); + return TokenUtil.creatToken(userInfo); + } +} diff --git a/virtual-patient-web/src/main/resources/application.yml b/virtual-patient-web/src/main/resources/application.yml new file mode 100644 index 00000000..796e110d --- /dev/null +++ b/virtual-patient-web/src/main/resources/application.yml @@ -0,0 +1,42 @@ +#服务器端口 +server: + port: 8899 + +spring: + application: + name: virtual-patient + ##数据源配置 + datasource: + type: com.alibaba.druid.pool.DruidDataSource + druid: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://192.168.10.137:3306/doctor_training?useUnicode=true&characterEncoding=utf-8&useSSL=true&nullCatalogMeansCurrent=true&serverTimezone=GMT%2B8 + username: root + password: 'Root&&&123456' + initial-size: 5 # 初始化大小 + min-idle: 10 # 最小连接数 + max-active: 20 # 最大连接数 + max-wait: 60000 # 获取连接时的最大等待时间 + min-evictable-idle-time-millis: 300000 # 一个连接在池中最小生存的时间,单位是毫秒 + time-between-eviction-runs-millis: 60000 # 多久才进行一次检测需要关闭的空闲连接,单位是毫秒 + filters: stat,wall # 配置扩展插件:stat-监控统计,log4j-日志,wall-防火墙(防止SQL注入),去掉后,监控界面的sql无法统计 + validation-query: SELECT 1 # 检测连接是否有效的 SQL语句,为空时以下三个配置均无效 + test-on-borrow: true # 申请连接时执行validationQuery检测连接是否有效,默认true,开启后会降低性能 + test-on-return: true # 归还连接时执行validationQuery检测连接是否有效,默认false,开启后会降低性能 + test-while-idle: true # 申请连接时如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效,默认false,建议开启,不影响性能 + stat-view-servlet: + enabled: false # 是否开启 StatViewServlet + filter: + stat: + enabled: true # 是否开启 FilterStat,默认true + log-slow-sql: true # 是否开启 慢SQL 记录,默认false + slow-sql-millis: 5000 # 慢 SQL 的标准,默认 3000,单位:毫秒 + merge-sql: false # 合并多个连接池的监控数据,默认false + + profiles: + active: dev + +mybatis-plus: + mapper-locations: classpath*:mapper/**/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl \ No newline at end of file diff --git a/virtual-patient-web/src/main/resources/logback-spring.xml b/virtual-patient-web/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..ff6e1417 --- /dev/null +++ b/virtual-patient-web/src/main/resources/logback-spring.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/virtual-patient-web/src/main/resources/mybatis-config.xml b/virtual-patient-web/src/main/resources/mybatis-config.xml new file mode 100644 index 00000000..65b797a0 --- /dev/null +++ b/virtual-patient-web/src/main/resources/mybatis-config.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/virtual-patient-web/src/test/java/org/example/AppTest.java b/virtual-patient-web/src/test/java/org/example/AppTest.java new file mode 100644 index 00000000..d5f435df --- /dev/null +++ b/virtual-patient-web/src/test/java/org/example/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}