diff --git a/pom.xml b/pom.xml
index 48b22f29..b7c46fc7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,11 +44,14 @@
8.0.26
1.5.22
2.2.5
+ 8.5.7
+ 4.9.0
+
mysql
mysql-connector-java
@@ -121,6 +124,18 @@
swagger-annotations
${io-swagger.version}
+
+
+ io.minio
+ minio
+ ${minio.version}
+
+
+
+ com.squareup.okhttp3
+ okhttp
+ ${okhttp.version}
+
diff --git a/virtual-patient-common/pom.xml b/virtual-patient-common/pom.xml
index 4eb50d36..5011adfa 100644
--- a/virtual-patient-common/pom.xml
+++ b/virtual-patient-common/pom.xml
@@ -101,6 +101,16 @@
hutool-all
+
+ io.minio
+ minio
+
+
+
+ com.squareup.okhttp3
+ okhttp
+
+
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
index 70fe2534..89d7e453 100644
--- a/virtual-patient-common/src/main/java/com/supervision/config/JwtInterceptor.java
+++ b/virtual-patient-common/src/main/java/com/supervision/config/JwtInterceptor.java
@@ -37,21 +37,21 @@ public class JwtInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
- //请求消息头获取用户ID
- String token = request.getHeader("token");
- if (StrUtil.isBlank(token)) {
- // 如果是swagger来的接口,说明这里是测试的,会伪造一个用户
- if (StrUtil.isNotBlank(request.getHeader("Knife4j-Gateway-Code"))) {
- cacheAuth(JWTUtil.parseToken(devActiveUser()));
- return true;
- } else {
- throw new BusinessException("当前用户未登录", HttpStatus.UNAUTHORIZED.value());
- }
- }
- JWT jwt = JWTUtil.parseToken(token);
- // 校验token是否过期,如果过期了,需要提示过期重新登录
- checkTokenExpire(jwt);
- cacheAuth(jwt);
+// //请求消息头获取用户ID
+// String token = request.getHeader("token");
+// if (StrUtil.isBlank(token)) {
+// // 如果是swagger来的接口,说明这里是测试的,会伪造一个用户
+// if (StrUtil.isNotBlank(request.getHeader("Knife4j-Gateway-Code"))) {
+// cacheAuth(JWTUtil.parseToken(devActiveUser()));
+// return true;
+// } else {
+// throw new BusinessException("当前用户未登录", HttpStatus.UNAUTHORIZED.value());
+// }
+// }
+// JWT jwt = JWTUtil.parseToken(token);
+// // 校验token是否过期,如果过期了,需要提示过期重新登录
+// checkTokenExpire(jwt);
+// cacheAuth(jwt);
return true;
}
diff --git a/virtual-patient-common/src/main/java/com/supervision/config/MinioConfig.java b/virtual-patient-common/src/main/java/com/supervision/config/MinioConfig.java
new file mode 100644
index 00000000..92329f17
--- /dev/null
+++ b/virtual-patient-common/src/main/java/com/supervision/config/MinioConfig.java
@@ -0,0 +1,24 @@
+package com.supervision.config;
+
+import io.minio.MinioClient;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MinioConfig {
+
+ /**
+ * 创建基于Java端的MinioClient
+ */
+ @Bean
+ @ConditionalOnProperty(prefix = "minio",name = "url")
+ public MinioClient minioClient(MinioProperties minioProperties) {
+ return MinioClient.builder().endpoint(minioProperties.getUrl())
+ .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
+ .build();
+ }
+
+
+}
diff --git a/virtual-patient-common/src/main/java/com/supervision/config/MinioProperties.java b/virtual-patient-common/src/main/java/com/supervision/config/MinioProperties.java
new file mode 100644
index 00000000..d846f184
--- /dev/null
+++ b/virtual-patient-common/src/main/java/com/supervision/config/MinioProperties.java
@@ -0,0 +1,19 @@
+package com.supervision.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "minio")
+public class MinioProperties {
+
+ private String url;
+
+ private String accessKey;
+
+ private String secretKey;
+
+ private String bucketName;
+}
diff --git a/virtual-patient-common/src/main/java/com/supervision/util/MinioUtil.java b/virtual-patient-common/src/main/java/com/supervision/util/MinioUtil.java
new file mode 100644
index 00000000..69566704
--- /dev/null
+++ b/virtual-patient-common/src/main/java/com/supervision/util/MinioUtil.java
@@ -0,0 +1,85 @@
+package com.supervision.util;
+
+import com.supervision.config.MinioProperties;
+import io.minio.*;
+import io.minio.http.Method;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.InputStream;
+
+@Slf4j
+public class MinioUtil {
+ private static final MinioClient minioClient = SpringBeanUtil.getBean(MinioClient.class);
+
+ private static final String bucketName = SpringBeanUtil.getBean(MinioProperties.class).getBucketName();
+
+ static {
+ try {
+ if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
+
+ log.info("未找到bucket,自动建立");
+ minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * 上传一个文件
+ */
+ public static String uploadFile(InputStream stream, String objectName) throws Exception {
+ ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(objectName)
+ .stream(stream, -1, 10485760).build());
+ return objectWriteResponse.object();
+ }
+
+ /**
+ * 下载一个文件
+ */
+ public static InputStream download(String fileId) throws Exception {
+ return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileId).build());
+ }
+
+
+
+ /**
+ * 删除一个对象
+ */
+ public static void deleteObject(String fileId) throws Exception {
+ minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(fileId).build());
+ }
+
+
+
+
+ /**
+ * 获取文件信息
+ *
+ * @Param: [bucket, objectName]
+ * @return: java.lang.String
+ * @Author: MrFugui
+ * @Date: 2021/11/15
+ */
+ public static String getObjectInfo(String fileId) throws Exception {
+ return minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(fileId).build()).toString();
+ }
+
+ /**
+ * 生成一个给HTTP GET请求用的presigned URL。浏览器/移动端的客户端可以用这个URL进行下载,即使其所在的存储桶是私有的。
+ *
+ * @Param: [bucketName, objectName, expires]
+ * @return: java.lang.String
+ * @Author: MrFugui
+ * @Date: 2021/11/15
+ */
+ public static String getPresignedObjectUrl(String bucketName, String objectName, Integer expires) throws Exception {
+ GetPresignedObjectUrlArgs build = GetPresignedObjectUrlArgs
+ .builder().bucket(bucketName).object(objectName).expiry(expires).method(Method.GET).build();
+ return minioClient.getPresignedObjectUrl(build);
+ }
+
+
+
+}
diff --git a/virtual-patient-web/src/main/java/com/supervision/VirtualPatientApplication.java b/virtual-patient-web/src/main/java/com/supervision/VirtualPatientApplication.java
index adf816c6..58cf6d1d 100644
--- a/virtual-patient-web/src/main/java/com/supervision/VirtualPatientApplication.java
+++ b/virtual-patient-web/src/main/java/com/supervision/VirtualPatientApplication.java
@@ -3,6 +3,7 @@ package com.supervision;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.scheduling.annotation.EnableScheduling;
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
index a7b3e38a..02bb9969 100644
--- a/virtual-patient-web/src/main/java/com/supervision/controller/TestController.java
+++ b/virtual-patient-web/src/main/java/com/supervision/controller/TestController.java
@@ -7,9 +7,14 @@ import cn.hutool.json.JSONUtil;
import com.supervision.exception.BusinessException;
import com.supervision.model.ConfigPhysicalTool;
import com.supervision.service.ConfigPhysicalToolService;
+import com.supervision.util.MinioUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.*;
@RestController
@@ -86,6 +91,16 @@ public class TestController {
return signServer;
}
+ @PostMapping("testFileUpload")
+ public String testFileUpload(MultipartFile file) throws Exception {
+ return MinioUtil.uploadFile(file.getInputStream(), UUID.randomUUID().toString());
+ }
+
+ @PostMapping("downloadFile")
+ public InputStream downloadFile(String fileId) throws Exception {
+ return MinioUtil.download(fileId);
+ }
+
}
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
index 4de37f6c..894bc394 100644
--- a/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java
+++ b/virtual-patient-web/src/main/java/com/supervision/controller/UserController.java
@@ -133,18 +133,10 @@ public class UserController {
@ApiOperation("获取本机IP地址,用来给websocket使用")
@GetMapping("queryWebSocketUrl")
public String queryWebSocketUrl() {
- // 如果是本地开发环境,则获取本机IP地址
- if ("local".equals(active)) {
- String template = "ws://{}:{}/virtual-patient/";
- String localhostStr = NetUtil.getLocalhostStr();
- return StrUtil.format(template, localhostStr, port);
- } else {
- String template = "wss://{}:{}/virtual-patient-websocket/";
- if (StrUtil.isNotBlank(wsIp) && StrUtil.isNotBlank(wsPort)) {
- return StrUtil.format(template, wsIp, wsPort);
- }
+ String template = "wss://{}:{}/virtual-patient-websocket/";
+ if (StrUtil.isNotBlank(wsIp) && StrUtil.isNotBlank(wsPort)) {
+ return StrUtil.format(template, wsIp, wsPort);
}
-
throw new BusinessException("未获取到ws的nginx地址,请确认配置文件是否配置");
}
diff --git a/virtual-patient-web/src/main/resources/application-dev.yml b/virtual-patient-web/src/main/resources/application-dev.yml
index 1e13247e..e83815c3 100644
--- a/virtual-patient-web/src/main/resources/application-dev.yml
+++ b/virtual-patient-web/src/main/resources/application-dev.yml
@@ -51,6 +51,12 @@ spring:
port: 6379
password: 123456
+minio:
+ url: http://192.168.10.138:9002
+ accessKey: admin
+ secretKey: 12345678
+ bucketName: virtual-patient-bucket-dev
+
mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml
diff --git a/virtual-patient-web/src/main/resources/application-local.yml b/virtual-patient-web/src/main/resources/application-local.yml
index 665bfbae..31dca534 100644
--- a/virtual-patient-web/src/main/resources/application-local.yml
+++ b/virtual-patient-web/src/main/resources/application-local.yml
@@ -51,6 +51,11 @@ spring:
port: 6379
password: 123456
+minio:
+ url: http://192.168.10.138:9002
+ accessKey: admin
+ secretKey: 12345678
+ bucketName: virtual-patient-bucket-dev
mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml
@@ -72,4 +77,10 @@ human:
room-id: /getRoomId
text-driven: /text_driven
talk-status: /talkStatus
- resourceMaxNumber: 5
\ No newline at end of file
+ resourceMaxNumber: 5
+
+# local环境使用dev的
+ws:
+ # nginx的wss地址(如果是wss的,那么带不带s都可以访问)
+ nginx-ip: 192.168.10.138
+ nginx-port: 443
\ No newline at end of file