diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 13e1289..4e5dbd0 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -42,7 +42,7 @@ paths: code: 0 msg: "success" data: - url: "/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10" + url: "http://localhost:6666/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10" fileName: "annualReport.docx" "400": description: 参数校验失败(exportId 为空 / businessData 为空) @@ -175,8 +175,9 @@ components: properties: url: type: string - description: 文件下载路径(pathname only,无 origin) - example: "/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10" + format: uri + description: 文件下载 URL(由 gmp.download-origin 配置 + 路径组成,未配置则只返回路径) + example: "http://localhost:6666/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10" fileName: type: string description: 文件名 diff --git a/src/main/java/com/gmp/mock/controller/DocxController.java b/src/main/java/com/gmp/mock/controller/DocxController.java index c892730..3cfbcd3 100644 --- a/src/main/java/com/gmp/mock/controller/DocxController.java +++ b/src/main/java/com/gmp/mock/controller/DocxController.java @@ -2,6 +2,7 @@ package com.gmp.mock.controller; import jakarta.validation.Valid; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -26,10 +27,13 @@ public class DocxController { private final DocxService docxService; private final FileCacheService fileCache; + private final String downloadOrigin; - public DocxController(DocxService docxService, FileCacheService fileCache) { + public DocxController(DocxService docxService, FileCacheService fileCache, + @Value("${gmp.download-origin:}") String downloadOrigin) { this.docxService = docxService; this.fileCache = fileCache; + this.downloadOrigin = downloadOrigin; } /** @@ -51,7 +55,9 @@ public class DocxController { ) { CachedResult result = docxService.export(request.getExportId(), request.getBusinessData()); - String url = "/api/docx/download?id=" + result.key(); + String url = downloadOrigin.isBlank() + ? "/api/docx/download?id=" + result.key() + : downloadOrigin + "/api/docx/download?id=" + result.key(); ExportResultData data = new ExportResultData(url, result.fileName()); return ResponseEntity.ok(ApiResponse.ok(data)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9a00a0f..e39ef9f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,3 +4,6 @@ server: spring: application: name: gmp-mock-service + +gmp: + download-origin: http://193.112.146.124:6666