From ebae0c1137ba96d38e5b2323577129d2c9ff2e6e Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 22 五月 2025 09:45:59 +0800 Subject: [PATCH] 1、优化配置文件; 2、优化ID生成器代码; 3、修改注释; 4、修改权限初始化时算法; 5、导出Excel文件功能归为一个新类; 6、工站数据库存入验空修改; --- pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/util/QrCodeUtil.java | 35 ++++++++++++++++++----------------- 1 files changed, 18 insertions(+), 17 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..6c5e9a6 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); } @@ -58,18 +71,6 @@ return ""; } - public static void downloadExcel(HttpServletResponse response, String fileName, String sheetName, List<Converter> list){ - if(CollectionUtils.isEmpty(list)){ - return; - } - try{ - response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - response.setCharacterEncoding("utf-8"); - fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); - 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); - } - } + + } \ No newline at end of file -- Gitblit v1.8.0