Merge remote-tracking branch 'origin/master'
# Conflicts: # zkh-web/pom.xml
This commit is contained in:
+20
-1
@@ -14,6 +14,14 @@
|
|||||||
<description>Common utilities and base classes for ZKH framework</description>
|
<description>Common utilities and base classes for ZKH framework</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.validation</groupId>
|
||||||
|
<artifactId>jakarta.validation-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.annotation</groupId>
|
||||||
|
<artifactId>jakarta.annotation-api</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.persistence</groupId>
|
<groupId>jakarta.persistence</groupId>
|
||||||
<artifactId>jakarta.persistence-api</artifactId>
|
<artifactId>jakarta.persistence-api</artifactId>
|
||||||
@@ -32,12 +40,23 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-common</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.8.14</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.14.1</version>
|
||||||
|
<configuration>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
|||||||
@@ -46,6 +46,9 @@
|
|||||||
<version>1.18.42</version>
|
<version>1.18.42</version>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
+3
-6
@@ -39,12 +39,6 @@
|
|||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
<version>5.8.41</version>
|
<version>5.8.41</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springdoc</groupId>
|
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
|
||||||
<version>2.8.14</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -60,6 +54,9 @@
|
|||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -25,49 +26,49 @@ import java.nio.file.Paths;
|
|||||||
@RestController("_fileController")
|
@RestController("_fileController")
|
||||||
@RequestMapping("/file")
|
@RequestMapping("/file")
|
||||||
public class FileController {
|
public class FileController {
|
||||||
private final static Logger log = LoggerFactory.getLogger(FileController.class);
|
private final static Logger log = LoggerFactory.getLogger(FileController.class);
|
||||||
private final IFileUploadService fileUploadService;
|
private final IFileUploadService fileUploadService;
|
||||||
private final IFileDownloadService fileDownloadService;
|
private final IFileDownloadService fileDownloadService;
|
||||||
|
|
||||||
public FileController(IFileUploadService fileUploadService, IFileDownloadService fileDownloadService) {
|
public FileController(IFileUploadService fileUploadService, IFileDownloadService fileDownloadService) {
|
||||||
this.fileUploadService = fileUploadService;
|
this.fileUploadService = fileUploadService;
|
||||||
this.fileDownloadService = fileDownloadService;
|
this.fileDownloadService = fileDownloadService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "上传文件", description = "上传文件到服务器")
|
@Operation(summary = "上传文件", description = "上传文件到服务器")
|
||||||
@ApiResponse(responseCode = "200", description = "上传成功",
|
@ApiResponse(responseCode = "200", description = "上传成功",
|
||||||
content = @Content(mediaType = "application/json",
|
content = @Content(mediaType = "application/json",
|
||||||
schema = @Schema(implementation = R.class)))
|
schema = @Schema(implementation = R.class)))
|
||||||
@PostMapping
|
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
public R<FileInfo> upload(
|
public R<FileInfo> upload(
|
||||||
@Parameter(description = "要上传的文件", required = true)
|
@Parameter(description = "要上传的文件", required = true, name = "file")
|
||||||
MultipartFile file) {
|
@RequestPart("file") MultipartFile file) {
|
||||||
try {
|
try {
|
||||||
FileInfo upload = fileUploadService.upload(file);
|
FileInfo upload = fileUploadService.upload(file);
|
||||||
return R.success(upload);
|
return R.success(upload);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("上传失败", e);
|
log.error("上传失败", e);
|
||||||
return R.serverError("上传失败");
|
return R.serverError("上传失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "下载文件", description = "根据文件路径下载文件")
|
@Operation(summary = "下载文件", description = "根据文件路径下载文件")
|
||||||
@ApiResponse(responseCode = "200", description = "下载成功")
|
@ApiResponse(responseCode = "200", description = "下载成功")
|
||||||
@ApiResponse(responseCode = "404", description = "文件未找到")
|
@ApiResponse(responseCode = "404", description = "文件未找到")
|
||||||
@GetMapping("{path}")
|
@GetMapping
|
||||||
public ResponseEntity<Resource> download(
|
public ResponseEntity<Resource> download(
|
||||||
@Parameter(description = "文件路径", required = true)
|
@Parameter(description = "文件路径", required = true)
|
||||||
@PathVariable String path) {
|
@RequestParam("path") String path) {
|
||||||
Path normalize = Paths.get(path).normalize();
|
Path normalize = Paths.get(path).normalize();
|
||||||
try {
|
try {
|
||||||
Resource download = fileDownloadService.download(normalize.toString());
|
Resource download = fileDownloadService.download(normalize.toString());
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.header("Content-Disposition", "attachment; filename=\"" + download.getFilename() + "\"")
|
.header("Content-Disposition", "attachment; filename=\"" + download.getFilename() + "\"")
|
||||||
.body(download);
|
.body(download);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("下载失败", e);
|
log.error("下载失败", e);
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.notFound().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,16 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.14.1</version>
|
||||||
|
<configuration>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
|||||||
+3
-5
@@ -43,11 +43,6 @@
|
|||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springdoc</groupId>
|
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
|
||||||
<version>2.8.14</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -63,6 +58,9 @@
|
|||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-parameters</arg>
|
||||||
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
Reference in New Issue
Block a user