|
@@ -19,15 +19,16 @@ import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
+import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -202,28 +203,30 @@ public class DocumentAuthServiceImpl implements DocumentAuthService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Mono<JsonModel> downFile(Integer pdfId) {
|
|
|
- OssArchivePdf ossArchivePdf = documentAuthDao.findOssArchivePdfById(pdfId);
|
|
|
- if (ossArchivePdf != null) {
|
|
|
- try {
|
|
|
- // 创建OSSClient实例。
|
|
|
- OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
- File file = new File("src/main/resources/static/file");
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdir();
|
|
|
- }
|
|
|
- // 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
|
|
|
- ossClient.getObject(new GetObjectRequest(bucketName, ossArchivePdf.getOssName()), new File("src/main/resources/static/file/" + ossArchivePdf.getName()));
|
|
|
- // 关闭OSSClient。
|
|
|
- ossClient.shutdown();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return Mono.just(JsonModel.error(e.getMessage()));
|
|
|
+ public Mono<Void> downFile(Integer pdfId, ServerHttpRequest request, ServerHttpResponse response) {
|
|
|
+ try {
|
|
|
+ OssArchivePdf ossArchivePdf = documentAuthDao.findOssArchivePdfById(pdfId);
|
|
|
+ // 创建OSSClient实例。
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+ File file = new File("src/main/resources/static/file");
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdir();
|
|
|
}
|
|
|
- } else {
|
|
|
- return Mono.just(JsonModel.error("文件不存在"));
|
|
|
+ // 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
|
|
|
+ ossClient.getObject(new GetObjectRequest(bucketName, ossArchivePdf.getOssName()), new File("src/main/resources/static/file/" + ossArchivePdf.getName()));
|
|
|
+ // 关闭OSSClient。
|
|
|
+ ossClient.shutdown();
|
|
|
+ File pdfFile = new File("src/main/resources/static/file/" + ossArchivePdf.getName());
|
|
|
+ //输出文件名乱码问题处理
|
|
|
+ response.getHeaders().set(HttpHeaders.CONTENT_DISPOSITION,
|
|
|
+ "attachment; filename=" + new String(pdfFile.getName().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
|
|
+ ZeroCopyHttpOutputMessage zeroCopyResponse = (ZeroCopyHttpOutputMessage) response;
|
|
|
+ response.getHeaders().setContentType(MediaType.APPLICATION_PDF);
|
|
|
+ return zeroCopyResponse.writeWith(pdfFile, 0, pdfFile.length());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return Mono.error(e);
|
|
|
}
|
|
|
- return Mono.just(JsonModel.success(ossArchivePdf.getName()));
|
|
|
}
|
|
|
|
|
|
@Override
|