|
|
@@ -1,5 +1,8 @@
|
|
|
package cn.start.tz.module.pressure2.controller.app.taskorderitemreport;
|
|
|
|
|
|
+import cn.start.tz.framework.common.pojo.CommonResult;
|
|
|
+import cn.start.tz.framework.ratelimiter.core.annotation.RateLimiter;
|
|
|
+import cn.start.tz.module.infra.api.file.FileApi;
|
|
|
import cn.start.tz.module.pressure2.framework.appauth.core.annotation.AppAuth;
|
|
|
import cn.start.tz.module.pressure2.controller.admin.pipetaskorderinput.vo.PipeTaskOrderInputPrintReqVO;
|
|
|
import cn.start.tz.module.pressure2.controller.admin.reporttemplate.vo.ReportMockPreviewVO;
|
|
|
@@ -98,4 +101,60 @@ public class PipeAppReportTemplateController {
|
|
|
}
|
|
|
response.getOutputStream().write(bos.toByteArray());
|
|
|
}
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FileApi fileApi;
|
|
|
+
|
|
|
+ @PostMapping("/image/{imageUrl}")
|
|
|
+ @Operation(summary = "通用文件获取(图片/视频/PDF等)")
|
|
|
+ @PermitAll
|
|
|
+ @RateLimiter
|
|
|
+ public void printFromPdf(HttpServletResponse response, @PathVariable String imageUrl) throws Exception {
|
|
|
+ CommonResult<byte[]> file = fileApi.getFileByPath(imageUrl);
|
|
|
+ byte[] data = file.getData();
|
|
|
+
|
|
|
+ // 根据文件后缀动态设置 Content-Type
|
|
|
+ String contentType = getContentType(imageUrl);
|
|
|
+ response.setContentType(contentType);
|
|
|
+
|
|
|
+ // 图片类型内联显示,其他类型触发下载
|
|
|
+ if (contentType.startsWith("image/")) {
|
|
|
+ response.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(extractFileName(imageUrl), StandardCharsets.UTF_8));
|
|
|
+ } else {
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(extractFileName(imageUrl), StandardCharsets.UTF_8));
|
|
|
+ }
|
|
|
+
|
|
|
+ response.getOutputStream().write(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据文件后缀返回对应的 MIME 类型
|
|
|
+ */
|
|
|
+ private String getContentType(String fileUrl) {
|
|
|
+ String lowerUrl = fileUrl.toLowerCase();
|
|
|
+ if (lowerUrl.endsWith(".png")) return "image/png";
|
|
|
+ if (lowerUrl.endsWith(".jpg") || lowerUrl.endsWith(".jpeg")) return "image/jpeg";
|
|
|
+ if (lowerUrl.endsWith(".gif")) return "image/gif";
|
|
|
+ if (lowerUrl.endsWith(".webp")) return "image/webp";
|
|
|
+ if (lowerUrl.endsWith(".bmp")) return "image/bmp";
|
|
|
+ if (lowerUrl.endsWith(".svg")) return "image/svg+xml";
|
|
|
+ if (lowerUrl.endsWith(".mp4")) return "video/mp4";
|
|
|
+ if (lowerUrl.endsWith(".mov")) return "video/quicktime";
|
|
|
+ if (lowerUrl.endsWith(".avi")) return "video/x-msvideo";
|
|
|
+ if (lowerUrl.endsWith(".pdf")) return "application/pdf";
|
|
|
+ if (lowerUrl.endsWith(".doc")) return "application/msword";
|
|
|
+ if (lowerUrl.endsWith(".docx")) return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
|
+ if (lowerUrl.endsWith(".xls")) return "application/vnd.ms-excel";
|
|
|
+ if (lowerUrl.endsWith(".xlsx")) return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
|
+ // 默认按图片处理
|
|
|
+ return "image/png";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从路径中提取文件名
|
|
|
+ */
|
|
|
+ private String extractFileName(String fileUrl) {
|
|
|
+ int lastSlash = fileUrl.lastIndexOf('/');
|
|
|
+ return lastSlash >= 0 ? fileUrl.substring(lastSlash + 1) : fileUrl;
|
|
|
+ }
|
|
|
}
|