From af8b0ddeeb5fc71f5099e6be44dc9d3064a3b243 Mon Sep 17 00:00:00 2001
From: 刘小明 <liuxm_a@163.com>
Date: 星期四, 29 八月 2024 16:49:59 +0800
Subject: [PATCH] 优化查询全部工站(id以string格式传给前端)
---
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/util/QrCodeUtil.java | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/util/QrCodeUtil.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/util/QrCodeUtil.java
index 877c76a..b14a3ae 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/util/QrCodeUtil.java
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/util/QrCodeUtil.java
@@ -11,8 +11,7 @@
import org.springframework.core.io.ClassPathResource;
import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.net.URLEncoder;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@@ -32,8 +31,22 @@
public static byte[] genQrCode(String code) throws IOException, WriterException {
File logoFile = logoCache.computeIfAbsent(LOGO_PATH, key -> {
try {
+ // 浣跨敤ClassPathResource鑾峰彇璧勬簮鐨勮緭鍏ユ祦
ClassPathResource resource = new ClassPathResource(key);
- return resource.getFile();
+ // 鍒涘缓涓�涓复鏃舵枃浠舵潵淇濆瓨璧勬簮鍐呭(閬垮厤澶勭悊宓屽jar鏂囦欢鏃舵壘涓嶅埌鏂囦欢)
+ File tempFile = File.createTempFile("logo", ".png");
+ try (InputStream in = resource.getInputStream();
+ OutputStream out = new FileOutputStream(tempFile)) {
+ // 浠庤緭鍏ユ祦澶嶅埗鍒颁复鏃舵枃浠�
+ byte[] buffer = new byte[1024];
+ int bytesRead;
+ while ((bytesRead = in.read(buffer)) != -1) {
+ out.write(buffer, 0, bytesRead);
+ }
+ // 杩斿洖涓存椂鏂囦欢
+ tempFile.deleteOnExit(); // 鑷姩鍒犻櫎涓存椂鏂囦欢锛堝綋JVM閫�鍑烘椂锛�
+ return tempFile;
+ }
} catch (IOException e) {
throw new RuntimeException("鍔犺浇Logo鍥剧墖澶辫触", e);
}
@@ -69,7 +82,7 @@
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), list.get(0).getClass()).sheet(sheetName).doWrite(list);
}catch (Exception e){
- log.error("瀵煎嚭浜у搧淇℃伅寮傚父", e);
+ log.error("瀵煎嚭{}寮傚父",sheetName,e);
}
}
}
\ No newline at end of file
--
Gitblit v1.8.0