From a65937bb7d85168af8256f917aad1aa12c0b8c1d Mon Sep 17 00:00:00 2001
From: cuijian <cuijian@xalxzn.com>
Date: 星期三, 18 六月 2025 13:32:55 +0800
Subject: [PATCH] 入库打印二维码

---
 lxzn-module-tms/src/main/java/org/jeecg/modules/tms/utils/QrCodePrinterUtils.java              |  130 ++++++++++++++++++--------------
 lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java |    4 
 lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/InboundOrderController.java     |   12 +-
 lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IInboundOrderService.java          |    7 +
 lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/InboundOrderServiceImpl.java  |   71 +++++++++++++++++
 5 files changed, 156 insertions(+), 68 deletions(-)

diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/InboundOrderController.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/InboundOrderController.java
index 71e4a00..679a554 100644
--- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/InboundOrderController.java
+++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/controller/InboundOrderController.java
@@ -252,17 +252,17 @@
 	 @AutoLog(value = "宸ュ叿鍏ュ簱-鏂板鍏ュ簱")
 	 @ApiOperation(value = "宸ュ叿鍏ュ簱-鏂板鍏ュ簱", notes = "宸ュ叿鍏ュ簱-鏂板鍏ュ簱")
 	 @PostMapping("/addInStorage")
-	 public Result<?> addInStorage(@RequestBody JSONObject jSONObject) {
-		inboundOrderService.addInStorage(jSONObject);
-		return Result.OK("鎿嶄綔鎴愬姛");
+	 public Result<List<Map<String,String>>> addInStorage(@RequestBody JSONObject jSONObject) {
+		 List<Map<String,String>> result  = inboundOrderService.addInStorage(jSONObject);
+		return Result.OK(result);
 	 }
 
 	 @AutoLog(value = "宸ュ叿鍏ュ簱-鐢宠鍗曞叆搴�")
 	 @ApiOperation(value = "宸ュ叿鍏ュ簱-鐢宠鍗曞叆搴�", notes = "宸ュ叿鍏ュ簱-鐢宠鍗曞叆搴�")
 	 @PostMapping("/addApplyInStorage")
-	 public Result<?> addApplyInStorage(@RequestBody JSONObject jSONObject) {
-		 inboundOrderService.addApplyInStorage(jSONObject);
-		 return Result.OK("鎿嶄綔鎴愬姛");
+	 public Result<List<Map<String,String>>> addApplyInStorage(@RequestBody JSONObject jSONObject) {
+		 List<Map<String,String>> result  = inboundOrderService.addApplyInStorage(jSONObject);
+		 return Result.OK(result);
 	 }
 
 }
diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IInboundOrderService.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IInboundOrderService.java
index e892396..02b858f 100644
--- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IInboundOrderService.java
+++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/IInboundOrderService.java
@@ -6,6 +6,9 @@
 import org.jeecg.modules.tms.entity.dto.InboundOrderFlowDto;
 import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * @Description: 鍏ュ簱鐢宠鍗�
  * @Author: jeecg-boot
@@ -18,7 +21,7 @@
 
     void approvalProcess(InboundOrderFlowDto inboundOrderFlowDto);
 
-    void addInStorage(JSONObject jSONObject);
+    List<Map<String,String>> addInStorage(JSONObject jSONObject);
 
-    void addApplyInStorage(JSONObject jSONObject);
+    List<Map<String,String>> addApplyInStorage(JSONObject jSONObject);
 }
diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/InboundOrderServiceImpl.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/InboundOrderServiceImpl.java
index ea6a3a7..b9e31ed 100644
--- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/InboundOrderServiceImpl.java
+++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/InboundOrderServiceImpl.java
@@ -24,6 +24,7 @@
 import org.jeecg.modules.tms.entity.vo.InboundDetailVo;
 import org.jeecg.modules.tms.mapper.InboundOrderMapper;
 import org.jeecg.modules.tms.service.*;
+import org.jeecg.modules.tms.utils.QrCodePrinterUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -216,9 +217,12 @@
     }
 
     @Override
