From 0dffefa0ba7f38d54852b3c3f97158df236bfe34 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 21 七月 2026 16:42:40 +0800
Subject: [PATCH] 【丽水】病人出院记录查询慢问题处理
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/QRCodeController.java | 85 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 80 insertions(+), 5 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/QRCodeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/QRCodeController.java
index ef46ef6..95945b0 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/QRCodeController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/QRCodeController.java
@@ -1,10 +1,12 @@
package com.ruoyi.web.controller.smartor;
import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.mchange.v2.uid.UidUtils;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.config.ServerConfig;
@@ -21,10 +23,17 @@
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
+import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.StringWriter;
+import java.net.URI;
import java.util.*;
@Slf4j
@@ -41,6 +50,11 @@
@Value("${ruoyi.profile}")
private String profile;
+
+ /**
+ * 鍏徃logo鍦╟lasspath涓殑璺緞锛屾墦鍖呰繘jar鍚庝换浣曠幆澧冮兘鑳借鍙栧埌
+ */
+ private static final String LOGO_CLASSPATH = "/images/hrslogo.png";
@Autowired
private ServerConfig serverConfig;
@@ -122,24 +136,85 @@
@PostMapping(value = "/getQRcode")
public AjaxResult getQRcode(@RequestParam("url") String url) {
log.info("鑾峰彇闂嵎浜岀淮鐮佺殑鍏ュ弬锛歿}", url);
- String uuid = UUID.randomUUID().toString().replace("-", "");
- String filePath = profile + "\\qrpath" + "\\" + uuid + ".png"; // 淇濆瓨浜岀淮鐮佸浘鍍忕殑鏂囦欢璺緞
+ // 灏濊瘯浠巙rl涓彁鍙杙鍙傛暟鐨勫�间綔涓哄浘鐗囧悕绉帮紝鍊间负绌哄垯鐢║UID
+ String fileName = UUID.randomUUID().toString().replace("-", "");
+ try {
+ URI uri = new URI(url);
+ String query = uri.getQuery();
+ if (query != null) {
+ for (String param : query.split("&")) {
+ String[] pair = param.split("=", 2);
+ if ("p".equals(pair[0]) && pair.length > 1 && !pair[1].isEmpty()) {
+ fileName = pair[1] + "-" + System.currentTimeMillis();
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.warn("瑙f瀽url涓殑p鍙傛暟澶辫触锛屼娇鐢║UID浣滀负鏂囦欢鍚�");
+ }
+ String filePath = profile + "\\qrpath" + "\\" + fileName + ".png"; // 淇濆瓨浜岀淮鐮佸浘鍍忕殑鏂囦欢璺緞
//鍒ゆ柇鏂囦欢澶规槸鍚﹀瓨鍦�
File file = new File(profile + "\\qrpath");
if (!file.exists()) {
file.mkdirs();
}
generateQRCode(url, filePath);
- return AjaxResult.success(serverConfig.getUrl() + "/profile/qrpath/" + uuid + ".png");
+ return AjaxResult.success(serverConfig.getUrl() + "/profile/qrpath/" + fileName + ".png");
}
private void generateQRCode(String url, String filePath) {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
try {
- BitMatrix bitMatrix = qrCodeWriter.encode(url, BarcodeFormat.QR_CODE, 500, 500);
+ // 浣跨敤楂樺閿欑骇鍒紙H绾э紝30%瀹归敊锛夛紝纭繚浜岀淮鐮佷腑闂村祵鍏ogo鍚庝粛鍙甯告壂鎻�
+ Map<EncodeHintType, Object> hints = new HashMap<>();
+ hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
+ hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
+ hints.put(EncodeHintType.MARGIN, 1);
+ BitMatrix bitMatrix = qrCodeWriter.encode(url, BarcodeFormat.QR_CODE, 500, 500, hints);
+
+ // 灏咮itMatrix杞负浜屽�糂ufferedImage锛堥粦鐧斤級
+ BufferedImage binaryImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
+
+ // 鍒涘缓RGB褰╄壊鍥惧儚锛屾妸浜岀淮鐮佺敾涓婂幓锛屽惁鍒欏悗缁粯鍒秎ogo浼氫涪澶遍鑹�
+ BufferedImage qrImage = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = qrImage.createGraphics();
+ graphics.setColor(Color.WHITE);
+ graphics.fillRect(0, 0, 500, 500);
+ graphics.drawImage(binaryImage, 0, 0, null);
+
+ // 浠巆lasspath璇诲彇logo骞剁粯鍒跺埌浜岀淮鐮佷腑闂�
+ try (InputStream logoStream = this.getClass().getResourceAsStream(LOGO_CLASSPATH)) {
+ if (logoStream != null) {
+ BufferedImage logoImage = ImageIO.read(logoStream);
+
+ // 璁$畻logo灏哄锛岃涓轰簩缁寸爜鐨�1/5
+ int logoWidth = qrImage.getWidth() / 5;
+ int logoHeight = qrImage.getHeight() / 5;
+
+ // 璁$畻logo灞呬腑浣嶇疆
+ int logoX = (qrImage.getWidth() - logoWidth) / 2;
+ int logoY = (qrImage.getHeight() - logoHeight) / 2;
+
+ // 缁樺埗鐧借壊鍦嗚鑳屾櫙锛岃logo鏇寸獊鍑�
+ int padding = 6;
+ graphics.setColor(Color.WHITE);
+ graphics.fillRoundRect(logoX - padding, logoY - padding, logoWidth + padding * 2, logoHeight + padding * 2, 10, 10);
+
+ // 缁樺埗logo
+ graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics.drawImage(logoImage, logoX, logoY, logoWidth, logoHeight, null);
+ } else {
+ log.warn("classpath涓湭鎵惧埌浜岀淮鐮乴ogo: {}", LOGO_CLASSPATH);
+ }
+ }
+ graphics.dispose();
+
+ // 杈撳嚭鏈�缁堝浘鐗�
File outputFile = new File(filePath);
- MatrixToImageWriter.writeToPath(bitMatrix, "PNG", outputFile.toPath());
+ ImageIO.write(qrImage, "PNG", outputFile);
} catch (WriterException | IOException e) {
e.printStackTrace();
}
--
Gitblit v1.9.3