From b32dba6d0c069e4d1a416358501b441865714ab3 Mon Sep 17 00:00:00 2001 From: Fancy <Fancy.fx@outlook.com> Date: 星期二, 20 八月 2024 17:22:10 +0800 Subject: [PATCH] order manage --- pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/util/QrCodeUtil.java | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 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..4fae5bf 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); } -- Gitblit v1.8.0