-    public void addInStorage(JSONObject jSONObject) {
+    public List<Map<String,String>> addInStorage(JSONObject jSONObject) {
         String inStorehouseType = jSONObject.getString("inStorehouseType");
         String locationCodeId = jSONObject.getString("locationCodeId");
+        //浜岀淮鐮佹墦鍗板垪琛�
+        List<Map<String,String>> results = new ArrayList<>();
+        List<String> contentList = new ArrayList<>();
         String classifyId = jSONObject.getString("classifyId");
         Date inboundTime = jSONObject.getDate("inboundTime");
         //鑾峰彇鍏ュ簱鏄庣粏
@@ -276,6 +280,7 @@
                         //澧炲姞搴撳瓨鏄庣粏
                         ToolLedgerDetail toolLedgerDetail = new ToolLedgerDetail();
                         toolLedgerDetail.setToolCode(inboundDetailVo.getToolCodeId());
+                        toolLedgerDetail.setPositionCode(locationCodeId);
                         toolLedgerDetail.setToolId(inboundDetailVo.getToolCode()+"-"+result);
                         toolLedgerDetail.setQuantity(BigDecimal.ONE);
                         toolLedgerDetail.setRemainingPercentage(BigDecimal.ONE);
@@ -284,7 +289,20 @@
                         //鏇存柊褰撳墠缂栫爜
                         newBaseTools.setCurrentCode(result);
                         baseToolsService.updateById(newBaseTools);
+                        //鎵撳嵃浜岀淮鐮�
+                        contentList.add(inboundDetailVo.getToolCode()+"-"+result);
                     }
+                    //鎵撳嵃浜岀淮鐮侊紝鏆傛椂娉ㄩ噴锛屽緟鐜板満璋冭瘯鎵撴爣鏈�
+//                    for(String content : contentList){
+//                        Map<String,String> result = new HashMap<>();
+//                        result.put("content",content);
+//                        result.put("image", QrCodePrinterUtils.generateBacthQRCode(content, 200, 200));
+//                        // 鐢熸垚浜岀淮鐮佸浘鐗囷紙Base64锛�
+//                        results.add(result);
+//                    }
+                    Map<String,String> result = new HashMap<>();
+                    result.put("content","淇濆瓨鎴愬姛");
+                    results.add(result);
                     //涓嶇鍒版妸
                 }else {
                     //淇濆瓨鍏ュ簱娴佹按
@@ -302,12 +320,17 @@
                         ToolLedgerDetail newToolLedgerDetail = new ToolLedgerDetail();
                         newToolLedgerDetail.setToolCode(inboundDetailVo.getToolCodeId());
                         newToolLedgerDetail.setQuantity(inboundDetailVo.getInStorageQuantity());
+                        newToolLedgerDetail.setPositionCode(locationCodeId);
                         newToolLedgerDetail.setStatus("1");
                         toolLedgerDetailService.save(newToolLedgerDetail);
                     }else {
                         toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().add(inboundDetailVo.getInStorageQuantity()));
+                        toolLedgerDetail.setPositionCode(locationCodeId);
                         toolLedgerDetailService.updateById(toolLedgerDetail);
                     }
+                    Map<String,String> result = new HashMap<>();
+                    result.put("content","淇濆瓨鎴愬姛");
+                    results.add(result);
                 }
             }
             //褰掕繕鍏ュ簱
@@ -330,6 +353,7 @@
                             .eq(ToolLedgerDetail::getToolId,inboundDetailVo.getOnlyCode()).one();
                     toolLedgerDetail.setQuantity(BigDecimal.ONE);
                     toolLedgerDetail.setRemainingPercentage(BigDecimal.ONE);
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetail.setStatus("1");
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
@@ -347,6 +371,7 @@
                     //澧炲姞搴撳瓨鏄庣粏鍙敤搴撳瓨锛屼慨鏀圭姸鎬�
                     ToolLedgerDetail toolLedgerDetail = toolLedgerDetailService.lambdaQuery().eq(ToolLedgerDetail::getToolCode,inboundDetailVo.getToolCodeId()).one();
                     toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().add(inboundDetailVo.getInStorageQuantity()));
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetail.setStatus("1");
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
@@ -361,6 +386,9 @@
                 }
 
             }
+            Map<String,String> result = new HashMap<>();
+            result.put("content","淇濆瓨鎴愬姛");
+            results.add(result);
         }else if("5".equals(inStorehouseType)){
             //寰幆鏂板鏄庣粏
             for(InboundDetailVo inboundDetailVo : inStoreDetailList) {
@@ -380,6 +408,7 @@
                             .eq(ToolLedgerDetail::getToolId,inboundDetailVo.getOnlyCode()).one();
                     toolLedgerDetail.setQuantity(BigDecimal.ONE);
                     toolLedgerDetail.setRemainingPercentage(BigDecimal.ONE);
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetail.setStatus("1");
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
@@ -397,6 +426,7 @@
                     //澧炲姞搴撳瓨鏄庣粏鍙敤搴撳瓨锛屼慨鏀圭姸鎬�
                     ToolLedgerDetail toolLedgerDetail = toolLedgerDetailService.lambdaQuery().eq(ToolLedgerDetail::getToolCode,inboundDetailVo.getToolCodeId()).one();
                     toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().add(inboundDetailVo.getInStorageQuantity()));
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetail.setStatus("1");
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
@@ -411,13 +441,20 @@
                 }
 
             }
+            Map<String,String> result = new HashMap<>();
+            result.put("content","淇濆瓨鎴愬姛");
+            results.add(result);
         }
+        return results;
     }
 
     @Override
-    public void addApplyInStorage(JSONObject jSONObject) {
+    public List<Map<String,String>> addApplyInStorage(JSONObject jSONObject) {
         String inStorehouseType = jSONObject.getString("inStorehouseType");
         String locationCodeId = jSONObject.getString("locationCodeId");
+        //浜岀淮鐮佹墦鍗板垪琛�
+        List<Map<String,String>> results = new ArrayList<>();
+        List<String> contentList = new ArrayList<>();
         //鍏ュ簱鐢宠鍗昳d
         String orderId = jSONObject.getString("orderId");
         //鑾峰彇鍏ュ簱鏄庣粏
@@ -478,12 +515,26 @@
                         toolLedgerDetail.setToolId(inboundDetailVo.getToolCode()+"-"+result);
                         toolLedgerDetail.setQuantity(BigDecimal.ONE);
                         toolLedgerDetail.setRemainingPercentage(BigDecimal.ONE);
+                        toolLedgerDetail.setPositionCode(locationCodeId);
                         toolLedgerDetail.setStatus("1");
                         toolLedgerDetailService.save(toolLedgerDetail);
                         //鏇存柊褰撳墠缂栫爜
                         newBaseTools.setCurrentCode(result);
                         baseToolsService.updateById(newBaseTools);
+                        //鎵撳嵃浜岀淮鐮�
+                        contentList.add(inboundDetailVo.getToolCode()+"-"+result);
                     }
+                    //鎵撳嵃浜岀淮鐮侊紝鏆傛椂娉ㄩ噴锛屽緟鐜板満楠岃瘉鎵撴爣鏈�
+//                    for(String content : contentList){
+//                        Map<String,String> result = new HashMap<>();
+//                        result.put("content",content);
+//                        result.put("image", QrCodePrinterUtils.generateBacthQRCode(content, 200, 200));
+//                        // 鐢熸垚浜岀淮鐮佸浘鐗囷紙Base64锛�
+//                        results.add(result);
+//                    }
+                    Map<String,String> result = new HashMap<>();
+                    result.put("content","淇濆瓨鎴愬姛");
+                    results.add(result);
                     //涓嶇鍒版妸
                 }else {
                     //淇濆瓨鍏ュ簱娴佹按
@@ -502,12 +553,17 @@
                         ToolLedgerDetail newToolLedgerDetail = new ToolLedgerDetail();
                         newToolLedgerDetail.setToolCode(inboundDetailVo.getToolCodeId());
                         newToolLedgerDetail.setQuantity(inboundDetailVo.getInStorageQuantity());
+                        newToolLedgerDetail.setPositionCode(locationCodeId);
                         newToolLedgerDetail.setStatus("1");
                         toolLedgerDetailService.save(newToolLedgerDetail);
                     }else {
                         toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().add(inboundDetailVo.getInStorageQuantity()));
+                        toolLedgerDetail.setPositionCode(locationCodeId);
                         toolLedgerDetailService.updateById(toolLedgerDetail);
                     }
+                    Map<String,String> result = new HashMap<>();
+                    result.put("content","淇濆瓨鎴愬姛");
+                    results.add(result);
                 }
                 //鏇存敼鏄庣粏鍏ュ簱鐘舵�佸強瀹為檯鍏ュ簱鏁伴噺
                 InboundDetail inboundDetail = inboundDetailService.getById(inboundDetailVo.getId());
@@ -535,6 +591,7 @@
                             .eq(ToolLedgerDetail::getToolId,inboundDetailVo.getOnlyCode()).one();
                     toolLedgerDetail.setQuantity(BigDecimal.ONE);
                     toolLedgerDetail.setRemainingPercentage(BigDecimal.ONE);
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetail.setStatus("1");
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
@@ -554,6 +611,7 @@
                     ToolLedgerDetail toolLedgerDetail = toolLedgerDetailService.lambdaQuery().eq(ToolLedgerDetail::getToolCode,inboundDetailVo.getToolCodeId()).one();
                     toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().add(inboundDetailVo.getInStorageQuantity()));
                     toolLedgerDetail.setStatus("1");
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
                     InStoreDetail inStoreDetail = new InStoreDetail();
@@ -572,6 +630,9 @@
                 inboundDetail.setInActualCount(inboundDetailVo.getInStorageQuantity());
                 inboundDetailService.updateById(inboundDetail);
             }
+            Map<String,String> result = new HashMap<>();
+            result.put("content","淇濆瓨鎴愬姛");
+            results.add(result);
         }else if("5".equals(inStorehouseType)){
             //寰幆鏂板鏄庣粏
             for(InboundDetailVo inboundDetailVo : inStoreDetailList) {
@@ -591,6 +652,7 @@
                             .eq(ToolLedgerDetail::getToolId,inboundDetailVo.getOnlyCode()).one();
                     toolLedgerDetail.setQuantity(BigDecimal.ONE);
                     toolLedgerDetail.setRemainingPercentage(BigDecimal.ONE);
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetail.setStatus("1");
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
@@ -610,6 +672,7 @@
                     ToolLedgerDetail toolLedgerDetail = toolLedgerDetailService.lambdaQuery().eq(ToolLedgerDetail::getToolCode,inboundDetailVo.getToolCodeId()).one();
                     toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().add(inboundDetailVo.getInStorageQuantity()));
                     toolLedgerDetail.setStatus("1");
+                    toolLedgerDetail.setPositionCode(locationCodeId);
                     toolLedgerDetailService.updateById(toolLedgerDetail);
                     //淇濆瓨鍏ュ簱娴佹按
                     InStoreDetail inStoreDetail = new InStoreDetail();
@@ -628,6 +691,9 @@
                 inboundDetail.setInActualCount(inboundDetailVo.getInStorageQuantity());
                 inboundDetailService.updateById(inboundDetail);
             }
+            Map<String,String> result = new HashMap<>();
+            result.put("content","淇濆瓨鎴愬姛");
+            results.add(result);
         }
         //鏇存敼鐢宠鍗曞叆搴撶姸鎬�
         InboundOrder inboundOrder = this.getById(orderId);
@@ -639,6 +705,7 @@
             inboundOrder.setInStatus("2");
         }
         this.updateById(inboundOrder);
+        return results;
     }
 
     private LoginUser getCurrentUser() {
diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java
index 2ef6f18..2c06432 100644
--- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java
+++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java
@@ -388,9 +388,9 @@
 		Map<String, BigDecimal> outBoundRequestMap = outBoundRequestList.stream()
 				.collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, OutBoundRequestDto::getOutboundQuantity));
 		Map<String, BigDecimal> ratedLifeMap = outBoundRequestList.stream()
-				.collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, dto->dto.getRatedLife() != null ? dto.getRatedLife() : null));
+				.collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, dto->dto.getRatedLife() != null ? dto.getRatedLife() : BigDecimal.ZERO));
 		Map<String, BigDecimal> useLifeMap = outBoundRequestList.stream()
-				.collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, dto->dto.getUseLife() != null ? dto.getUseLife() : null));
+				.collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, dto->dto.getUseLife() != null ? dto.getUseLife() : BigDecimal.ZERO));
 		//澶勭悊搴撳瓨鍙拌处鍙婂彴璐︽槑缁�
 		Map<String, ToolLedger> toolLedgerMap = toolLedgerService.list(new LambdaQueryWrapper<ToolLedger>().in(ToolLedger::getToolId, toolIdList)).stream()
 				.collect(Collectors.toMap(ToolLedger::getToolId, item -> item, (k1, k2) -> k1));
diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/utils/QrCodePrinterUtils.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/utils/QrCodePrinterUtils.java
index bde5895..2c92a36 100644
--- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/utils/QrCodePrinterUtils.java
+++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/utils/QrCodePrinterUtils.java
@@ -1,74 +1,92 @@
 package org.jeecg.modules.tms.utils;
 
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.MultiFormatWriter;
+import com.google.zxing.client.j2se.MatrixToImageWriter;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.QRCodeWriter;
+import liquibase.pro.packaged.S;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
 import javax.print.*;
 import javax.print.attribute.HashPrintRequestAttributeSet;
 import javax.print.attribute.PrintRequestAttributeSet;
 import java.awt.print.*;
 import java.awt.image.BufferedImage;
-import java.awt.*;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.*;
 
-public class QrCodePrinterUtils implements Printable {
+@RestController
+@RequestMapping("/tms/qyCode")
+@Slf4j
+public class QrCodePrinterUtils{
 
-    private final BufferedImage image;
+    @GetMapping("/generate")
+    public Result<Map<String, String>> generateQrCode() throws Exception {
+        String content = "Q201204330002-0001";
+        // 鐢熸垚浜岀淮鐮佸浘鐗囷紙Base64锛�
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        generateQRCodeImage(content, 200, 200, os);
+        String base64Img = "data:image/png;base64," + Base64.getEncoder().encodeToString(os.toByteArray());
 
-    public QrCodePrinterUtils(BufferedImage image) {
-        this.image = image;
+        // 杩斿洖缁撴灉
+        Map<String, String> result = new HashMap<>();
+        result.put("image", base64Img);
+        result.put("content", content);
+        return Result.OK(result);
     }
 
-    /**
-     * 鎵撳嵃浜岀淮鐮�
-     */
-    public void print() {
-        PrinterJob job = PrinterJob.getPrinterJob();
-        job.setPrintable(this);
-
-        // 寮瑰嚭鎵撳嵃瀵硅瘽妗嗭紙鍙�夛級
-        if (job.printDialog()) {
-            try {
-                job.print();
-            } catch (PrinterException e) {
-                System.err.println("鎵撳嵃澶辫触: " + e.getMessage());
-            }
-        }
+    public static void generateQRCodeImage(String text, int width, int height, OutputStream os) throws Exception {
+        QRCodeWriter qrCodeWriter = new QRCodeWriter();
+        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
+        MatrixToImageWriter.writeToStream(bitMatrix, "PNG", os);
     }
 
-    /**
-     * 瀹炵幇 Printable 鎺ュ彛鐨勬墦鍗版柟娉�
-     */
-    @Override
-    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
-        if (pageIndex > 0) {
-            return NO_SUCH_PAGE;
-        }
-
-        Graphics2D g2d = (Graphics2D) graphics;
-        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
-
-        // 璁$畻灞呬腑鍧愭爣
-        double pageWidth = pageFormat.getImageableWidth();
-        double pageHeight = pageFormat.getImageableHeight();
-        double imgWidth = image.getWidth();
-        double imgHeight = image.getHeight();
-
-        double scale = Math.min(pageWidth / imgWidth, pageHeight / imgHeight);
-        g2d.scale(scale, scale);
-        g2d.drawImage(image, 0, 0, null);
-
-        return PAGE_EXISTS;
-    }
-
-    /**
-     * 浣跨敤榛樿鎵撳嵃鏈烘墦鍗帮紝涓嶅脊瀵硅瘽妗�
-     */
-    public static void noDialogPrint(){
-        BufferedImage qrImage = QrCodeUtils.generateQrCode("Silent Print", 300, 300);
-        QrCodePrinterUtils printer = new QrCodePrinterUtils(qrImage);
-        PrinterJob job = PrinterJob.getPrinterJob();
-        job.setPrintable(printer);
+    public static String generateBacthQRCode(String content, int width, int height) {
         try {
-            job.print();
-        } catch (PrinterException e) {
-            e.printStackTrace();
+            Map<EncodeHintType, Object> hints = new HashMap<>();
+            hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
+            hints.put(EncodeHintType.MARGIN, 1);
+
+            BitMatrix matrix = new MultiFormatWriter().encode(
+                    content,
+                    BarcodeFormat.QR_CODE,
+                    width,
+                    height,
+                    hints
+            );
+
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
+            MatrixToImageWriter.writeToStream(matrix, "PNG", os);
+
+            return "data:image/png;base64," +
+                    Base64.getEncoder().encodeToString(os.toByteArray());
+        } catch (Exception e) {
+            throw new RuntimeException("鐢熸垚浜岀淮鐮佸け璐�", e);
         }
     }
+
+    @GetMapping("/batchGenerate")
+    public Result<List<Map<String,String>>> generateBatchQrCode(){
+        List<Map<String,String>> results = new ArrayList<>();
+        List<String> contentList = new ArrayList<>();
+        contentList.add("Q201204330002-0001");
+        contentList.add("Q201204330002-0002");
+        contentList.add("Q201204330002-0003");
+        for(String content : contentList){
+            Map<String,String> result = new HashMap<>();
+            result.put("content",content);
+            result.put("image",generateBacthQRCode(content, 200, 200));
+            // 鐢熸垚浜岀淮鐮佸浘鐗囷紙Base64锛�
+            results.add(result);
+        }
+        return Result.OK(results);
+    }
 }

--
Gitblit v1.9.3